本文整理匯總了Golang中encoding/xml.Encoder.EncodeElement方法的典型用法代碼示例。如果您正苦於以下問題:Golang Encoder.EncodeElement方法的具體用法?Golang Encoder.EncodeElement怎麽用?Golang Encoder.EncodeElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類encoding/xml.Encoder
的用法示例。
在下文中一共展示了Encoder.EncodeElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例2: 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
}
示例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 реализует интерфейс 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)
}
示例5: 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)
}
}
示例6: 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
}
示例7: 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
}
示例8: MarshalXML
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)
}
示例9: MarshalXML
func (b *boolWrapper) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
val := "False"
if *b {
val = "True"
}
e.EncodeElement(val, start)
return nil
}
示例10: 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
}
示例11: MarshalXML
// 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
}
示例12: MarshalXML
func (a CacheBehaviors) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
enc := EncodedCacheBehaviors{
Quantity: len(a),
Items: []CacheBehavior(a),
}
return e.EncodeElement(enc, start)
}
示例13: 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
}
示例14: writeData
// 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)
}
示例15: MarshalXML
// MarshalXML marshals the netconfInfo map as an array of XML
// <error-info> sub-elements
func (info netconfInfo) MarshalXML(e *xml.Encoder, se xml.StartElement) error {
for key, value := range info {
name := string(key)
elem := xml.StartElement{Name: xml.Name{Local: name}}
if err := e.EncodeElement(value, elem); err != nil {
return err
}
}
return nil
}