I have the following type of XML structure:
<catalog xmlns="http://www.namespace.com">
<product product-id="test-product">
<page-attributes>
<page-title xml:lang="en">test</page-title>
<page-title xml:lang="de">test2</page-title>
</page-attributes>
</product>
</catalog>
I used the following to fetch the product and it's page-title
elements:
$xml->registerXPathNamespace('ns', $xml->getNamespaces()[""]);
$xpath = '//ns:product[@product-id="test-product"]';
$product = $xml->xpath($xpath)[0];
foreach ($product->{'page-attributes'}->{'page-title'} as $title) {
var_dump($title);
var_dump($title->{"@attributes"});
var_dump($title->attributes());
}
But I just get:
object(SimpleXMLElement)#4 (0) {
}
object(SimpleXMLElement)#6 (0) {
}
object(SimpleXMLElement)#6 (0) {
}
object(SimpleXMLElement)#6 (0) {
}
object(SimpleXMLElement)#4 (0) {
}
object(SimpleXMLElement)#4 (0) {
}
How do I get the values of the page-title
elements (test
,test2
)? Also how do I get the attributes? The attributes have xml:
in front of them. Does that mean just the attributes are in their own namespace?