我有一个450万行的XML文件,但是我想不出一种方法使用解码器.DecodeElement()函数来解析信息。
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>
因此,以上内容构成了XML文件的一行。我的目标是提取“ t”和“ id”。
我目前的尝试涉及创建一个结构:
type DT struct {
id string `xml:"Data"` // This is my attempt to get the entire Data portion/segment/chunk(?)
}
执行实际解码的代码:
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)
}
}
}
上面的代码在运行时输出
&{}
这告诉我无法解析任何信息。当我输出时也是如此
fmt.Println(&dt.id)
有人可以帮我吗。我不确定我的输出为空的原因是由于我在struct中提取的方式还是解码问题。
相关分类