本文整理汇总了Golang中encoding/xml.Encoder类的典型用法代码示例。如果您正苦于以下问题:Golang Encoder类的具体用法?Golang Encoder怎么用?Golang Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Encoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: encEle
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())
}
示例2: marshalInnerXML
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
}
示例3: MarshalXML
func (n CharData) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement(struct {
S string `xml:",innerxml"`
}{
S: "<![CDATA[" + string(n) + "]]>",
}, start)
}
示例4: MarshalXML
// 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
}
示例5: MarshalXML
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
}
示例6: MarshalXML
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)
}
}
示例7: TransformXML
// 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
}
示例8: MarshalXML
// 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
}
示例9: MarshalXML
// 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
}
示例10: MarshalXML
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
}
示例11: MarshalXML
// 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)
}
示例12: encNS
func encNS(ns xml.Attr, e *xml.Encoder) error {
pi := xml.ProcInst{
Target: "namespace",
Inst: ([]byte)(ns.Value),
}
return e.EncodeToken(pi)
}
示例13: MarshalXML
// 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
}
示例14: MarshalXML
// 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
}
示例15: MarshalXML
// 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
}