當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。