php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41550 getElementById doesn't work after a schemaValidate
Submitted: 2007-05-31 15:17 UTC Modified: 2007-06-01 14:04 UTC
From: info at adaniels dot nl Assigned: rrichards (profile)
Status: Not a bug Package: DOM XML related
PHP Version: 5CVS-2007-05-31 (CVS) OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: info at adaniels dot nl
New email:
PHP Version: OS:

 

 [2007-05-31 15:17 UTC] info at adaniels dot nl
Description:
------------
Note that this is about the DOM extension, not DOM XML.

After using schemaValidate on a DOMDocument, the ID attributes should be marked, so getElementById() should work. This used to work in PHP 5.1.x, but is broken in current versions.

Reproduce code:
---------------
<?php
    $xml = <<<XML
<root>
  <item id="abc" />
  <item id="def" />
  <item id="xyz" />
</root>
XML;

    $schema = <<<XML
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" >
	<xs:element name="root">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="item" type="item" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	
	<xs:complexType name="item">
		<xs:attribute name="id" use="required" type="xs:ID"/>
	</xs:complexType>
</xs:schema>
XML;

	$dom = new DOMDocument();
	$dom->loadXML($xml);
	if (!$dom->schemaValidateSource($schema)) trigger_error("Validation failed", E_USER_ERROR);

    $node = $dom->getElementById('def');
    echo $node ? 'Node found' : 'Where is it?';
?>

Expected result:
----------------
Node found

Actual result:
--------------
Where is it?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-01 14:04 UTC] rrichards@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This appears to be a libxml2 regression bug introduced somewhere around the .20 release. Will be addressed there.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 18:01:34 2024 UTC