Re: How to Insert <?xml-stylesheet .....?> into DOMDocument

From: Date: Sat, 06 Dec 2008 10:40:19 +0000
Subject: Re: How to Insert <?xml-stylesheet .....?> into DOMDocument
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-284235@lists.php.net to get a copy of this message
Shanon Swafford wrote:
I have the following code: #!/usr/bin/php -q <?PHP error_reporting(E_ALL); ini_set('display_errors', '1');
    $doc = new DOMDocument();
    $doc->formatOutput = true;
    $foo = $doc->createElement("foo");
    $doc->appendChild($foo);
    $bar = $doc->createElement("bar");
    $foo->appendChild($bar);
    $bazz = $doc->createElement("bazz");
    $foo->appendChild($bazz);
    echo $doc->saveXML();
?> Which generates: <?xml version="1.0"?> <foo> <bar/> <bazz/> </foo> Is there a way to make it create the following XML? <?xml version="1.0"?> <?xml-stylesheet href="xsl_table.xsl" type="text/xsl"?> <foo> <bar/> <bazz/> </foo> I can't seem to find any dom functions to do this. Thanks in advance, Shanon
DOMProcessingInstruction as such: <?php error_reporting(E_ALL | E_STRICT); $doc = new DOMDocument(); $doc->formatOutput = true; // processing instruction data $styleheetParams = 'href="xsl_table.xsl" type="text/xsl"'; // create processing instruction $xmlstylesheet = new DOMProcessingInstruction( 'xml-stylesheet', $styleheetParams); //append it to the doc $doc->appendChild($xmlstylesheet); $foo = $doc->createElement("foo"); $doc->appendChild($foo); $bar = $doc->createElement("bar"); $foo->appendChild($bar); $bazz = $doc->createElement("bazz"); $foo->appendChild($bazz); echo $doc->saveXML(); ?> regards;

« previous php.general (#284235) next »