XML:查詢多名稱空間的XML
<lev:Locatie axisLabels="x y" srsDimension="2" srsName="epsg:28992" uomLabels="m m">
<gml:exterior xmlns:gml="http://www.opengis.net/gml">
<gml:LinearRing>
<gml:posList>
222518.0 585787.0 222837.0 585875.0 223229.0 585969.0 223949.0 586123.0 223389.0 586579.0 223305.0 586564.0 222690.0 586464.0 222706.0 586319.0 222424.0 586272.0 222287.0 586313.0 222054.0 586517.0 221988.0 586446.0 222174.0 586305.0 222164.0 586292.0 222172.0 586202.0 222232.0 586143.0 222279.0 586149.0 222358.0 586076.0 222422.0 586018.0 222518.0 585787.0
</gml:posList>
</gml:LinearRing>
</gml:exterior>
</lev:Locatie>
我需要去的GML:posList。我嘗試以下
的SimpleXML:
$xmldata = new SimpleXMLElement($xmlstr);
$xmlns = $xmldata->getNamespaces(true);
$retval = array();
foreach($xmldata as $attr => $child) {
if ((string)$child !== '') {
$retval[$attr] = (string)$child;
}
else {
$retval[$attr] = $child->children($xmlns['gml']);
}
}
var_export($retval);
的XPath:
$domdoc = new DOMDocument();
$domdoc->loadXML($xml);
$xpath = new DOMXpath($domdoc);
$xpath->registerNamespace('l', $xmlns['lev']);
$xpath->registerNamespace('g', $xmlns['gml']);
var_export($xml->xpath('//g:posList'));
如果我查詢列弗屬性:地區,我可以讓他們,但是,我似乎無法檢索GML :posList的值或例如gml:exterior的屬性。我知道我做錯了什麼,我只是沒有看到什麼...
謝謝托馬斯,我會試試看 –