how to get tag data by a specific attribute (id) let's say attribute data 54. http://joxi.ru/v29Q4Y5TZzdqZ2
1 answer
You can implement it based on this example:
(file.xml)
<?xml version="1.0" encoding="UTF-8"?> <list> <item type="Language"> <name>PHP</name> <link>www.php.net</link> </item> <item type="Database"> <name>Java</name> <link>www.oracle.com/br/technologies/java/</link> </item> </list>
Php
<?php $xml = simplexml_load_file("file.xml"); foreach($xml->children() as $child) { $role = $child->attributes(); foreach($child as $key => $value) { if($role == "Language") { echo("[".$key ."] ".$value . "<br />"); } } }
Result:
[name] PHP [link] www.php.net
Sources:
- PHP.net: https://www.php.net/simplexmlelement.attributes
- Another topic on your English-language sources: https://stackoverflow.com/questions/1652128/accessing-attribute-from-simplexml
|