1

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

Armand
  • 9,847
  • 9
  • 42
  • 75

5 Answers5

0

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

Javatar
  • 665
  • 2
  • 10
  • 17
0

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

hakre
  • 193,403
  • 52
  • 435
  • 836
0

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

  • if you don't know xpath see this: http://my.opera.com/pp-layouts/blog/2009/11/23/css-selectors-2-xpath –  Oct 04 '11 at 13:13
0

SimpleXMLElement

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

M. Suleiman
  • 858
  • 4
  • 22