func encEle(n tree.Elem, e *xml.Encoder) error { ele := xml.StartElement{ Name: n.GetToken().(xml.StartElement).Name, } attrs := n.GetAttrs() ele.Attr = make([]xml.Attr, len(attrs)) for i := range attrs { ele.Attr[i] = attrs[i].GetToken().(xml.Attr) } err := e.EncodeToken(ele) if err != nil { return err } if x, ok := n.(tree.Elem); ok { for _, i := range x.GetChildren() { err := encTok(i, e) if err != nil { return err } } } return e.EncodeToken(ele.End()) }
func (o *OSM) marshalInnerXML(e *xml.Encoder) error { if o == nil { return nil } if err := e.Encode(o.Bounds); err != nil { return err } if err := e.Encode(o.Nodes); err != nil { return err } if err := e.Encode(o.Ways); err != nil { return err } if err := e.Encode(o.Relations); err != nil { return err } if err := e.Encode(o.Changesets); err != nil { return err } return nil }
func (n CharData) MarshalXML(e *xml.Encoder, start xml.StartElement) error { return e.EncodeElement(struct { S string `xml:",innerxml"` }{ S: "<![CDATA[" + string(n) + "]]>", }, start) }
// MarshalXML implementation on JobErrorDateTime to skip "zero" time values func (jdt JobErrorDateTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if jdt.IsZero() { return nil } e.EncodeElement(jdt.Time, start) return nil }
func (node *Packageoption) MarshalXML(e *xml.Encoder, start xml.StartElement) error { var err error startElt := xml.StartElement{Name: xml.Name{Local: "packageoption"}} var dflt string if node.Default { dflt = "yes" } else { dflt = "no" } startElt.Attr = []xml.Attr{ xml.Attr{Name: xml.Name{Local: "name"}, Value: node.Name}, xml.Attr{Name: xml.Name{Local: "default"}, Value: dflt}, } err = e.EncodeToken(startElt) if err != nil { return err } err = marshalShortDescription("shortdescription", e, node.ShortDescription) if err != nil { return err } err = e.EncodeToken(xml.EndElement{Name: startElt.Name}) if err != nil { return err } return nil }
func (n NominalType) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if n == Nominal { return e.EncodeElement("NOMINAL", start) } else { return e.EncodeElement("CALCULATED", start) } }
// TransformXML parses the XML tree, traverses it and calls TransformFunc // on each XML token, writing the output to the writer, resulting in a // transformed XML tree func TransformXML(decoder *xml.Decoder, encoder *xml.Encoder, fn TransformFunc) error { parentNodes := &NodeList{} for { token, err := decoder.Token() if err != nil { if err != io.EOF { return trace.Wrap(err) } break } for _, t := range fn(parentNodes, token) { if err := encoder.EncodeToken(t); err != nil { return err } } switch e := token.(type) { case xml.StartElement: parentNodes.Push(e) case xml.EndElement: parentNodes.Pop() } } encoder.Flush() return nil }
// MarshalXML implements the xml.Marshaller method to allow for the // correct wrapper/start element case and attr data. func (c Change) MarshalXML(e *xml.Encoder, start xml.StartElement) error { start.Name.Local = "osmChange" start.Attr = []xml.Attr{ {Name: xml.Name{Local: "version"}, Value: "0.6"}, {Name: xml.Name{Local: "generator"}, Value: "go.osm"}, } if err := e.EncodeToken(start); err != nil { return err } if err := marshalInnerChange(e, "create", c.Create); err != nil { return err } if err := marshalInnerChange(e, "modify", c.Modify); err != nil { return err } if err := marshalInnerChange(e, "delete", c.Delete); err != nil { return err } if err := e.EncodeToken(start.End()); err != nil { return err } return nil }
func (a *Argument) MarshalXML(e *xml.Encoder, start xml.StartElement) error { var err error startElt := xml.StartElement{Name: xml.Name{Local: "argument"}} var opt string if a.Optional { opt = "yes" } else { opt = "no" } startElt.Attr = append(startElt.Attr, xml.Attr{Name: xml.Name{Local: "name"}, Value: a.Name}) startElt.Attr = append(startElt.Attr, xml.Attr{Name: xml.Name{Local: "optional"}, Value: opt}) startElt.Attr = append(startElt.Attr, xml.Attr{Name: xml.Name{Local: "type"}, Value: argumentTypeReveseMap[a.Type]}) err = e.EncodeToken(startElt) if err != nil { return err } err = e.EncodeToken(xml.EndElement{Name: startElt.Name}) if err != nil { return err } return nil }
// MarshalXML marshals NullInts greater than zero to XML. Otherwise nothing is // marshaled. func (n NullInt) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if n.Valid { e.EncodeElement(n.Int, start) } return nil }
func (a1 AdGroupAds) MarshalXML(e *xml.Encoder, start xml.StartElement) error { a := a1[0] e.EncodeToken(start) switch a.(type) { case TextAd: ad := a.(TextAd) e.EncodeElement(ad.AdGroupId, xml.StartElement{Name: xml.Name{"", "adGroupId"}}) e.EncodeElement(ad, xml.StartElement{ xml.Name{"", "ad"}, []xml.Attr{ xml.Attr{xml.Name{"http://www.w3.org/2001/XMLSchema-instance", "type"}, "TextAd"}, }, }) e.EncodeElement(ad.Status, xml.StartElement{Name: xml.Name{"", "status"}}) e.EncodeElement(ad.Labels, xml.StartElement{Name: xml.Name{"", "labels"}}) case ImageAd: return ERROR_NOT_YET_IMPLEMENTED case TemplateAd: return ERROR_NOT_YET_IMPLEMENTED default: return fmt.Errorf("unknown Ad type -> %#v", start) } e.EncodeToken(start.End()) return nil }
// MarshalXML реализует интерфейс xml.Marshaler для объекта NullDate // сериализация происходит с учётом шаблона, заданного в свойстве Layout func (d NullDate) MarshalXML(encoder *xml.Encoder, start xml.StartElement) error { if !d.Valid { return encoder.EncodeElement(nil, start) } d.fixLayout() return encoder.EncodeElement(d.String(), start) }
func encNS(ns xml.Attr, e *xml.Encoder) error { pi := xml.ProcInst{ Target: "namespace", Inst: ([]byte)(ns.Value), } return e.EncodeToken(pi) }
// MarshalXML impements the xml.Marshaler interface. // Any tag present with this type = true. func (b Bool) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if b { e.EncodeToken(start) e.EncodeToken(xml.EndElement{Name: start.Name}) } return nil }
// MarshalXML marshals times into their proper format. Otherwise nothing is // marshaled. All times are sent in UTC. func (t NullTime) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if t.Time != nil { e.EncodeElement(t.String(), start) } return nil }
// MarshalXML is a custom marshaller for Duration. func (dur *Duration) MarshalXML(e *xml.Encoder, start xml.StartElement) error { start.Attr = []xml.Attr{xml.Attr{Name: xml.Name{Local: "duration"}, Value: dur.Duration.String()}, xml.Attr{Name: xml.Name{Local: "state"}, Value: dur.State}, } e.EncodeToken(start) e.EncodeToken(xml.EndElement{Name: start.Name}) return nil }
//Print prints the XML character data in string form func (cd *PathResCharData) Print(e *xml.Encoder) error { var err error if _, ok := cd.Value.(xml.CharData); ok { val := cd.Value.(xml.CharData) err = e.EncodeToken(val) } return err }
//Print prints the XML comment in string form func (c *PathResComment) Print(e *xml.Encoder) error { var err error if _, ok := c.Value.(xml.Comment); ok { val := c.Value.(xml.Comment) err = e.EncodeToken(val) } return err }
func (a Aliases) MarshalXML(e *xml.Encoder, start xml.StartElement) error { enc := EncodedAliases{ Quantity: len(a), Items: []string(a), } return e.EncodeElement(enc, start) }
func (a CacheBehaviors) MarshalXML(e *xml.Encoder, start xml.StartElement) error { enc := EncodedCacheBehaviors{ Quantity: len(a), Items: []CacheBehavior(a), } return e.EncodeElement(enc, start) }
func (d Datum) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if d.Time != nil { formattedDate := d.Time.Format(xmlDateFormat) e.EncodeElement(formattedDate, start) } return nil }
func (b *boolWrapper) MarshalXML(e *xml.Encoder, start xml.StartElement) error { val := "False" if *b { val = "True" } e.EncodeElement(val, start) return nil }
func (f ApproximationType) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if f < approximationTypeEnd { return e.EncodeElement(approximationTypeLookup[f], start) } return fmt.Errorf("invalid approximation type: %d", f) }
// MarshalXML marshals NullBools to XML. Otherwise nothing is // marshaled. func (u UnitAmount) MarshalXML(e *xml.Encoder, start xml.StartElement) error { if u.USD > 0 || u.EUR > 0 { v := (uaAlias)(u) e.EncodeElement(v, start) } return nil }
func (a JobCommandJobRefArguments) MarshalXML(e *xml.Encoder, start xml.StartElement) error { start.Attr = []xml.Attr{ xml.Attr{xml.Name{Local: "line"}, string(a)}, } e.EncodeToken(start) e.EncodeToken(xml.EndElement{start.Name}) return nil }
func (a CustomErrorResponses) MarshalXML(e *xml.Encoder, start xml.StartElement) error { enc := EncodedCustomErrorResponses{ Quantity: len(a), Items: []CustomErrorResponse(a), } return e.EncodeElement(enc, start) }
func (o Origins) MarshalXML(e *xml.Encoder, start xml.StartElement) error { enc := EncodedOrigins{ Quantity: len(o), Items: []Origin(o), } return e.EncodeElement(enc, start) }
func (p PList) MarshalXML(e *xml.Encoder, start xml.StartElement) error { start.Name = xml.Name{Local: "plist"} start.Attr = []xml.Attr{xml.Attr{Name: xml.Name{Local: "version"}, Value: "1.0"}} e.EncodeToken(start) PDict(p).MarshalXML(e, xml.StartElement{}) e.EncodeToken(start.End()) return nil }
func (self *Element) Encode(enc *xml.Encoder, sr SchemaRepository, ga GetAliaser, params map[string]interface{}, path ...string) (err error) { if self.MinOccurs != "" && self.MinOccurs == "0" && !hasPrefix(params, MakePath(append(path, self.Name))) { return } for hasPrefix(params, MakePath(append(path, self.Name))) { start := xml.StartElement{ Name: xml.Name{ Space: ga.Namespace(), Local: self.Name, }, } err = enc.EncodeToken(start) if err != nil { return } if self.Type != "" { parts := strings.Split(self.Type, ":") switch len(parts) { case 1: err = self.Encode(enc, sr, ga, params, append(path, self.Name)...) if err != nil { return } case 2: var schema Schemaer schema, err = sr.GetSchema(ga.GetAlias(parts[0])) if err != nil { return } err = schema.EncodeType(parts[1], enc, sr, params, append(path, self.Name)...) if err != nil { return } default: err = fmt.Errorf("malformed type '%s' in path %q", self.Type, path) return } } else if self.ComplexTypes != nil { for _, e := range self.ComplexTypes.Sequence { err = e.Encode(enc, sr, ga, params, append(path, self.Name)...) if err != nil { return } } } err = enc.EncodeToken(start.End()) if err != nil { return } } return }
// writeData base64-encodes val. func writeData(e *xml.Encoder, val []byte) error { var encoded bytes.Buffer encoder := base64.NewEncoder(base64.StdEncoding, &encoded) // Just writing to a buffer, can't fail. encoder.Write(val) encoder.Close() return e.EncodeElement(encoded.String(), dataStartElement) }