本文整理汇总了Golang中encoding/xml.Decoder类的典型用法代码示例。如果您正苦于以下问题:Golang Decoder类的具体用法?Golang Decoder怎么用?Golang Decoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Decoder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: UnmarshalXML
func (ccs *CampaignCriterions) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error {
cc := NegativeCampaignCriterion{}
for token, err := dec.Token(); err == nil; token, err = dec.Token() {
if err != nil {
return err
}
switch start := token.(type) {
case xml.StartElement:
switch start.Name.Local {
case "campaignId":
if err := dec.DecodeElement(&cc.CampaignId, &start); err != nil {
return err
}
case "criterion":
criterion, err := criterionUnmarshalXML(dec, start)
if err != nil {
return err
}
cc.Criterion = criterion
case "bidModifier":
if err := dec.DecodeElement(&cc.BidModifier, &start); err != nil {
return err
}
case "isNegative":
if err := dec.DecodeElement(&cc.IsNegative, &start); err != nil {
return err
}
}
}
}
*ccs = append(*ccs, cc)
return nil
}
开发者ID:colinmutter,项目名称:gads,代码行数:33,代码来源:campaign_criterion.go
示例2: readSheetsFromZipFile
// readSheetsFromZipFile is an internal helper function that loops
// over the Worksheets defined in the XSLXWorkbook and loads them into
// Sheet objects stored in the Sheets slice of a xlsx.File struct.
func readSheetsFromZipFile(f *zip.File, file *File, sheetXMLMap map[string]string) ([]*Sheet, []string, error) {
var workbook *xlsxWorkbook
var error error
var rc io.ReadCloser
var decoder *xml.Decoder
var sheetCount int
workbook = new(xlsxWorkbook)
rc, error = f.Open()
if error != nil {
return nil, nil, error
}
decoder = xml.NewDecoder(rc)
error = decoder.Decode(workbook)
if error != nil {
return nil, nil, error
}
sheetCount = len(workbook.Sheets.Sheet)
sheets := make([]*Sheet, sheetCount)
names := make([]string, sheetCount)
sheetChan := make(chan *indexedSheet, sheetCount)
for i, rawsheet := range workbook.Sheets.Sheet {
go readSheetFromFile(sheetChan, i, rawsheet, file, sheetXMLMap)
}
for j := 0; j < sheetCount; j++ {
sheet := <-sheetChan
if sheet.Error != nil {
return nil, nil, sheet.Error
}
sheets[sheet.Index] = sheet.Sheet
names[sheet.Index] = workbook.Sheets.Sheet[sheet.Index].Name
}
return sheets, names, nil
}
开发者ID:LuxunForever,项目名称:Leftwood,代码行数:36,代码来源:lib.go
示例3: getWorksheetFromSheet
// getWorksheetFromSheet() is an internal helper function to open a
// sheetN.xml file, refered to by an xlsx.xlsxSheet struct, from the XLSX
// file and unmarshal it an xlsx.xlsxWorksheet struct
func getWorksheetFromSheet(sheet xlsxSheet, worksheets map[string]*zip.File, sheetXMLMap map[string]string) (*xlsxWorksheet, error) {
var rc io.ReadCloser
var decoder *xml.Decoder
var worksheet *xlsxWorksheet
var error error
var sheetName string
worksheet = new(xlsxWorksheet)
sheetName, ok := sheetXMLMap[sheet.Id]
if !ok {
if sheet.SheetId != "" {
sheetName = fmt.Sprintf("sheet%s", sheet.SheetId)
} else {
sheetName = fmt.Sprintf("sheet%s", sheet.Id)
}
}
f := worksheets[sheetName]
rc, error = f.Open()
if error != nil {
return nil, error
}
decoder = xml.NewDecoder(rc)
error = decoder.Decode(worksheet)
if error != nil {
return nil, error
}
return worksheet, nil
}
开发者ID:lasithasenanayake,项目名称:v6engine-deps,代码行数:31,代码来源:xmlWorkbook.go
示例4: readSharedStringsFromZipFile
// readSharedStringsFromZipFile() is an internal helper function to
// extract a reference table from the sharedStrings.xml file within
// the XLSX zip file.
func readSharedStringsFromZipFile(f *zip.File) (*RefTable, error) {
var sst *xlsxSST
var error error
var rc io.ReadCloser
var decoder *xml.Decoder
var reftable *RefTable
// In a file with no strings it's possible that
// sharedStrings.xml doesn't exist. In this case the value
// passed as f will be nil.
if f == nil {
return nil, nil
}
rc, error = f.Open()
if error != nil {
return nil, error
}
sst = new(xlsxSST)
decoder = xml.NewDecoder(rc)
error = decoder.Decode(sst)
if error != nil {
return nil, error
}
reftable = MakeSharedStringRefTable(sst)
return reftable, nil
}
开发者ID:Richardphp,项目名称:noms,代码行数:29,代码来源:lib.go
示例5: UnmarshalXML
func (self *Definitions) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
err = d.DecodeElement(&self.InnerDefinitions, &start)
if err != nil {
return
}
self.XMLName = start.Name
self.Aliases = map[string]string{}
self.Types.Schemas = xsd.SchemaMap{}
for _, schema := range self.Types.Schemata {
self.Types.Schemas[schema.TargetNamespace] = schema
}
for _, attr := range start.Attr {
if _, ok := self.Aliases[attr.Name.Local]; !ok {
self.Aliases[attr.Name.Local] = attr.Value
}
for k := range self.Types.Schemas {
if _, ok := self.Types.Schemas[k].Aliases[attr.Name.Local]; !ok {
self.Types.Schemas[k].Aliases[attr.Name.Local] = attr.Value
}
}
}
return
}
开发者ID:justwatchcom,项目名称:goat,代码行数:28,代码来源:wsdl.go
示例6: 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
示例7: 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
示例8: UnmarshalXML
// UnmarshalXML implements the XML Unmarshaler interface
func (s *Show) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
nfo := showFields{}
if err := d.DecodeElement(&nfo, &start); err != nil {
return err
}
s.Title = nfo.Title
s.Rating = nfo.Rating
s.Plot = nfo.Plot
s.URL = nfo.URL
s.TvdbID = nfo.TvdbID
s.ImdbID = nfo.ImdbID
s.Year = nfo.Year
if nfo.Premiered != "" {
firstAired, err := time.Parse("2006-01-02", nfo.Premiered)
if err != nil {
return err
}
s.FirstAired = &firstAired
}
return nil
}
开发者ID:odwrtw,项目名称:polochon,代码行数:26,代码来源:show.go
示例9: UnmarshalXML
// SEE http://play.golang.org/p/EFXZNsjE4a and
// http://stackoverflow.com/questions/17301149/golang-xml-unmarshal-and-time-time-fields
func (c *customTime) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var v string
d.DecodeElement(&v, &start)
parse, _ := time.Parse(TimeFormat, v)
*c = customTime{parse}
return nil
}
开发者ID:mehulsbhatt,项目名称:eticket-billing-server,代码行数:9,代码来源:transaction_interface.go
示例10: getArrayValue
func getArrayValue(parser *xml.Decoder) (result interface{}, err error) {
var token xml.Token
token, err = parser.Token()
result = []interface{}{}
for {
switch t := token.(type) {
case xml.StartElement:
if t.Name.Local == "value" {
var value interface{}
value, err = getValue(parser)
result = append(result.([]interface{}), value)
}
case xml.EndElement:
if t.Name.Local == "array" {
return result, err
}
}
token, err = parser.Token()
}
return
}
开发者ID:phusl,项目名称:machine,代码行数:26,代码来源:result.go
示例11: XMLText
func XMLText(decoder *xml.Decoder) (string, error) {
r := ""
for {
token, err := decoder.Token()
if err == io.EOF {
return r, io.EOF
}
switch token := token.(type) {
case xml.EndElement:
return r, nil
case xml.CharData:
r += string(token)
case xml.StartElement:
sub, err := XMLText(decoder)
r += sub
if err != nil {
return r, err
}
case xml.Comment: // ignore
case xml.ProcInst: // ignore
case xml.Directive: // ignore
default:
panic("unknown token")
}
}
}
开发者ID:raintreeinc,项目名称:ditaconvert,代码行数:27,代码来源:xmlutils.go
示例12: getStructMember
func getStructMember(parser *xml.Decoder) (member Struct) {
var token xml.Token
token, _ = parser.Token()
member = Struct{}
for {
switch t := token.(type) {
case xml.StartElement:
if t.Name.Local == "name" {
member["name"], _ = getElementValue(parser)
}
if t.Name.Local == "value" {
member["value"], _ = getValue(parser)
}
case xml.EndElement:
if t.Name.Local == "member" {
return member
}
}
token, _ = parser.Token()
}
return
}
开发者ID:phusl,项目名称:machine,代码行数:27,代码来源:result.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: nextElement
// Scan XML token stream to finc next Element (start or end)
func nextElement(p *xml.Decoder) (xml.Token, error) {
for {
t, err := p.Token()
if err != nil {
return xml.StartElement{}, err
}
switch elem := t.(type) {
case xml.StartElement, xml.EndElement:
return t, nil
case xml.CharData:
// https://xmpp.org/rfcs/rfc6120.html#xml-whitespace
// rfc6120, section 1.4: "whitespace" is used to refer to any character
// or characters matching [...] SP, HTAB, CR, or LF.
switch string(elem) {
case " ", "\t", "\r", "\n": //TODO: consider more than one whitespace
log.Println("xmpp: received whitespace ping")
}
case xml.ProcInst:
if !(elem.Target == "xml" && strings.HasPrefix(string(elem.Inst), "version=")) {
log.Printf("xmpp: received unhandled ProcInst element: target=%s inst=%s\n", elem.Target, string(elem.Inst))
}
default:
log.Printf("xmpp: received unhandled element: %#v\n", elem)
}
}
}
开发者ID:twstrike,项目名称:coyim,代码行数:28,代码来源:xml.go
示例15: parseFeed
func parseFeed(d *xml.Decoder) (v Video, err error) {
var feed Feed
err = d.Decode(&feed)
if err != nil {
return
}
if len(feed.Groups) == 0 || len(feed.Groups[0].Titles) == 0 {
err = errors.New("invalid feed")
return
}
group := feed.Groups[0]
found := false
for _, title := range group.Titles {
if title.Type == "plain" {
v.Title = title.Value
found = true
break
}
}
if !found {
v.Title = group.Titles[0].Value
}
v.Duration = time.Duration(group.Duration.Value) * time.Second
return
}
开发者ID:kballard,项目名称:voidbot,代码行数:29,代码来源:youtube.go
示例16: readOptiongroup
func readOptiongroup(attributes []xml.Attr, dec *xml.Decoder) *Optiongroup {
og := &Optiongroup{}
og.ShortDescription = make(map[string]string)
forloop:
for {
t, err := dec.Token()
if err != nil {
break
}
switch v := t.(type) {
case xml.StartElement:
switch v.Name.Local {
case "shortdescription":
lang, text := readShortDescription(v.Attr, dec)
og.ShortDescription[lang] = text
case "classoption":
og.Classoption = append(og.Classoption, readClassoption(v.Attr, dec))
}
case xml.EndElement:
if v.Name.Local == "optiongroup" {
break forloop
}
}
}
return og
}
开发者ID:speedata,项目名称:ltxdoc,代码行数:27,代码来源:xmlreader.go
示例17: ParseList
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
}
开发者ID:voltron42,项目名称:xtraml,代码行数:25,代码来源:choice.go
示例18: readPackageoption
func readPackageoption(attributes []xml.Attr, dec *xml.Decoder) *Packageoption {
po := &Packageoption{}
po.ShortDescription = make(map[string]string)
for _, attribute := range attributes {
switch attribute.Name.Local {
case "name":
po.Name = attribute.Value
case "default":
po.Default = attribute.Value == "yes"
}
}
forloop:
for {
t, err := dec.Token()
if err != nil {
break
}
switch v := t.(type) {
case xml.StartElement:
switch v.Name.Local {
case "shortdescription":
lang, text := readShortDescription(v.Attr, dec)
po.ShortDescription[lang] = text
}
case xml.EndElement:
if v.Name.Local == "packageoption" {
break forloop
}
}
}
return po
}
开发者ID:speedata,项目名称:ltxdoc,代码行数:34,代码来源:xmlreader.go
示例19: UnmarshalXML
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
}
开发者ID:voltron42,项目名称:xtraml,代码行数:29,代码来源:simple.go
示例20: readVariant
func readVariant(attributes []xml.Attr, dec *xml.Decoder) Variant {
variant := Variant{}
variant.Description = make(map[string]template.HTML)
for _, attribute := range attributes {
if attribute.Name.Local == "name" {
variant.Name = attribute.Value
}
}
for {
t, err := dec.Token()
if err != nil {
break
}
switch v := t.(type) {
case xml.StartElement:
switch v.Name.Local {
case "argument":
variant.Arguments = append(variant.Arguments, readArgument(v.Attr, dec))
case "description":
lang, text := readDescription(v.Attr, dec)
variant.Description[lang] = text
}
case xml.EndElement:
if v.Name.Local == "variant" {
return variant
}
}
}
return variant
}
开发者ID:speedata,项目名称:ltxdoc,代码行数:30,代码来源:xmlreader.go
注:本文中的encoding/xml.Decoder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论