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

2
  • Well, what do you think? And what have you tried so far? Commented Oct 4, 2011 at 13:09
  • possible duplicate of Best XML Parser for PHP Commented Oct 4, 2011 at 13:09

5 Answers 5

5

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:

How to Parse XML File in PHP

Parsing XML with PHP's simpleXML

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

Comments

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

Comments

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

Comments

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

1 Comment

0

SimpleXMLElement

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

Comments

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.