当前位置: 首页>>代码示例>>Golang>>正文


Golang Decoder.DecodeElement方法代码示例

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


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

示例1: UnmarshalXML

// UnmarshalXML implements the xml.Unmarshaler interface.
func (r *repos) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var payload struct {
		Data []struct {
			ID        string `xml:"id"`
			Name      string `xml:"name"`
			Type      string `xml:"repoType"`
			Policy    string `xml:"repoPolicy"`
			Format    string `xml:"format"`
			RemoteURI string `xml:"remoteUri"`
		} `xml:"data>repositories-item"`
	}

	if err := d.DecodeElement(&payload, &start); err != nil {
		return err
	}

	for _, repo := range payload.Data {
		newRepo := &Repository{
			ID:        repo.ID,
			Name:      repo.Name,
			Type:      repo.Type,
			Format:    repo.Format,
			Policy:    repo.Policy,
			RemoteURI: repo.RemoteURI,
		}

		*r = append(*r, newRepo)
	}

	return nil
}
开发者ID:gitter-badger,项目名称:alkasir,代码行数:32,代码来源:repository.go

示例2: UnmarshalXML

func (r *SolvedRecord) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	rr := struct {
		RunId     string `xml:"run_id"`
		UserId    string `xml:"user_id"`
		ProblemId string `xml:"problem_id"`
		Date      string `xml:"date"`
		Language  string `xml:"language"`
		CpuTime   string `xml:"cputime"`
		Memory    string `xml:"memory"`
		CodeSize  string `xml:"code_size"`
	}{}
	if err := d.DecodeElement(&rr, &start); err != nil {
		return err
	}

	date, err := strconv.ParseInt(strings.Trim(rr.Date, "\n"), 10, 0)
	cpuTime, err := strconv.Atoi(strings.Trim(rr.CpuTime, "\n"))
	memory, err := strconv.Atoi(strings.Trim(rr.Memory, "\n"))
	codeSize, err := strconv.Atoi(strings.Trim(rr.CodeSize, "\n"))
	if err != nil {
		return err
	}

	*r = SolvedRecord{
		RunId:     strings.Trim(rr.RunId, "\n"),
		UserId:    strings.Trim(rr.UserId, "\n"),
		ProblemId: strings.Trim(rr.ProblemId, "\n"),
		Date:      date,
		Language:  strings.Trim(rr.Language, "\n"),
		CpuTime:   cpuTime,
		Memory:    memory,
		CodeSize:  codeSize,
	}
	return nil
}
开发者ID:zakuro9715,项目名称:aojgo,代码行数:35,代码来源:solved_record.go

示例3: UnmarshalXML

func (g *QueryGroup) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	var v struct {
		XMLName xml.Name  `xml:"querygroup"`
		ID      string    `xml:"id,attr"`
		Targets *string   `xml:"targets,attr"`
		Query   []*Query  `xml:"query"`
		Any     *xml.Name `xml:",any"`
	}
	if err := dec.DecodeElement(&v, &start); err != nil {
		return err
	}
	if any := v.Any; any != nil {
		return fmt.Errorf("querygroup %s: invalid element: %s", g.ID, any.Local)
	}
	var targets []string
	switch p := v.Targets; {
	case p != nil && *p != "":
		targets = strings.Split(*p, ",")
	case p != nil:
		targets = []string{}
	}
	*g = QueryGroup{
		ID:      v.ID,
		Targets: targets,
		Query:   v.Query,
	}
	return nil
}
开发者ID:The-Cloud-Source,项目名称:opentsp,代码行数:28,代码来源:control.go

示例4: UnmarshalXML

// UnmarshalXML unmarshals UserData XML.
func (u *UserData) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	// Assume that UserData has the same general key-value structure as
	// EventData does.
	in := struct {
		Pairs []KeyValue `xml:",any"`
	}{}

	// Read tokens until we find the first StartElement then unmarshal it.
	for {
		t, err := d.Token()
		if err != nil {
			return err
		}

		if se, ok := t.(xml.StartElement); ok {
			err = d.DecodeElement(&in, &se)
			if err != nil {
				return err
			}

			u.Name = se.Name
			u.Pairs = in.Pairs
			d.Skip()
			break
		}
	}

	return nil
}
开发者ID:ChongFeng,项目名称:beats,代码行数:30,代码来源:event.go

示例5: UnmarshalXML

// UnmarshalXML implements xml.Unmarshaler
func (u *UUID) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var v []byte
	d.DecodeElement(&v, &start)
	b := u[:]

	return decodeUUID(b, v)
}
开发者ID:suapapa,项目名称:tools,代码行数:8,代码来源:uuid.go

