RE: Query2XML: adding an attribute to the root element
| From: | Lukas Feiler | Date: | Tue, 13 Feb 2007 10:46:17 +0000 |
| Subject: | RE: Query2XML: adding an attribute to the root element | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26559@lists.php.net to get a copy of this message | ||
Hi Diana!
Your mail should have gone to pear-general@lists.php.net.
Diana Quintal wrote:
>
>
> Hi Lukas,
>
> I LOVE your Query2XML package!!! I'm hoping you can
> help me. I'm stuck on something SO simple. I am
> desperately trying to add an attribute to the root
> node and I just can't make it do it! I couldn't find
> anything in the great documentation that says whether
> I can or cannot do this. Can I do it?????
You have to work with the DOMDocument instance returned by
XML_Query2XML::getXML():
//returns an instance of DOMDocument
$doc = $query2xml->getXML($sql, $options);
//get the root DOMElement
$root = $doc->firstChild;
//set the attribute using DOMElement::setAttribute()
$root->setAttribute('date_generated', date("Y-m-d\TH:i:s"));
BTW:
http://query2xml.sourceforge.net/docs/html/XML_Query2XML/tutorial_XML_Query2
XML.pkg.html#casestudies.case05
contains such an example.
You can read more about PHP5's DOM extension and the classes
it provides here: http://www.php.net/manual/en/ref.dom.php
Cheers,
Lukas