|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-07-06 06:11 UTC] flying at dom dot natm dot ru
DOM XML module handle XML namespaces in a wrong way. Take a look at a simple example:
<?php
$xml = xmldoc('<?xml version="1.0"?><root xmlns:m="http://www.m.com/"/>');
$root = $xml->root();
$child = $root->add_child($xml->create_element('m:child'));
echo 'Namespace prefix: '.$child->prefix().'<br>';
echo 'Node name: '.$child->tagname().'<br>';
?>
It is obvious, that result should be:
Namespace prefix: m
Node name: child
But instead we have:
Namespace prefix:
Node name: m:child
Moreover, it is even possible to create nodes with undeclared namespaces, like:
$child = $root->add_child($xml->create_element('q:child'));
and it will not return any errors. But XML document itself will be invalid after it, because of undeclared namespace.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
Fixed in CVS Log Message: - Added some namespace support with DomNode->add_namespace(uri, prefix) and DomDocument->create_element_ns(uri, nodename) Therefore you have to use create_element_ns, if you want to add elements with namespace (W3C spec) and maybe declare the namespace before with add_namespace() on some parent node (no w3c spec :). your example should work with the following: $child = $root->add_child($xml->create_element_ns('http://www.m.com/','child')); chregu