示例6: InitFromXml

func (m *MSystem) InitFromXml(p *xml.Decoder, t xml.StartElement) error {
	err := p.DecodeElement(m, &t)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:anxiousmodernman,项目名称:gorets,代码行数:7,代码来源:system.go

示例7: UnmarshalXML

func (el *Element) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	// prevent recursion
	type Elem Element

	type element struct {
		Elem
		MaxOccursStr string `xml:"maxOccurs,attr"`
	}

	item := element{
		MaxOccursStr: "1",
		Elem: Elem{
			MinOccurs: 1,
		},
	}

	if err := d.DecodeElement(&item, &start); err != nil {
		return err
	}

	if item.MaxOccursStr == "unbounded" {
		el.MaxOccurs = int(math.MaxInt64)
	} else {
		el.MaxOccurs, _ = strconv.Atoi(item.MaxOccursStr)
	}

	el.Name = item.Name
	el.XMLName = item.XMLName
	el.Type = item.Type
	el.MinOccurs = item.MinOccurs

	return nil
}
开发者ID:hheld,项目名称:xsd2code,代码行数:33,代码来源:xsdTypes.go

示例8: UnmarshalXML

func (nagc *NegativeAdGroupCriterion) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	for token, err := dec.Token(); err == nil; token, err = dec.Token() {
		if err != nil {
			return err
		}
		switch start := token.(type) {
		case xml.StartElement:
			tag := start.Name.Local
			switch tag {
			case "adGroupId":
				if err := dec.DecodeElement(&nagc.AdGroupId, &start); err != nil {
					return err
				}
			case "criterionUse":
				if err := dec.DecodeElement(&nagc.CriterionUse, &start); err != nil {
					return err
				}
			case "criterion":
				criterion, err := criterionUnmarshalXML(dec, start)
				if err != nil {
					return err
				}
				nagc.Criterion = criterion
			case "AdGroupCriterion.Type":
				break
			default:
				return fmt.Errorf("unknown NegativeAdGroupCriterion field %s", tag)
			}
		}
	}
	return nil
}
开发者ID:colinmutter,项目名称:gads,代码行数:32,代码来源:negative_ad_group_criterion.go

示例9: ParseMetadataCompactDecoded

func ParseMetadataCompactDecoded(start xml.StartElement, parser *xml.Decoder, delim string) (*CompactData, error) {
	type XmlMetadataElement struct {
		Resource string `xml:"Resource,attr"`
		/* only valid for table */
		Class string `xml:"Class,attr"`
		/* only valid for lookup_type */
		Lookup  string   `xml:"Lookup,attr"`
		Version string   `xml:"Version,attr"`
		Date    string   `xml:"Date,attr"`
		Columns string   `xml:"COLUMNS"`
		Data    []string `xml:"DATA"`
	}
	xme := XmlMetadataElement{}
	err := parser.DecodeElement(&xme, &start)
	if err != nil {
		fmt.Println("failed to decode: ", err)
		return nil, err
	}
	if xme.Columns == "" {
		return nil, nil
	}
	data := *extractMap(xme.Columns, xme.Data, delim)
	data.Date = xme.Date
	data.Version = xme.Version
	data.Id = xme.Resource
	if xme.Class != "" {
		data.Id = xme.Resource + ":" + xme.Class
	}
	if xme.Lookup != "" {
		data.Id = xme.Resource + ":" + xme.Lookup
	}

	return &data, nil
}
开发者ID:anxiousmodernman,项目名称:gorets,代码行数:34,代码来源:common.go

示例10: UnmarshalXML

// UnmarshalXML function unmarshal an <album-list> XML fragment to a Map[string]*Album
func (am *AlbumMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	// result
	m := map[string]*Album{}

LOOP:
	for {
		token, err := d.Token()
		if err != nil {
			return err
		}

		switch t := token.(type) {
		case xml.StartElement:

			if t.Name.Local == "album" {
				a := Album{}
				elmt := xml.StartElement(t)
				d.DecodeElement(&a, &elmt)
				m[a.ID] = &a
			}
		case xml.EndElement:
			if t.Name.Local == "album-list" {
				break LOOP
			}
		}
	}

	*am = AlbumMap(m)
	return nil
}
开发者ID:mmbros,项目名称:music-arc,代码行数:31,代码来源:album.go

示例11: UnmarshalXML

