How to access an XML document in PHP

There two common ways to access an xml document using PHP. One is the usual Document Object Model and the other is by using the SAX parser that comes with all the installation of PHP.


Using the Document Object Model is the common way used by many developers to access the xml documents. You might have worked with the DOM in other languages too. The steps are the same.

The first step is to create a new document object using the command, new DOMDocument(); and the next step is to load the xml file into that object. For this you can use the command, load('xmlfilename.xml').

After this is done you can navigate through the xml document using the functions like getElementsByTagName. By using this function you can store all the nodes in a particular array and then use the array's item(n)->nodeValue to get the values of the nodes, where n is the node number.

You can also access the xml document using the SAX parser that comes with the installation of PHP. It is lightweight and that is the advantage of using it. Moreover it can also be used for large xml files.



SetApp - 100 Apps for everything you ever wanted to do on Mac

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

 

 

“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

Copyright - © 2004 - 2019 - All Rights Reserved.