php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41257 lookupPrefix, lookupNamespaceURI do not work as expected
Submitted: 2007-05-02 07:37 UTC Modified: 2007-05-04 19:33 UTC
From: daniel dot oconnor at gmail dot com Assigned: rrichards (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.2.1 OS: Windows, Linux
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: daniel dot oconnor at gmail dot com
New email:
PHP Version: OS:

 

 [2007-05-02 07:37 UTC] daniel dot oconnor at gmail dot com
Description:
------------
DOMDocument should extend DOMNode (http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document), and should be able to find any xmlns defined in the top level element.

Currently, DOMDocument->lookupPrefix() and DOMDocument->lookupNamespaceURI() will never return any values other than null; or warn developers they are using the wrong method.

Additionally, DOMDocument->lookupPrefix & friends should be able to recognise xmlns defined in the root node of a document.

Reproduce code:
---------------
<?php
$xml = '<?xml version="1.0" encoding="UTF-8"?>
<office:document-content office:class="text" office:version="1.0" xmlns:chart="http://openoffice.org/2000/chart" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:dr3d="http://openoffice.org/2000/dr3d" xmlns:draw="http://openoffice.org/2000/drawing" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:form="http://openoffice.org/2000/form" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:meta="http://openoffice.org/2000/meta" xmlns:number="http://openoffice.org/2000/datastyle" xmlns:office="http://openoffice.org/2000/office" xmlns:ooo="http://openoffice.org/2004/office" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:script="http://openoffice.org/2000/script" xmlns:style="http://openoffice.org/2000/style" xmlns:svg="http://www.w3.org/2000/svg" xmlns:table="http://openoffice.org/2000/table" xmlns:text="http://openoffice.org/2000/text" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <office:body>
        <table:table table:name="Table13" table:style-name="Table13">
            <table:table-column table:style-name="Table13.A" />
            <table:table-row table:style-name="Table13.1">
                <table:table-cell table:style-name="Table13.A1" table:value-type="string">
                    <text:p text:style-name="P84">Important Notes and Qualifications</text:p>
                </table:table-cell>
            </table:table-row>
        </table:table>
        <text:p text:style-name="P88">&lt; &lt; func_image(photograph) &gt; &gt;</text:p>
    </office:body>
</office:document-content>';

$document = new DOMDocument('1.0', 'UTF-8');
$document->loadXML($xml);

foreach ($document->getElementsByTagNameNS('http://openoffice.org/2000/table', 'table') as $element) {
    echo 'local name: ', $element->localName, ', prefix: ', $element->prefix, ' xmlns (element):', $element->lookupNamespaceURI($element->prefix), ' xmlns (document):', $document->lookupNamespaceURI($element->prefix), "\n";
}
print "\n\n";
foreach ($document->getElementsByTagName('*') as $element) {
    echo 'local name: ', $element->localName, ', prefix: ', $element->prefix, ' xmlns (element):', $element->lookupNamespaceURI($element->prefix), ' xmlns (document):', $document->lookupNamespaceURI($element->prefix), "\n";
}
print "\n\n";
foreach ($document->getElementsByTagNameNS('*', '*') as $element) {
    echo 'local name: ', $element->localName, ', prefix: ', $element->prefix, ' xmlns (element):', $element->lookupNamespaceURI($element->prefix), ' xmlns (document):', $document->lookupNamespaceURI($element->prefix), "\n";
}

print "\n\n";
foreach ($document->getElementsByTagNameNS('http://openoffice.org/2000/table', '*') as $element) {
    echo 'local name: ', $element->localName, ', prefix: ', $element->prefix, ' xmlns (element):', $element->lookupNamespaceURI($element->prefix), ' xmlns (document):', $document->lookupNamespaceURI($element->prefix), "\n";
}

print "\n\n";
foreach ($document->getElementsByTagNameNS('http://openoffice.org/2000/table', '*') as $element) {
    echo 'local name: ', $element->localName, ', prefix: ', $element->prefix, ' xmlns (element):', $element->lookupNamespaceURI($element->prefix), ' xmlns (document):', $document->lookupNamespaceURI($element->prefix), "\n";
}

print "\n\n";
foreach ($document->getElementsByTagNameNS('http://openoffice.org/2000/table', 'table') as $element) {
    echo 'local name: ', $element->localName, ', prefix: ', $element->prefix, ' xmlns (element):', $element->lookupNamespaceURI($element->prefix), ' xmlns (document):', $document->lookupNamespaceURI($element->prefix), "\n";
}

Expected result:
----------------
$document->lookupNamespaceURI() and $element->lookupNamespaceURI() should return identical results.

Actual result:
--------------
local name: table, prefix: table xmlns (element):http://openoffice.org/2000/table xmlns (document):

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-04 19:33 UTC] rrichards@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC