我有一個450萬行的XML文件,但是我想不出一種方法使用解碼器.DecodeElement()函數(shù)來解析信息。XML的摘要:<dt xmlns:directive="d" xmlns:ref="ref"> <Data> <directive:Entry Name='abcd'> <list> <map> <directive:Entry Name='id'> <Integer>21</Integer> </directive:Entry> <directive:Entry Name='t'> <Date>T14:31:43.823Z</Date> </directive:Entry> </map> </list> </directive:Entry> </Data></dt>因此,以上內(nèi)容構(gòu)成了XML文件的一行。我的目標(biāo)是提取“ t”和“ id”。我目前的嘗試涉及創(chuàng)建一個結(jié)構(gòu):type DT struct { id string `xml:"Data"` // This is my attempt to get the entire Data portion/segment/chunk(?)}執(zhí)行實際解碼的代碼:decoder := xml.NewDecoder(readInFile())for { t, _ := decoder.Token() if t == nil { break } switch se := t.(type) { case xml.StartElement: inE := se.Name.Local if inE == "dt" { var dt DT decoder.DecodeElement(&dt, &se) fmt.Println(&dt) } }}上面的代碼在運行時輸出&{}這告訴我無法解析任何信息。當(dāng)我輸出時也是如此fmt.Println(&dt.id)有人可以幫我嗎。我不確定我的輸出為空的原因是由于我在struct中提取的方式還是解碼問題。
- 2 回答
- 0 關(guān)注
- 268 瀏覽
添加回答
舉報
0/150
提交
取消