php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27524 get_elements_by_tagname
Submitted: 2004-03-08 01:03 UTC Modified: 2004-03-08 03:20 UTC
From: ken at world dot std dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 4.3.4 OS: Mac OS X 10.3.2 Build 7D24
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: ken at world dot std dot com
New email:
PHP Version: OS:

 

 [2004-03-08 01:03 UTC] ken at world dot std dot com
Description:
------------
Hi,

I'm new to using the PHP DOM interface, so I apologize
if this "bug" is my misunderstanding of the specs, but
I haven't seen any mention of this anywhere yet.  I'm
using the get_elements_by_tagname

Reproduce code:
---------------
$dom = domxml_open_file("XMLBugTest.xml");
$temp = $dom->get_elements_by_tagname("x");
$y_nodes = $temp[0]->get_elements_by_tagname("y");

// Access the first node
$current_node = $y_nodes[0];

// Initialize the node counter
$nodecount = 0;

// Process each node in the collection
while($current_node)
{
	echo "<br>" . $current_node->node_type() . " -- " . $current_node->node_name() . " -- " . $current_node->get_content();
	
	// Count this node
	$nodecount++;
		
	// Get the next node in the collection
	$current_node = $current_node->next_sibling();
}

// Report the total node count
echo "<br>Number of processed nodes:  " . $nodecount;

Expected result:
----------------
1 -- y -- Item 1 
1 -- y -- Item 2 
1 -- y -- Item 3 
1 -- y -- Item 4 
Number of processed nodes: 4

Actual result:
--------------
1 -- y -- Item 1 
3 -- #text -- 
1 -- y -- Item 2 
3 -- #text -- 
1 -- y -- Item 3 
3 -- #text -- 
1 -- y -- Item 4 
3 -- #text -- 
Number of processed nodes: 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-08 01:07 UTC] ken at world dot std dot com
Hi,

Sorry, I forgot to include the XML file which I was
using to generate the output.  Here it is:

<?xml version="1.0" encoding="iso-8859-1"?>
<x>
	<y>
		Item 1
	</y>
	<y>
		Item 2
	</y>
	<y>
		Item 3
	</y>
	<y>
		Item 4
	</y>
</x>
 [2004-03-08 03:20 UTC] chregu@php.net
next_sibling() takes the next sibling node of the <y> 
element, which is a text node... It has nothing to do 
with get_elements_by_tagname.

get_elements_by_tagname returns an array, you have to 
loop through this, if you only want all the <y> elements
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 02:01:23 2020 UTC