--我需要一些帮助! --我正在尝试使用php解析一个带有GML标记的文件。我使用simplexml_load_file函数解析我的文件,除了gml:标记之外,它运行得很好。
以下是文件:
<par>
.....
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>
{{ DATAS I WOULD LIKE TO PARSE}}
</gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
</gml:Polygon>
......
</par>下面是我使用的代码:
<?php
if (file_exists('doc.xml')) {
$xml = simplexml_load_file('doc.xml');
}
...
foreach ($xml->...->par->{'gml:Polygon'}->{'gml:outerBoundaryIs'}->{'gml:LinearRing'}->{'gml:coordinates'} as $coords) {
echo $coords;
echo '<br>';
}运行这段代码,我就明白了:
警告:尝试在第44行的\www\xmlphptest\index.php中读取null上的属性"gml:LinearRing“
警告:尝试在第44行的\www\xmlphptest\index.php中读取null上的属性“gml:坐标”
警告: foreach()参数的类型必须是数组\对象,在第44行的\www\xmlphptest\index.php中给出null
你能帮帮我吗!谢谢:)
发布于 2021-10-20 20:25:21
在php文档中找到的。与xml相关的名称空间:https://www.php.net/manual/fr/simplexmlelement.registerxpathnamespace.php。
谢谢
https://stackoverflow.com/questions/69649471
复制相似问题