Hello,
checking out the behavior of Namespaces & Prefixes of the new dom
implementation of PHP5 I got some (for me!) unexpected results.

look at the following source code: (plz copy&paste it to your editor ;)

<pre>
<?php
        // PHP5: ext/dom: Namespace Tests
        
        function printRootNS($xmlCode) {
                $doc = new DomDocument();
                
                $doc->loadXML($xmlCode);
                $root = $doc->documentElement;
                print(trim(htmlspecialchars($doc->saveXML())) . "\n\t => Namespace of
root-Element: <b>" . $root->namespaceURI . "</b>\n\n"); 
        }
        
        function printRootNSNewPrefix($xmlCode, $newPrefix) {
                $doc = new DomDocument();
                
                $doc->loadXML($xmlCode);
                $root = $doc->documentElement;
                $root->prefix = $newPrefix;
                print(trim(htmlspecialchars($doc->saveXML())) . "\n\t => Namespace of
root-Element: <b>" . $root->namespaceURI . "</b>\n\n"); 
        }

        printRootNS('<prefix:root xmlns:prefix="somedomain.name"
xmlns:anotherprefix="anotherdomain.name"/>');
        
        print("\nI'm going to change prefix with \"\$root->prefix =
'anotherprefix';\" now... \n\n\n");
        printRootNSNewPrefix('<prefix:root xmlns:prefix="somedomain.name"
xmlns:anotherprefix="anotherdomain.name"/>', "anotherprefix");
?>
</pre>


This is the corresponding output:

<?xml version="1.0"?>
<prefix:root xmlns:prefix="somedomain.name"
xmlns:anotherprefix="anotherdomain.name"/>
         => Namespace of root-Element: somedomain.name


I'm going to change prefix with "$root->prefix = 'anotherprefix';" now... 


<?xml version="1.0"?>
<xml:root xmlns:prefix="somedomain.name"
xmlns:anotherprefix="anotherdomain.name"/>
         => Namespace of root-Element: http://www.w3.org/XML/1998/namespace



I thought that setting $root->prefix will set the prefix and the
namespaceUri to the other domain... but it seems to me that the parser
doesn't see the "xmlns:anotherprefix" as a prefix-declaration?
maybe i just misunderstood something, so please correct me if so.

I know, namespaces are quite difficult to implement - it isn't my goal to
annoye you with it!

Best regards,
vivian

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to