當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Encoder.EncodeToken方法代碼示例

本文整理匯總了Golang中encoding/xml.Encoder.EncodeToken方法的典型用法代碼示例。如果您正苦於以下問題:Golang Encoder.EncodeToken方法的具體用法?Golang Encoder.EncodeToken怎麽用?Golang Encoder.EncodeToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在encoding/xml.Encoder的用法示例。


在下文中一共展示了Encoder.EncodeToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

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

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

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

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

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

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

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

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

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

示例11: MarshalXML

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
}
開發者ID:hooklift,項目名稱:terraform,代碼行數:8,代碼來源:job.go

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

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

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

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


注:本文中的encoding/xml.Encoder.EncodeToken方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。