• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang xml.Encoder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中encoding/xml.Encoder的典型用法代码示例。如果您正苦于以下问题:Golang Encoder类的具体用法?Golang Encoder怎么用?Golang Encoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Encoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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())
}
开发者ID:ChrisTrenkamp,项目名称:goxpath,代码行数:27,代码来源:marshal.go


示例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
}
开发者ID:paulmach,项目名称:go.osm,代码行数:27,代码来源:osm.go


示例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)
}
开发者ID:StephaneTy-Pro,项目名称:Pickles2TesLink,代码行数:7,代码来源:Pickles2TestLink.go


示例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
}
开发者ID:NYTimes,项目名称:encoding-wrapper,代码行数:8,代码来源:job.go


示例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
}
开发者ID:speedata,项目名称:ltxdoc,代码行数:31,代码来源:xmlout.go


示例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)
	}
}
开发者ID:GeoNet,项目名称:delta,代码行数:7,代码来源:nominal_type.go


示例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
}
开发者ID:gravitational,项目名称:configure,代码行数:28,代码来源:xml.go


示例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
}
开发者ID:paulmach,项目名称:go.osm,代码行数:31,代码来源:change.go


示例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
}
开发者ID:fubotv,项目名称:go-recurly,代码行数:9,代码来源:type_null_int.go


示例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
}
开发者ID:foxglove1028,项目名称:gads,代码行数:25,代码来源:ad_group_ads.go


示例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)
}
开发者ID:mihteh,项目名称:types,代码行数:9,代码来源:datetime.go


示例12: encNS

func encNS(ns xml.Attr, e *xml.Encoder) error {
	pi := xml.ProcInst{
		Target: "namespace",
		Inst:   ([]byte)(ns.Value),
	}
	return e.EncodeToken(pi)
}
开发者ID:ChrisTrenkamp,项目名称:goxpath,代码行数:7,代码来源:marshal.go


示例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
}
开发者ID:wrouesnel,项目名称:epp,代码行数:9,代码来源:bool.go


示例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
}
开发者ID:fubotv,项目名称:go-recurly,代码行数:9,代码来源:type_null_time.go


示例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
}
开发者ID:ChristopherRabotin,项目名称:sg,代码行数:9,代码来源:stats.go


示例16: Print

//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
}
开发者ID:postfix,项目名称:goxpath,代码行数:9,代码来源:chardata.go


示例17: Print

//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
}
开发者ID:postfix,项目名称:goxpath,代码行数:9,代码来源:comment.go


示例18: MarshalXML

func (a Aliases) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	enc := EncodedAliases{
		Quantity: len(a),
		Items:    []string(a),
	}

	return e.EncodeElement(enc, start)
}
开发者ID:abacusadvertising,项目名称:Stout,代码行数:8,代码来源:cloudfront.go


示例19: MarshalXML

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
}
开发者ID:peteraba,项目名称:invoice-export,代码行数:8,代码来源:behavior.go


示例20: MarshalXML

func (b *boolWrapper) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	val := "False"
	if *b {
		val = "True"
	}
	e.EncodeElement(val, start)
	return nil
}
开发者ID:ironmig,项目名称:gokeepasslib,代码行数:8,代码来源:bool_wrapper.go



注:本文中的encoding/xml.Encoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang xml.Name类代码示例发布时间:2022-05-24
下一篇:
Golang xml.Decoder类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap