Hindi Songs

Search About PHP!!!

Thursday, July 9, 2009

Load and Output XML

We want to initialize the XML parser, load the xml, and output it:

Example

< ?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("note.xml");

print $xmlDoc->saveXML();
? >

The output of the code above will be:

Tove Jani Reminder Don't forget me this weekend!

If you select "View source" in the browser window, you will see the following HTML:

< ?xml version="1.0" encoding="ISO-8859-1"? >
<>
<>Tove< /to >
<>Jani< /from >
<>Reminder< /heading >
<>Don't forget me this weekend!< /body >
< /note >

The example above creates a DOMDocument-Object and loads the XML from "note.xml" into it.

Then the saveXML() function to puts the internal XML document into a string, so we can output it.