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

Golang xml.StartElement类代码示例

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

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



在下文中一共展示了StartElement类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: MarshalXML

func (bagc BiddableAdGroupCriterion) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	start.Attr = append(
		start.Attr,
		xml.Attr{
			xml.Name{"http://www.w3.org/2001/XMLSchema-instance", "type"},
			"BiddableAdGroupCriterion",
		},
	)
	e.EncodeToken(start)
	e.EncodeElement(&bagc.AdGroupId, xml.StartElement{Name: xml.Name{"", "adGroupId"}})
	criterionMarshalXML(bagc.Criterion, e)

	if bagc.UserStatus != "" {
		e.EncodeElement(&bagc.UserStatus, xml.StartElement{Name: xml.Name{"", "userStatus"}})
	}
	if bagc.DestinationUrl != "" {
		e.EncodeElement(&bagc.DestinationUrl, xml.StartElement{Name: xml.Name{"", "destinationUrl"}})
	}
	e.EncodeElement(&bagc.BiddingStrategyConfiguration, xml.StartElement{Name: xml.Name{"", "biddingStrategyConfiguration"}})
	if bagc.BidModifier != 0 {
		e.EncodeElement(&bagc.BidModifier, xml.StartElement{Name: xml.Name{"", "bidModifier"}})
	}
	e.EncodeToken(start.End())
	return nil
}
开发者ID:Nyarum,项目名称:gads,代码行数:25,代码来源:biddable_ad_group_criterion.go


示例2: 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


示例3: marshalDescription

func marshalDescription(eltname string, e *xml.Encoder, desc map[string]template.HTML) error {
	var err error
	for lang, text := range desc {
		startElt := xml.StartElement{Name: xml.Name{Local: eltname}}

		startElt.Attr = []xml.Attr{
			xml.Attr{Name: xml.Name{Local: "lang"}, Value: lang},
		}

		err = e.EncodeToken(startElt)
		if err != nil {
			return err
		}

		err = e.EncodeToken(xml.CharData(string(text)))
		if err != nil {
			return err
		}

		err = e.EncodeToken(xml.EndElement{Name: startElt.Name})
		if err != nil {
			return err
		}

	}
	return nil
}
开发者ID:speedata,项目名称:ltxdoc,代码行数:27,代码来源:xmlout.go


示例4: 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


示例5: ParseList

func (c ChoiceParser) ParseList(d *xml.Decoder, start xml.StartElement, containerPtr interface{}, typeofPtr interface{}, appenderType appender) error {
	typeof := reflect.TypeOf(typeofPtr).Elem()
	container := reflect.ValueOf(containerPtr).Elem()
	token, err := d.Token()
	for token != start.End() {
		if err != nil {
			return err
		}
		next, ok := token.(xml.StartElement)
		if ok {
			item, err := c.Parse(d, next)
			if err != nil {
				return err
			}
			val := reflect.ValueOf(item)
			if !val.Type().Implements(typeof) {
				return fmt.Errorf("Item is not a valid %v.", typeof.Name())
			}
			appendFn := appenders[appenderType]
			appendFn(container, val)
		}
		token, err = d.Token()
	}
	return nil
}
开发者ID:voltron42,项目名称:xtraml,代码行数:25,代码来源:choice.go


示例6: MarshalXML

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


示例7: UnmarshalXML

func (x *XmlNode) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	x.Name = getName(start.Name)
	x.Attrs = map[string]string{}
	for _, attr := range start.Attr {
		x.Attrs[getName(attr.Name)] = attr.Value
	}
	token, err := d.Token()
	for token != start.End() {
		if err != nil {
			return err
		}
		next, ok := token.(xml.StartElement)
		if ok {
			child := XmlNode{}
			err = child.UnmarshalXML(d, next)
			if err != nil {
				return err
			}
			x.Children = append(x.Children, child)
		} else {
			text, ok := token.(xml.CharData)
			if ok {
				x.Children = append(x.Children, TextNode(string([]byte(text))))
			}
		}
		token, err = d.Token()
	}
	return nil
}
开发者ID:voltron42,项目名称:xtraml,代码行数:29,代码来源:simple.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: setAttr

func setAttr(n *xml.StartElement, key, val string) {
	n.Attr = append([]xml.Attr{}, n.Attr...)

	for i := range n.Attr {
		attr := &n.Attr[i]
		if attr.Name.Local == key {
			if val == "" {
				n.Attr = append(n.Attr[:i], n.Attr[i+1:]...)
			} else {
				attr.Value = val
			}
			return
		}
	}

	if val == "" {
		return
	}

	n.Attr = append(n.Attr, xml.Attr{
		Name:  xml.Name{Local: key},
		Value: val,
	})
	sort.Sort(attrByName(n.Attr))
}
开发者ID:raintreeinc,项目名称:ditaconvert,代码行数:25,代码来源:xmlutil.go


示例10: UnmarshalXML

func (a *APITime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	a.Time = time.Time{}

	for {
		t, _ := d.Token()
		if t == nil {
			return fmt.Errorf("couldn't find apitime end element, ran out of data!")
		}
		if t == start.End() {
			break
		}
		if timeBytes, ok := t.(xml.CharData); ok {
			var err error
			a.Time, err = time.Parse(ApiDateTimeFormat, string(timeBytes))
			if err != nil {
				return err
			}
		}
	}

	if a.Time.IsZero() {
		return fmt.Errorf("couldn't find a valid apitime.")
	}

	return nil
}
开发者ID:inominate,项目名称:eveapitime,代码行数:26,代码来源:apitime.go


