0

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.

3

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

glad I could help :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.