pugixml不生成输出

时间:2016-10-18 13:28:24

标签: c++ pugixml

我尝试使用pugixml将.xml文件读取到我的C ++程序中。 问题是,即使是第一个例子也不行。

我的.xml看起来像这样:

<?xml version='1.0' encoding='UTF-8'?>
 <trk>
    <name bahn="Bahn 1"/>
    <trkseg>
      <trkpt lat="48.0815471" lon="11.2745363">
      </trkpt>
      <trkpt lat="48.0815471" lon="11.2745363">
      </trkpt>
    </trkseg>
  </trk>
  <trk>
    <name bahn ="Bahn 2"/>
    <trkseg>
      <trkpt lat="48.08161089580602" lon="11.274945462810345">
      </trkpt>
      <trkpt lat="48.08161089580602" lon="11.274945462810345">
      </trkpt>
    </trkseg>
  </trk>

我尝试使用

加载文档
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("kreisel_argelsriederfeld.xml");
std::cout<<"Load result: " << result.description()<<", mesh name"<< doc.child("name").attribute("bahn").value()<<std::endl;


pugi::xml_node bahnen = doc.child("trkseg");
std::cout << bahnen.value()<<std::endl;

虽然当我调用它时,输出到达", mesh name",之后只显示空白区域。我的错误在哪里?是因为我说错了名字还是那样的?作为&#34;加载结果&#34;我得到&#34;没有错误&#34;,所以应该加载文件,不是吗?我找到了几个示例和教程,但所有这些都使用它来加载文件。

1 个答案:

答案 0 :(得分:1)

该文件无效XML(仅允许一个顶级Perl Code: my $ff = File::Fetch->new(uri => "$uri"); my $where = $ff->fetch ( to => "$DOWNLOAD_LOCATION" ); print Dumper($ff); Output: Fetch failed! HTTP response: 502 Bad Gateway [502 notresolvable] at <path>\myfile.pl line 249. Dumper Output: $VAR1 = bless( {'vol' => '', 'file_default' => 'file_default', '_error_msg' => 'Fetch failed! HTTP response: 502 Bad Gateway [502 notresolvable]', 'file' => 'myfilename.zip', 'scheme' => 'http', 'path' => '/repository/download/buildlabel/1042086:id/', '_error_msg_long' => 'Fetch failed! HTTP response: 502 Bad Gateway [502 notresolvable] at C:/Perl/lib/File/Fetch.pm line 598. 元素)。见pugixml error handling example

如果您想拥有多个<trk>,则需要将它们包含在一个顶级<trk>元素中。

编辑:错过了关于没有错误的部分。也许pugixml在这里是宽容的,真正的问题是<trks>被认为是文档节点的子节点。因此,而不是<trk>尝试doc.child("name")