php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18197 DOMXML module have invalid handling of namespaces
Submitted: 2002-07-06 06:11 UTC Modified: 2002-08-14 10:28 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: flying at dom dot natm dot ru Assigned:
Status: Closed Package: DOM XML related
PHP Version: 4.2.1 OS: Any
Private report: No CVE-ID: None
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-14 05:16 UTC] chregu@php.net
it looks like domxml can't create nodes with namespaces right now. 

for creating nodes with namespaces, there is the DOM spec method createElementNS(namespaceURI,name), i will implement this soon.

chregu
 [2002-08-14 10:28 UTC] chregu@php.net
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



 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC