With this XML file with structure:
<?xml version="1.0"?>
<element>
<child attrName="something"/>
</element>
i can access with php to read attrName value with expression:
<?php
$xml = simplexml_load_file("fileAbove.xml") or die("Error: Cannot create object");
foreach($xml->children() as $child) {
if($child->getName() == "element") {
$attrValue = $xml->xpath('/element/child/@attrName');
echo $attrValue;
}
}
?>
So result will be:
something
But how with this file structure i can't get attrValue with same php code from above?
<?xml version="1.0"?>
<element someAttr="" otherAttr="">
<child attrName="attrValue"/>
</element>
I'm geting error:
Notice: Undefined offset: 0
Does anybody know what i miss?
Thank you