Tuesday, January 11, 2011

Create and Send Xml in php

To create and send xml in php, the php code looks like this:

<?php

        // Start XML file, create parent node
        $doc = new DOMDocument();
        $doc->formatOutput = true;
        $node = $doc->createElement("rootnode");
        $parnode = $doc->appendChild($node);
        
        $node = $doc->createElement("childnode");
        $newnode = $parnode->appendChild($node);

        $newnode->setAttribute("description", "Some Description Text");
        $xmlfile = $doc->saveXML();
        header("Content-type: text/xml");
        echo $xmlfile;
?>

No comments:

Post a Comment