Bug #54905 [Fbk->NoF]: inconsistant namespace behaviour with DocumentFragment

From: Date: Tue, 30 Dec 2014 10:41:43 +0000
Subject: Bug #54905 [Fbk->NoF]: inconsistant namespace behaviour with DocumentFragment
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-189406@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=54905&edit=1

 ID:               54905
 Updated by:       php-bugs@lists.php.net
 Reported by:      andrew at miniatureworldmaker dot com dot au
 Summary:          inconsistant namespace behaviour with DocumentFragment
-Status:           Feedback
+Status:           No Feedback
 Type:             Bug
 Package:          DOM XML related
 Operating System: Fedora / Debian
 PHP Version:      5.3.6
 Private report:   N

 New Comment:

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.


Previous Comments:
------------------------------------------------------------------------
[2013-12-02 17:35:34] mike@php.net

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

This test case is quite convoluted, I think I get the opposite result, but I can't really tell.

Please re-open this bug with a proper reproduce script.

------------------------------------------------------------------------
[2011-05-23 10:05:53] andrew at miniatureworldmaker dot com dot au

Description:
------------
In an XML document, when an xmlns attribute is present, all child elements of that 
element are also considered to be in that namespace. 

When a DocumentFragment is created and the root element contains an xmlns 
attribute this is the behaviour currently displayed by PHP. 

However if a documentfragment is appended to an element already present in the DOM 
which contains an xmlns, the appended fragment appears to be assigned a default 
'null' namespace.

Test script:
---------------
Scenario 1:  xmlns is present in the fragment.


<?php

const BLAH_NS = 'http://blah.com/blah';

  $xml = '
<root>
    <foo>
        <bar />
    </foo>
</root>
';

$fragXML = '<content
xmlns="'.BLAH_NS.'"><sneh>some</sneh><grah>here</grah><ul><li>one</li><li>two</li><li>three</li></ul></content>';


$doc = new DOMDocument('1.0','UTF-8');
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;

$doc->loadXML( $xml );

$xpath = new DOMXPath( $doc );
$barElement = $xpath->query( '//bar' )->item(0);

// create a new element with  xmlns="http://blah.com/blah" . The expectation is that
// every child of this node will be part of this namespace as per the section on default 
// name spaces http://www.w3schools.com/XML/xml_namespaces.asp

// create a new document Fragment
$DOMFragment = $doc->createDocumentFragment();
$DOMFragment->appendXML( $fragXML );


// Attach the fragment to the rest of the document
$barElement->appendChild( $DOMFragment );

// all good so far
echo $doc->saveXML();

// register the bar name space so we can perform a lookup
$xpath->registerNamespace('b', BLAH_NS);

echo "\n\n\n";
// this doesn't work 
$grahElement = $xpath->query( '//b:grah' )->item(0);
echo "Find //b:grah " .$grahElement->nodeValue."\n";


// this works 
$grahElement = $xpath->query( '//grah' )->item(0);
echo "Find //grah  ".$grahElement->nodeValue."\n";

?>

Scenario 2: The xmlns attribute is present on the element the fragment is attached to


<?php

const BLAH_NS = 'http://blah.com/blah';

  $xml = '
<root>
    <foo>
        <bar />
    </foo>
</root>
';

$fragXML =
'<sneh>some</sneh><grah>here</grah><ul><li>one</li><li>two</li><li>three</li></ul>';


$doc = new DOMDocument('1.0','UTF-8');
$doc->formatOutput = true;
$doc->preserveWhiteSpace = false;

$doc->loadXML( $xml );

$xpath = new DOMXPath( $doc );
$barElement = $xpath->query( '//bar' )->item(0);

// create a new element with  xmlns="http://blah.com/blah" . The expectation is that
// every child of this node will be part of this namespace as per the section on default 
// name spaces http://www.w3schools.com/XML/xml_namespaces.asp

$contentElement = $doc->createElementNS( BLAH_NS, 'content' );
$barElement->appendChild( $contentElement );

// create a new document Fragment
$DOMFragment = $doc->createDocumentFragment();
$DOMFragment->appendXML( $fragXML );


// Attach the fragment to the rest of the document
$contentElement->appendChild( $DOMFragment );

// all good so far
echo $doc->saveXML();

// register the bar name space so we can perform a lookup
$xpath->registerNamespace('b', BLAH_NS);

echo "\n\n\n";
// this doesn't work 
$grahElement = $xpath->query( '//b:grah' )->item(0);
echo "Find //b:grah " .$grahElement->nodeValue."\n";


// this works 
$grahElement = $xpath->query( '//grah' )->item(0);
echo "Find //grah  ".$grahElement->nodeValue."\n";

?>

Expected result:
----------------
In both cases I would expect the output of:

Find //b:grah here
Find //grah  

Actual result:
--------------
Find //b:grah 
Find //grah  grahtest


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=54905&edit=1


Thread (3 messages)

« previous php.bugs (#189406) next »