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
0
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
}
示例#3
0
文件: xmlout.go 项目: speedata/ltxdoc
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
}
示例#4
0
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())
}
示例#5
0
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
}
示例#6
0
文件: xmlout.go 项目: speedata/ltxdoc
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
}
示例#7
0
文件: xmlout.go 项目: speedata/ltxdoc
func (c *Command) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	var err error
	if c.Level == "" {
		c.Level = "beginner"
	}
	cmdstartelt := xml.StartElement{Name: xml.Name{Local: "command"}}
	cmdstartelt.Attr = []xml.Attr{
		xml.Attr{Name: xml.Name{Local: "name"}, Value: c.Name},
		xml.Attr{Name: xml.Name{Local: "label"}, Value: strings.Join(c.Label, ",")},
		xml.Attr{Name: xml.Name{Local: "level"}, Value: c.Level},
	}
	err = e.EncodeToken(cmdstartelt)
	if err != nil {
		return err
	}
	err = marshalShortDescription("shortdescription", e, c.ShortDescription)
	if err != nil {
		return err
	}

	err = marshalDescription("description", e, c.Description)
	if err != nil {
		return err
	}

	err = e.Encode(c.Variant)
	if err != nil {
		return err
	}

	return e.EncodeToken(xml.EndElement{Name: cmdstartelt.Name})
}
示例#8
0
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
}
示例#9
0
文件: xmlout.go 项目: speedata/ltxdoc
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
}
示例#10
0
文件: change.go 项目: paulmach/go.osm
// 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
}
示例#11
0
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))
}
示例#12
0
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
}
示例#13
0
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)
	}
}
示例#14
0
文件: plist.go 项目: v-yarotsky/dawg
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
}
示例#15
0
文件: element.go 项目: leobcn/goat
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
}
示例#16
0
文件: plist.go 项目: v-yarotsky/dawg
func (a PArray) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	start.Name = xml.Name{Local: "array"}
	e.EncodeToken(start)
	for _, el := range a {
		el.(xml.Marshaler).MarshalXML(e, start)
	}
	e.EncodeToken(start.End())
	return nil
}
示例#17
0
文件: alfred.go 项目: v-yarotsky/dawg
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
}
示例#18
0
文件: plist.go 项目: v-yarotsky/dawg
func (d PDict) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	start.Name = xml.Name{Local: "dict"}
	e.EncodeToken(start)
	for k, v := range d {
		e.EncodeElement(k, xml.StartElement{Name: xml.Name{Local: "key"}})
		v.MarshalXML(e, start)
	}
	e.EncodeToken(start.End())
	return nil
}
示例#19
0
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
}
示例#20
0
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)
}
示例#21
0
文件: errors.go 项目: PMaynard/coyim
// 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
}
示例#22
0
文件: marshal.go 项目: hudl/fargo
// 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())
}
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
}
示例#24
0
文件: marshal.go 项目: hudl/fargo
// MarshalXML is a custom XML marshaler for DataCenterInfo, writing either Metadata or AlternateMetadata
// depending on the type of data center indicated by the Name.
func (i DataCenterInfo) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	if err := e.EncodeToken(start); err != nil {
		return err
	}

	if err := e.EncodeElement(i.Name, startName); err != nil {
		return err
	}
	if err := e.EncodeElement(metadataValue(i), startMetadata); err != nil {
		return err
	}

	return e.EncodeToken(start.End())
}
示例#25
0
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
}
示例#26
0
文件: st.go 项目: kpmy/lomo
func (u *extern) attr(start *xml.StartElement, name string, value interface{}) {
	str := func(value string) {
		assert.For(value != "", 20)
		a := xml.Attr{}
		a.Name.Local = name
		a.Value = value
		start.Attr = append(start.Attr, a)
	}
	switch v := value.(type) {
	case string:
		str(v)
	case bool:
		if v {
			str("true")
		} else {
			str("false")
		}
	case int:
		str(strconv.Itoa(v))
	case types.Type:
		str(v.String())
	default:
		halt.As(100, reflect.TypeOf(v), v)
	}
}
示例#27
0
文件: xmlout.go 项目: speedata/ltxdoc
func (node *Package) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
	var err error
	startElt := xml.StartElement{Name: xml.Name{Local: "package"}}

	if node.Level == "" {
		node.Level = "beginner"
	}

	startElt.Attr = []xml.Attr{
		xml.Attr{Name: xml.Name{Local: "name"}, Value: node.Name},
		xml.Attr{Name: xml.Name{Local: "level"}, Value: node.Level},
		xml.Attr{Name: xml.Name{Local: "label"}, Value: strings.Join(node.Label, ",")},
		xml.Attr{Name: xml.Name{Local: "loadspackages"}, Value: strings.Join(node.LoadsPackages, ",")},
	}

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

	err = marshalShortDescription("shortdescription", e, node.ShortDescription)
	if err != nil {
		return err
	}

	err = marshalDescription("description", e, node.Description)
	if err != nil {
		return err
	}

	err = e.Encode(node.Options)
	if err != nil {
		return err
	}

	err = e.Encode(node.Commands)
	if err != nil {
		return err
	}

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

	return nil
}
示例#28
0
func (s *serverStream) writeOpen() error {
	var start xml.StartElement
	start.Name = xml.Name{Local: "stream:stream", Space: "jabber:client"}
	start.Attr = append(start.Attr,
		xml.Attr{Name: xml.Name{Local: "xmlns:stream"}, Value: "http://etherx.jabber.org/streams"},
		xml.Attr{Name: xml.Name{Local: "xmlns:xml"}, Value: "http://www.w3.org/XML/1998/namespace"},
		xml.Attr{Name: xml.Name{Local: "from"}, Value: s.from},
		xml.Attr{Name: xml.Name{Local: "version"}, Value: s.version},
	)
	if err := s.streamEncoder.EncodeToken(start); err != nil {
		return err
	}

	// xml.Encoder doesn't flush until it generated end tag
	// so we flush here to make it send stream's open tag
	return s.streamEncoder.Flush()
}
示例#29
0
文件: job.go 项目: hooklift/terraform
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
}
示例#30
0
// 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
}