使用eclipse在C++中读取openstreetmap XML文件
Reading a openstreetmap XML file in C++ using eclipse
我是xml的新手。我正在尝试读取一个从openstreetmaps中获取的xml文件。它看起来像
<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="CGImap 0.0.2">
<bounds minlat="48.3994690" minlon="9.9897780" maxlat="48.3998220" maxlon="9.9898260"/>
<node id="149248718" lat="48.3994984" lon="9.9897961" user="Matthias Frank" uid="287306" visible="true" version="7" changeset="7966729" timestamp="2011-04-25T18:01:43Z"/>
<node id="1831376336" lat="48.3995041" lon="9.9898087" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:51Z"/>
<node id="1831376346" lat="48.3995599" lon="9.9902392" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376331" lat="48.3993243" lon="9.9898198" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:51Z"/>
<node id="1831376349" lat="48.3996127" lon="9.9906471" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376348" lat="48.3996044" lon="9.9910549" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376418" lat="48.4000685" lon="9.9897909" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:55Z"/>
<node id="1831376350" lat="48.3996158" lon="9.9908451" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:52Z"/>
<node id="1831376374" lat="48.3999450" lon="9.9897917" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:54Z"/>
<way id="172207897" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:02:59Z">
<nd ref="1831376348"/>
<nd ref="1831376350"/>
<nd ref="1831376349"/>
<nd ref="1831376346"/>
<nd ref="1831376336"/>
<tag k="bicycle" v="yes"/>
<tag k="highway" v="living_street"/>
<tag k="name" v="Hintere Rebengasse"/>
<tag k="oneway" v="yes"/>
</way>
<way id="172207928" user="NUP" uid="168758" visible="true" version="1" changeset="12345652" timestamp="2012-07-19T20:03:01Z">
<nd ref="1831376331"/>
<nd ref="1831376336"/>
<nd ref="1831376374"/>
<nd ref="1831376418"/>
<tag k="bicycle" v="yes"/>
<tag k="highway" v="living_street"/>
<tag k="name" v="Pfauengasse"/>
<tag k="oneway" v="yes"/>
</way>
</osm>
读取数据的最简单和最短的方法是什么?例如,从节点中,我想读取id、lat、lon,对于每个节点,我也想保存这些信息。对于作为"方式"的元素,我想阅读附在它上面的ref和"标签"元素。
我使用的是简单的fstream,但它看起来不是最有效的方式。
请帮助
您可以也应该使用XML解析器:
http://lars.ruoff.free.fr/xmlcpp/
对于轻量级解析,我通常使用RapidXml。它快速且易于使用(至少从我的角度来看)
您应该使用XML解析库。哪一个取决于你。目前,我正在研究tinyxml,但我还没有使用它,所以我不能支持它。不过,它看起来确实很简单,可以合并到一个项目中。
相关文章:
- Cppcheck生成xml转储文件
- 如何在pugixml中获取节点的内部XML
- 如何使用tinyxml2从XML加载父实体和子实体
- boost xml parsingl将xml的路径作为变量发送
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- 使用 Tinyxml 在 xml 中添加一个子子项
- 增强基于 XML class_id的反序列化
- 在 c++ 中使用 vtd-xml 时,如何摆脱 EOFException?
- 防止在C++中选择错误文件时提升 xml 解析器崩溃
- c++ 读取 xml 文件的内容
- 删除 XML 文件中的子节点C++
- 使用 RapidXML 更新C++中的 XML 节点和属性值
- 在Cmake构建CmakeList.txt中读取/解析XML文件
- 从 XML 中读取未指定结构的每个数据成员
- XML to XML XSLT transformation. MSXML in VBScript
- 将 QGraphicsView 或 Scene 转换为 XML/JSON
- Qt 写入 xml: QIODevice::write (QFile, "D:/logs.xml" ): 设备未打开
- 使用 libxml2 解析 XML 文件时缺少元素值
- 为什么TinyXML2的XMLDocument::FirstChild()函数在尝试解析这个有效的XML文件时返回NULL?
- 使用eclipse在C++中读取openstreetmap XML文件