Reputation: 13
I am trying to display a list of all the tags in a XML file. But I can't seem to do it. [
This is the XML I am tying to read the tags from: https://i.sstatic.net/9bYHi.png
If someone knows a way to keep the tree struckture of the xml file and trasfer it into an array. That would be really helpfull.
My question is different because I don't know the contents of the xml file. My image is just an example. I am looking for a solution that reads all the tags from an xml file and also keeps the tree structure when putting it in an array.
Upvotes: 0
Views: 243
Reputation: 46
I always use xml_parser_create, so you could do the following
$yourxmlfile = "pathto/yourfilename.xml";
$xmldata = file_get_contents($yourxmlfile);
$p = xml_parser_create();
xml_parse_into_struct($p, $xmldata, $vals, $index);
xml_parser_free($p);
print_r($vals);
that should print the xml structure as an array, see http://php.net/manual/en/function.xml-parse-into-struct.php for more info about it
Upvotes: 1