Reputation: 10264
I want to open and read an XML file using php, but I wont be able to know the names of the elements in the xml file, I will only know the structure. What I want to know is, is there a framework or class build into php which can open the xml file and then loop through the elements and retrieve the name of the element and the text value of the element and a check that returns true if the element has children?
Thanks
Upvotes: 1
Views: 702
Reputation: 71160
You should look at SimpleXML:
http://php.net/manual/en/class.simplexmlelement.php
Take a look here:
http://debuggable.com/posts/parsing-xml-using-simplexml:480f4dfe-6a58-4a17-a133-455acbdd56cb
http://www.w3schools.com/PHP/php_xml_simplexml.asp
But most importantly, searching SO often has answers to what you need:
Parsing XML with PHP's simpleXML
Upvotes: 5
Reputation: 848
You could also take a look at: http://www.w3schools.com/php/php_xml_simplexml.asp. (maybe Expat too)
Upvotes: 0
Reputation:
the best is
it is really easy to use and powerful
all xml implementations in php are libxml based so you need to choose the right API for you
and i think DOM is the easiest and the most complete one!
bye
Upvotes: 0
Reputation: 197787
What I want to know is, is there a framework or class build into php which can open the xml file and then loop through the elements and retrieve the name of the element and the text value of the element and a check that returns true if the element has children?
Yes there is. Buit-in XML functions can be found in the PHP manual, there are a lot:
Upvotes: 0
Reputation: 665
Why not using google? This will be usefull:
http://ditio.net/2008/12/01/php-xpath-tutorial-advanced-xml-part-1/
Upvotes: 0