I try to parse wfs xml structures with PHP 8.1 and have the following snippet:
<?php
$rawContent = file_get_contents('https://www.geobasisdaten.niedersachsen.de/doorman/noauth/WFS_NI_2211_ATKIS_BDLM-Modell-konform?request=getCapabilities&service=wfs&version=1.1.0');
// source: https://numis.niedersachsen.de/trefferanzeige?docuuid=e26aebd6-cc4c-4af2-8be3-8719b808df5d&plugid=/ingrid-group:iplug-csw-dsc-lgln&docid=julvu30Bh4CjFjsS0QgC
// the following works fine:
// $rawContent = file_get_contents('https://pegelonline.wsv.de/webservices/gis/aktuell/wfs?request=GetCapabilities&service=WFS&typename=gk%3Awaterlevels&version=1.1.0');
// source: https://pegelonline.wsv.de
$wfsStructure= new \SimpleXMLElement($rawContent);
$wfsStructure->registerXPathNamespace('wfs', 'http://www.opengis.net/wfs');
$wfsStructure->registerXPathNamespace('ows', 'http://www.opengis.net/ows/1.1');
$wfsStructure->registerXPathNamespace('ogc', 'http://www.opengis.net/ogc');
$resultList = $wfsStructure->xpath('//*[local-name()=\'FeatureType\']');
// same result with following xpath
// $resultList = $wfsStructure->xpath('/wfs:WFS_Capabilities/wfs:FeatureTypeList//wfs:FeatureType');
var_dump($resultList);
The result is kind of boring:
array(105) {
[0]=>
object(SimpleXMLElement)#2 (0) {
}
[1]=>
object(SimpleXMLElement)#3 (0) {
}
[2]=>
object(SimpleXMLElement)#4 (0) {
}
(…)
[103]=>
object(SimpleXMLElement)#105 (0) {
}
[104]=>
object(SimpleXMLElement)#106 (0) {
}
}
So my script detects 104 nodes, but all of them are empty. Do you have any clues why I’m stepping in trouble there? When I call the other wfs source commented in the script above, everything works fine.
You need a couple of tweaks - for example,
$resultList = $wfsStructure->xpath('//*[local-name()=\'FeatureType\']');
doesn't work because you have a single quote sorrounding a single quote instead of a double quote).Try it like this and see if it works. For example, to get the text values of all the
<wfs:OtherSRS>
nodes which are children of the 2nd<wfs:FeatureType>
node:The output should be: