Introduction on using PHP to create XML documents

You can create XML documents using the PHP DOM. If you have worked earlier in any script or language using DOM then you can very well work with the PHP DOM too. As with other language you have to first create a new document object.

_______________________________________________


_______________________________________________

The DOM has lot of function like createElement, createTextNode etc which can be used to create an element and to create a text node for an element. Then you can use add the textnode to an element and that element to another element and so on using the appendChild function.

Suppose you have create a new document object using the following command,

$domobj = new DomDocument();

Then you can create an element using command like,

$book = $domobj->createElement("book");
$author = $domobj->createElement("author");
$authtext = $domobj->createTextNode("Jeffrey Archer");

Now to add the elements to the document object, you have to perform the following commands,

$author->appendChild($authtext);
$book->appendChild($author);
$domobj->documentElement->appendChild($book);

Now you are free to save that XML file or print it out on the screen.

OASIS Interoperability Demo Features Eight Open Source and Commercial Implementations of OpenDocument Format (ODF) 1.2 ...
BUDAPEST, Hungary--(BUSINESS WIRE)--OpenOffice.org Conference (OOoCon) in Budapest showcased both open source and commercial software applications processing ODF documents from the Louvre

Oracle lawsuit unlikely to prompt Java forking
Oracle's lawsuit against Google over Java patents could alienate some people in the Java space, but the litigation is not likely to prompt a forking of the Java platform itself, the founder of the popular Spring Framework for Java development said on Wednesday.

Ferrari Recalls 458 Italias After A Spate Of Fires
Ferrari recalled more than 400 luxury Italia cars Wednesday after reports that a design fault could cause them to catch fire.

RSS Not Parsed -- Please Refresh Page


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?