XmlPullParser获取子节点
我正在使用 Android 的 XmlPullParser 处理 OpenStreetMap (.osm) 文件。我遇到问题的部分是这样的:
<way id='-13264' action='modify' visible='true'>
<nd ref='-13252' />
<nd ref='-13251' />
<nd ref='-13249' />
</way>
我需要使用每个路节点中的 nd- 节点,一次一个路节点(这是关键),准确地说,在这些节点之间创建某种数据结构。 似乎没有方便的方法来获取 XmlPullParser 中一个节点的所有子节点,因此我在这些节点上尝试了很多嵌套的 if/elseif- 内容,但无法让它工作。有人可以为我提供一些示例代码来处理节点的子节点,但保持相似父节点的子节点分开吗?
I'm working with an OpenStreetMap (.osm) file with Android's XmlPullParser. The part I'm having problems with is this:
<way id='-13264' action='modify' visible='true'>
<nd ref='-13252' />
<nd ref='-13251' />
<nd ref='-13249' />
</way>
I need to work with the nd- nodes within every way- node, one way- node at a time (that's the crux), creating a certain data structure between those nodes to be precise.
There seems to be no convenient method to get all the child nodes of one node in the XmlPullParser, so i tried a lot of that nested if/elseif- stuff on those nodes, but can't get it to work. Can someone provide me with some sample code to work with child nodes of a node, but keeping the child nodes of similar parent nodes seperate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我解析这个的方式。您可以自由使用它,但您必须自己实现
Way
类! :)当然,如果您收到的 xml 略有不同,那么这个确切的代码可能无法工作。再次,我将把它作为提问者的练习。
This is how I would parse this. You are free to use it, but you will have to come up with the implementation for the
Way
class on your own! :)Of course if the xml coming to you is even a slight bit different this exact code may not work. Again, I will leave that as an exercise for the asker.
您可以使用以下代码:
You can use the following code: