英文:
Parsing arbitrary XML in Go
问题
我想使用Go语言解析任意的XML并提取特定的标签。例如,如果我们有以下XML:
<foo>
Hello, world.
<bar attr="true" />
</foo>
我想提取<bar attr="true" />
,并且还想以字符串的形式访问“其他”数据,而不必担心它是什么。我不想定义文档可能包含的每个可能的XML标签,只想提取我想要的标签。
有人可以帮忙指导如何实现吗?提前感谢。
英文:
I want to use Go to parse arbitrary XML and pick out specific tags. For example if we have:
<foo>
Hello, world.
<bar attr="true" />
</foo>
I want to pick out <bar attr="true" />
, and also be able to access the "other" data as a string without having to worry about what it is. I don't want to have to define every possible XML tag the document could contain - only the ones I want to pick out.
Could someone help advise how this can be done? Thanks in advance.
答案1
得分: 2
我认为你想要的是一个XPath库,对吗?试试这个:http://godoc.org/launchpad.net/xmlpath
英文:
I think what you want is an xpath library, right? try this one: http://godoc.org/launchpad.net/xmlpath
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论