
Sample code for XML parsing with PHPThere are lots of examples on using XML with PHP in the internet. A simple search would provide you a lot of code to work with. For example if you want to load an XML document 'books.xml', then you can use the following code.
_______________________________________________ $domobj =
new DomDocument(); Suppose you want to get all the names of the authors in the XML file, then you can do so by, $authors = $domobj->getElementsByTagName("author"); The above code would get an array of all the authors available in the XML file. If you want to print out all the authors, then you have to use a foreach loop to print out as given below: foreach($authors
as $authnode) { The same example can also be done by using the XPath query to navigate through all the authors in the XML document. This can be done like, $xptoauthor
= new domxpath($domobj); You can try these samples on your own to have a feel on how easy it is to work with XML and PHP.
|
Cisco
CCNA Certification Video Tutorial Guide - Learn How to Pass the Cisco
CCNA 640-802 Exam... Guaranteed!
| |||
|
| ||||