Parsing XML using PHP4
By Burhan Khalid2005-08-16
eXtensible Markup Language or XML as its commonly called is primarily used to facilitate the interchage of information between environments that are not compatible natively (that is, they don’t support each other’s default file format). An example here would be a database server that doesn’t import Access files and has its own propriety data format.
The key word in XML is extensible. This means that the structure of the file is left entirely up to the creator. There are simply a few rules that you must follow to create XML (one such rule being that there can be only one root element). Other than that, the end user has free reign as to the tags that he may use, attributes, etc. One more thing about XML that we must understand is that there is no tag set for XML. Like HTML, which has a set of tags (<p>, etc.), XML has no pre-set tags. It is up to the end user to define tags for a file. In XML, a tag can be almost anything :
- <jim>info about jim</jim>
- <address type="home">555 Main Street</address>
A few more rules about XML and we will be on our way to our PHP code. XML documents must be well-formed. This means that there can be only one root element (the top most element), all child elements must be nested properly <p>foo<b>bar</b></p> not <p>foo<b>bar</p></b>, and all elements must have end tags.
In XML, an element is also referred to as a node.
Once these simple rules are understood, we can start creating a XML document that a XML parser will understand.
Tutorial pages:
|
© 2004-2005 Burhan Khalid
|
|||||||||
You might also want to check these out:
|
Link to This Tutorial Page!

