【发布时间】:2021-10-20 16:05:41
【问题描述】:
我需要帮助! 我正在尝试使用 php 解析带有 GML 标签的 XML 文件。我正在使用 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:coordinates”
警告:foreach() 参数必须是数组|对象类型,在第 44 行的 \www\xmlphptest\index.php 中给出 null
你能帮帮我吗! 谢谢:)
【问题讨论】:
-
您好,请考虑添加“最小可重现示例”stackoverflow.com/help/minimal-reproducible-example