func (t *Tag) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	t.Name = start.Name
	t.Attr = start.Attr
	for {
		token, err := d.Token()
		if err != nil {
			if err == io.EOF {
				return nil
			}
			return err
		}
		switch token.(type) {
		case xml.StartElement:
			tok := token.(xml.StartElement)
			var data *Tag
			if err := d.DecodeElement(&data, &tok); err != nil {
				return err
			}
			t.Children = append(t.Children, data)
		case xml.CharData:
			t.Children = append(t.Children, token.(xml.CharData).Copy())
		case xml.Comment:
			t.Children = append(t.Children, token.(xml.Comment).Copy())
		}
	}
	return nil
}
开发者ID:nobonobo,项目名称:gomobileapp,代码行数:27,代码来源:xmlutil.go

示例12: UnmarshalXML

func (p *Problem) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	pp := struct {
		Id                 string       `xml:"id"`
		Name               string       `xml:"name"`
		Available          string       `xml:"available"`
		ProblemTimeLimit   string       `xml:"problemtimelimit"`
		ProblemMemoryLimit string       `xml:"problemmemorylimit"`
		Status             Status       `xml:"status"`
		SolvedList         []SolvedUser `xml:"solved_list>user"`
	}{}
	if err := d.DecodeElement(&pp, &start); err != nil {
		return err
	}

	available, err := strconv.Atoi(strings.Trim(pp.Available, "\n"))
	problemTimeLimit, err := strconv.Atoi(strings.Trim(pp.ProblemTimeLimit, "\n"))
	problemMemoryLimit, err := strconv.Atoi(strings.Trim(pp.ProblemMemoryLimit, "\n"))
	if err != nil {
		return err
	}

	*p = Problem{
		Id:                 strings.Trim(pp.Id, "\n"),
		Name:               strings.Trim(pp.Name, "\n"),
		Available:          available,
		ProblemTimeLimit:   problemTimeLimit,
		ProblemMemoryLimit: problemMemoryLimit,
		Status:             pp.Status,
		SolvedList:         pp.SolvedList,
	}
	return nil
}
开发者ID:zakuro9715,项目名称:aojgo,代码行数:32,代码来源:problem.go

示例13: UnmarshalXML

func (c *choice) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	for {
		tok, err := dec.Token()
		if err != nil && err == io.EOF {
			return nil
		}
		if err != nil {
			return err
		}
		switch v := tok.(type) {
		case xml.StartElement:
			switch v.Name.Local {
			case "description":
				d := &description{}
				d.commands = c.commands
				dec.DecodeElement(d, &v)
				switch d.Lang {
				case "en":
					c.DescriptionEn = d
				case "de":
					c.DescriptionDe = d
				}
			}
		}
	}
	return nil
}
开发者ID:speedata,项目名称:publisher,代码行数:27,代码来源:commandsxml.go

示例14: UnmarshalXML

func (freq *Freq) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var s string
	if err := d.DecodeElement(&s, &start); err != nil {
		return err
	}
	switch s {
	case "":
		*freq = Freq{0}
	case "always":
		// Use second as the minimum unit of change frequence
		*freq = Freq{time.Second}
	case "hourly":
		*freq = Freq{time.Hour}
	case "daily":
		*freq = Freq{time.Hour * 24}
	case "weekly":
		*freq = Freq{time.Hour * 24 * 7}
	case "monthly":
		*freq = Freq{time.Hour * 24 * 30}
	case "yearly":
		*freq = Freq{time.Hour * 24 * 365}
	case "never":
		// time.Duration is int64
		*freq = Freq{1<<63 - 1}
	default:
		return errors.New("invalid frequence: " + s)
	}
	return nil
}
开发者ID:fanyang01,项目名称:crawler,代码行数:29,代码来源:sitemap.go

示例15: UnmarshalXML

func (agcs *AdGroupCriterions) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
	adGroupCriterionType, err := findAttr(start.Attr, xml.Name{
		Space: "http://www.w3.org/2001/XMLSchema-instance", Local: "type"})
	if err != nil {
		return err
	}
	switch adGroupCriterionType {
	case "BiddableAdGroupCriterion":
		bagc := BiddableAdGroupCriterion{}
		err := dec.DecodeElement(&bagc, &start)
		if err != nil {
			return err
		}
		*agcs = append(*agcs, bagc)
	case "NegativeAdGroupCriterion":
		nagc := NegativeAdGroupCriterion{}
		err := dec.DecodeElement(&nagc, &start)
		if err != nil {
			return err
		}
		*agcs = append(*agcs, nagc)
	default:
		if StrictMode {
			return fmt.Errorf("unknown AdGroupCriterion -> %#v", adGroupCriterionType)
		}
	}
	return nil
}
开发者ID:allan-simon,项目名称:gads,代码行数:28,代码来源:ad_group_criterion.go


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