Using DOM, XML and PHP to parse XML

XML documents can be parsed using DOM and PHP easily. You can also use XPath for more precise navigation and retrieval of the contents of the nodes.


_______________________________________________


To parse an XML document, first you have to create a document object to load the XML file in it. Once you have loaded the document, you can use the getElementsByTagName method to get all the elements that have a particular node name. Using the foreach loop you can print all the elements that you have retrieved.

If you are going to use XPath then you can make more precise queries on the XML document. for example if you want to query all the authors available in your XML file, you could use something like, "/books/book/author" in your XPath query.

Suppose you want only the author name of the book in the 5th position then you could use a query like, "/books/book[position()=5]/author". A good knowledge on using XPath will help you a lot in navigating an XML document.




_______________________________________________

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________








 

 

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.