Reputation: 2198
i have the following structure in an xml-element:
<assets>
<icon id="1" type="grave" x="586" y="477">
<text short="hello world" tooltip="" tteng=" "/>
</icon>
</assets>
Now, using PHP
, i try to find this specific node
with xpath
. I have to find this node by the short-value in the <text>
snippet.
So, i need to get the parent of
<text="hello world" ... >
I was looking on php.net
, but it didn't helped me that much.
What i tried is this:
$node = $xml->xpath('//text="hello world"');
but that didn't do the trick.
Regarding to the info from marc-b i added the following to my function:
public static function loadValuesFromNode($fileName, $name) {
var_dump($name); // echoes "hello world"
$xml = simplexml_load_file(self::$xmlDir . "/" . $fileName); // correct path, already tested
$node = $xml->xpath('//text[@short="'.$name.'"]');
var_dump($node); // empty -> (array(0) { }
}
If i change the xpath to:
'[@short="'.$name.'"'] (so without the text-thingy)
it returns "false";
Thanks in advance :)
Upvotes: 0
Views: 438
Reputation: 360892
To test an attribute's contents, you need
//node[@attribute="value"]
so
//text[@short="hello world"]
Upvotes: 1