Php 在DomDocument中按id获取节点是否很热?

Php 在DomDocument中按id获取节点是否很热?,php,domdocument,overpass-api,Php,Domdocument,Overpass Api,我从立交桥api得到这个结果-这是街道 <?xml version="1.0" encoding="UTF-8"?> <osm version="0.6" generator="Overpass API"> <note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note> <

我从
立交桥api
得到这个结果-这是街道

<?xml version="1.0" encoding="UTF-8"?>
<osm version="0.6" generator="Overpass API">
<note>The data included in this document is from www.openstreetmap.org. The data is made available under ODbL.</note>
<meta osm_base="2013-12-03T12:52:02Z"/>

  <node id="1549294055" lat="49.4310141" lon="7.5117213"/>
  <node id="1549294085" lat="49.4313484" lon="7.5126816"/>
  <node id="1549294087" lat="49.4315384" lon="7.5132431"/>
  <node id="1549294093" lat="49.4318250" lon="7.5140125"/>
  <node id="1549294094" lat="49.4318541" lon="7.5140969"/>
  <node id="1549294104" lat="49.4322262" lon="7.5151568"/>
  <node id="1549294106" lat="49.4324901" lon="7.5159332"/>
  <node id="1552775307" lat="49.4328287" lon="7.5169585"/>
  <node id="1552775309" lat="49.4328551" lon="7.5170364"/>
  <node id="1552775318" lat="49.4330332" lon="7.5176039"/>
  <node id="1552775347" lat="49.4333308" lon="7.5186515"/>
  <node id="1552775375" lat="49.4341515" lon="7.5215118"/>
  <node id="1552775408" lat="49.4345873" lon="7.5229784"/>
  <node id="1552775447" lat="49.4358841" lon="7.5273364"/>
  <node id="1552775464" lat="49.4367267" lon="7.5302234"/>
  <node id="1552809430" lat="49.4368016" lon="7.5304614"/>
  <way id="28367045">
    <nd ref="1549294106"/>
    <nd ref="1552775307"/>
    <nd ref="1552775309"/>
    <nd ref="1552775318"/>
    <nd ref="1552775347"/>
    <nd ref="1552775375"/>
    <nd ref="1552775408"/>
    <nd ref="1552775447"/>
    <nd ref="1552775464"/>
    <nd ref="1552809430"/>
    <tag k="highway" v="secondary"/>
    <tag k="ref" v="L 356"/>
  </way>
  <way id="141545567">
    <nd ref="1549294104"/>
    <nd ref="1549294106"/>
    <tag k="bridge" v="yes"/>
    <tag k="highway" v="secondary"/>
    <tag k="layer" v="1"/>
    <tag k="ref" v="L 356"/>
  </way>
  <way id="141545568">
    <nd ref="1549294055"/>
    <nd ref="1549294085"/>
    <nd ref="1549294087"/>
    <nd ref="1549294093"/>
    <nd ref="1549294094"/>
    <nd ref="1549294104"/>
    <tag k="highway" v="secondary"/>
    <tag k="ref" v="L 356"/>
  </way>

</osm>

下面的代码应该在节点之间循环,这听起来像是您正在尝试做的事情。您拥有的代码在标记之间循环,每个标记下的标记不包含任何ID

$doc = new DOMDocument;
$doc->loadXML($result);

$nodes = $doc->getElementsByTagName('node');

foreach ($nodes as $node) {
    $id = intval($node->getAttribute('id'));
    $lat = intval($node->getAttribute('lat'));
    $lon = intval($node->getAttribute('lon'));

    var_dump($node);
}

希望这至少能帮助您走上正轨。

预期的输出是什么?我不使用
getElementById
,而是使用一个XPath表达式。类似于:
$xpath=newdomxpath($doc)$elem=$xpath->query(“/*[@id='$id']”)->item(0)@CBroe,谢谢,现在我看到问题了。。。您可能对如何将
DTD
添加到现有的
DOMDocument
对象有一些想法?我是谷歌的,openstreetmap的唯一一件事就是跟踪@AmalMuralis提示。@CBroe是的,会出现很多硬代码。。。我想我最好使用
simplexml\u load\u string
和一次循环遍历所有xml。我需要通过
方式通过ID获取所有节点。不仅仅是循环槽节点。
$doc = new DOMDocument;
$doc->loadXML($result);

$nodes = $doc->getElementsByTagName('node');

foreach ($nodes as $node) {
    $id = intval($node->getAttribute('id'));
    $lat = intval($node->getAttribute('lat'));
    $lon = intval($node->getAttribute('lon'));

    var_dump($node);
}