示例11: writeResponse

func writeResponse(w http.ResponseWriter, statusCode int, action string, data interface{}) {
	responseBuffer := &bytes.Buffer{}
	encoder := xml.NewEncoder(responseBuffer)
	resultWrapper := xml.StartElement{Name: xml.Name{Local: action + "Result"}}
	err := encoder.EncodeToken(resultWrapper)
	if err != nil {
		panic(err)
	}
	err = xmlutil.BuildXML(data, encoder)
	if err != nil {
		panic(err)
	}
	err = encoder.EncodeToken(resultWrapper.End())
	if err != nil {
		panic(err)
	}
	err = encoder.Flush()
	if err != nil {
		panic(err)
	}

	w.WriteHeader(statusCode)
	_, err = w.Write(responseBuffer.Bytes())
	if err != nil {
		panic(err)
	}
}
开发者ID:rosenhouse,项目名称:awsfaker,代码行数:27,代码来源:query.go


示例12: MarshalXML

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
}
开发者ID:v-yarotsky,项目名称:dawg,代码行数:8,代码来源:plist.go


示例13: Encode

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
}
开发者ID:leobcn,项目名称:goat,代码行数:58,代码来源:element.go


示例14: MarshalXML

func (a AlfredOutput) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	start.Name = xml.Name{Local: "items"}
	e.EncodeToken(start)
	for _, item := range a {
		e.EncodeElement(item, xml.StartElement{Name: xml.Name{Local: "item"}})
	}
	e.EncodeToken(start.End())
	return nil
}
开发者ID:v-yarotsky,项目名称:dawg,代码行数:9,代码来源:alfred.go


示例15: MarshalXML

func (mmo MutateMembersOperand) MarshalXML(e *xml.Encoder, start xml.StartElement) error {

	mmo.encodeEmails()

	e.EncodeToken(start)
	e.EncodeElement(&mmo.UserListId, xml.StartElement{Name: xml.Name{baseRemarketingUrl, "userListId"}})
	e.EncodeElement(&mmo.DataType, xml.StartElement{Name: xml.Name{baseRemarketingUrl, "dataType"}})
	e.EncodeElement(&mmo.Members, xml.StartElement{Name: xml.Name{baseRemarketingUrl, "members"}})
	e.EncodeToken(start.End())
	return nil
}
开发者ID:colinmutter,项目名称:gads,代码行数:11,代码来源:adwords_user_list.go


示例16: makeStartXml

func makeStartXml(root *XlsObjNode, enc *xml.Encoder) {
	valueList := root.value.([]*XlsObjNode)
	token := xml.StartElement{xml.Name{"", root.key}, make([]xml.Attr, 0)}

	for _, key := range valueList {
		if key.nodeType == ATTR_TYPE {
			attr := xml.Attr{xml.Name{"", key.key}, key.value.(string)}
			token.Attr = append(token.Attr, attr)
		}
	}
	enc.EncodeToken(token)
}
开发者ID:icetoggle,项目名称:allconvert,代码行数:12,代码来源:xls_to_xml_parser.go


示例17: MarshalXML

// MarshalXML implements xml.Marshaler interface
func (c StreamErrorCondition) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	t := xml.StartElement{
		Name: xml.Name{
			"urn:ietf:params:xml:ns:xmpp-streams", string(c),
		},
	}

	e.EncodeToken(t)
	e.EncodeToken(t.End())

	return nil
}
开发者ID:PMaynard,项目名称:coyim,代码行数:13,代码来源:errors.go


示例18: MarshalXML

// MarshalXML is a custom XML marshaler for metadataMap, mapping each metadata name/value pair to a
// correspondingly named XML element with the pair's value as character data content.
func (m metadataMap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	if err := e.EncodeToken(start); err != nil {
		return err
	}

	for k, v := range m {
		if err := e.EncodeElement(v, startLocalName(k)); err != nil {
			return err
		}
	}

	return e.EncodeToken(start.End())
}
开发者ID:hudl,项目名称:fargo,代码行数:15,代码来源:marshal.go


示例19: MarshalXML

func (nagc NegativeAdGroupCriterion) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	start.Attr = append(
		start.Attr,
		xml.Attr{
			xml.Name{"http://www.w3.org/2001/XMLSchema-instance", "type"},
			"NegativeAdGroupCriterion",
		},
	)
	e.EncodeToken(start)
	e.EncodeElement(&nagc.AdGroupId, xml.StartElement{Name: xml.Name{"", "adGroupId"}})
	criterionMarshalXML(nagc.Criterion, e)
	e.EncodeToken(start.End())
	return nil
}
开发者ID:colinmutter,项目名称:gads,代码行数:14,代码来源:negative_ad_group_criterion.go


示例20: MarshalXML

func (this *Pair) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	if err := e.EncodeToken(start); err != nil {
		return err
	}
	if err := this.Left.marshalXML(e, start); err != nil {
		return err
	}
	if err := this.Right.marshalXML(e, start); err != nil {
		return err
	}
	if err := e.EncodeToken(start.End()); err != nil {
		return err
	}
	return nil
}
开发者ID:katydid,项目名称:relaxng,代码行数:15,代码来源:grammar.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang engine.NewPassthroughEngine函数代码示例发布时间:2022-05-24
下一篇:
Golang xml.Name类代码示例发布时间: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