本文整理汇总了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
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng