PHP5: ext/dom - set namespace of node manually
| From: | Vivian Steller | Date: | Mon, 16 Feb 2004 00:04:45 +0000 |
| Subject: | PHP5: ext/dom - set namespace of node manually | ||
| Groups: | php.general php.xml.dev | ||
| Request: | Send a blank email to php-general+get-177756@lists.php.net to get a copy of this message | ||
Hello,
the following code shows my problem:
<?php
class MyElement extends DomElement {
function __construct($name) {
parent::__construct($name);
}
}
$doc = new DomDocument();
$node = new MyElement("test");
$node = $doc->appendChild($node);
$node->setAttribute("xmlns", "http://www.somedomain.de/");
print("Namespace: '" . $node->namespaceURI . "'");
$xmlCode = $doc->saveXML();
print("<pre>" . htmlspecialchars($xmlCode) . "</pre>");
?>
the output would be:
> Namespace: ''
> <?xml version="1.0"?>
> <test xmlns="http://www.somedomain.de/"/>
As you can see it is impossible to set the namespace manually! I tried to
set it with the help of a DomNamespaceNode-object but those objects are no
"real" nodes (why!?!) and the consequence is that you couldn't append such
a node with $node->appendChild($domnamspacenode_object); ...
Further it isn't possible to use the function $doc->createElementNS(...)
because this function returns a domelement-object but i want the element to
be my own MyElement-object.
So how to get a namespace in my node???
thanks in advance,
vivi