Armand
Armand

Reputation: 10264

What XML parser to use with PHP

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

Answers (5)

M. Suleiman
M. Suleiman

Reputation: 848

SimpleXMLElement

You could also take a look at: http://www.w3schools.com/php/php_xml_simplexml.asp. (maybe Expat too)

Upvotes: 0

user652649
user652649

Reputation:

the best is

http://www.php.net/dom

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

hakre
hakre

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:

PHP XML Manipulation

Upvotes: 0

Javatar
Javatar

Reputation: 665

Why not using google? This will be usefull:

http://ditio.net/2008/12/01/php-xpath-tutorial-advanced-xml-part-1/

http://lv.php.net/DOMDocument

Upvotes: 0

Related Questions