C++ 在C++;使用eclipse

C++ 在C++;使用eclipse,c++,xml,eclipse,dom,openstreetmap,C++,Xml,Eclipse,Dom,Openstreetmap,我是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="

我是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和“tag”元素

我正在使用简单的fstream,但它看起来不是最有效的方式


请帮助

您应该使用XML解析库。哪一个取决于你。目前,我正在寻找tinyxml,但我还没有使用它,所以我不能认可它。不过,将它合并到项目中看起来非常简单。

您可以而且应该使用XML解析器,而不是再次发明轮子:

对于轻量级解析,我通常使用RapidXml。它速度快且易于使用(至少在我看来)