How
to use PHP DOM functions to create XML
Do
you need to create XML using PHP? Then you can use the PHP DOM functions
to create an XML file. If you have worked with PHP 4 earlier then there
is a slight change in the syntax of PHP 5. It is easy to work with this
syntax if you have already worked with the browser's DOM functions.
_______________________________________________
The new
DomDocument() function is used to create a new DOM Document object.
After creating the new document object, you can add elements to it using
the document object's createElement() method.
Using this
method you can create the different elements that are needed for the
document. Suppose you want to add a text content to the particular node
you can use the createTextNode() method to create the text node and
then use appendChild() method to append that text node to any element
of your choice.
Then append
that element to the root node of the XML document using the same appendchild()
method. Now you can save the XML to another file also or print it out
in the browser.