-
-
Save blide/4f49b774c3cbb24e3116 to your computer and use it in GitHub Desktop.
Revisions
-
blide created this gist
Jul 30, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ package main import ( "encoding/xml" "fmt" "os" "runtime" ) type DrugStores struct { XMLName xml.Name `xml:"DrugStores"` Stores []DrugStore `xml:"DrugStore"` } type DrugStore struct { XMLName xml.Name `xml:"DrugStore` AgentName string `xml:"agentName"` Items []Item `xml:"Item"` } type Item struct { XMLName xml.Name `xml:"Item"` ItemName string `xml:"itemName"` } var c = make(chan int, 5) func main() { runtime.GOMAXPROCS(runtime.NumCPU()) xmlFile, err := os.Open("goods.xml") if err != nil { return } stores := DrugStores{} decoder := xml.NewDecoder(xmlFile) for { t, _ := decoder.Token() switch se := t.(type) { case xml.StartElement: if se.Name.Local == "DrugStore" { var store DrugStore decoder.DecodeElement(&store, &se) fmt.Println(len(store.Items)) stores.Stores = append(stores.Stores, store) fmt.Println(len(stores.Stores)) } } } }