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.



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.

_______________________________________

Recommended XML Books

cover
cover
cover
cover
cover
cover






 

 

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!


New XML Books Titles - Best Seller's @ Amazon.com

Visit XML Training Material Guide Homepage

Technology helps engage students - how do classroom instruction and social dynamics change when the classroom is completely dependant on modern technology?

Cisco CCNA Certification Video Tutorial Guide - Learn How to Pass the Cisco CCNA 640-802 Exam... Guaranteed!

Train Signal Computer Training