php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31409 Element is in wrong Namespace
Submitted: 2005-01-04 19:01 UTC Modified: 2005-01-04 22:22 UTC
From: joern_h at gmx dot net Assigned:
Status: Not a bug Package: XML related
PHP Version: 5.0.3 OS: Windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: joern_h at gmx dot net
New email:
PHP Version: OS:

 

 [2005-01-04 19:01 UTC] joern_h at gmx dot net
Description:
------------
When an empty element is has a xmlns attribute the element following it is also reported to be in this namespace. In the following example the 'a' element is wrongly reported as being in the 'http://t/' namespace.

Reproduce code:
---------------
<?php

$xml = <<<HERE
<?xml version="1.0" encoding="utf-8" ?>
<root>
    <test xmlns="http://t/" />
    <a />
</root>
HERE;

$parser =& xml_parser_create_ns('utf-8', ';');
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, true);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);

$index = array();
$vals  = array();
if (!xml_parse_into_struct($parser, $xml, $vals, $index)) {
    echo xml_error_string(xml_get_error_code($parser)) . "\n";
}
print_r($vals);

xml_parser_free($parser);

?>

Expected result:
----------------
Array
(
    [0] => Array
        (
            [tag] => root
            [type] => open
            [level] => 1
        )

    [1] => Array
        (
            [tag] => http://t/;test
            [type] => complete
            [level] => 2
        )

    [2] => Array
        (
            [tag] => a
            [type] => complete
            [level] => 2
        )

    [3] => Array
        (
            [tag] => root
            [type] => close
            [level] => 1
        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [tag] => root
            [type] => open
            [level] => 1
        )

    [1] => Array
        (
            [tag] => http://t/;test
            [type] => complete
            [level] => 2
        )

    [2] => Array
        (
            [tag] => http://t/;a
            [type] => complete
            [level] => 2
        )

    [3] => Array
        (
            [tag] => root
            [type] => close
            [level] => 1
        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-04 22:22 UTC] rrichards@php.net
This is a bug in libxml not PHP. issue being addressed there.
For workaround use full open and closing tags for empty elements defining namespaces:
<test xmlns="http://t/"></test>
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 01:01:34 2025 UTC