php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26205 DomDocument->get_elements_by_tagname does not find children or attributes
Submitted: 2003-11-11 12:22 UTC Modified: 2003-11-25 03:25 UTC
From: jenny dot watt at continuetolearn dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 4.3.3 OS: 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: jenny dot watt at continuetolearn dot com
New email:
PHP Version: OS:

 

 [2003-11-11 12:22 UTC] jenny dot watt at continuetolearn dot com
Description:
------------
I am opening an XML file and retrieving data using the get DomDocument->get_elements_by_tagname() function.

This works on my Windows XP running 4.3.4 and it worked on the Unix system running 4.2.4 but when it was upgraded to 4.3.4 I can get simple tag names but not the child tags or attributes of a tag.

From what I understand from the administrator, this was only an upgrade to PHP.

Reproduce code:
---------------
//---- statements that call function
$courseDetails = domxml_open_file("quiz.xml");
$form->format = get_content($courseDetails,"questions/@TYPE");
$form->openyear = get_content($courseDetails,"timeopen/year");

//---- function called by statements above ----
function get_content($rootObject,$objectName){
  if(!$objectList = $rootObject->get_elements_by_tagname($objectName)){
     echo "error1";
     return "";
  }
  $firstChild = $objectList[0]->first_child();
  if($firstChild->node_name() == "#text"){
    $objectValue = $objectList[0]->get_content();
    return $objectValue;
  }
  return "";
}
//---- file this code is called on "quiz.xml" -----
<?xml version="1.0" encoding="iso-8859-1"?>
<quiz>
  <timeopen>
    <year>2003</year>
  </timeopen>
  <questions TYPE="blackboard">
    <file>res00001.dat</file>
  </questions>
</quiz>

Expected result:
----------------
should assign $form->format the value of "blackboard" and $form->openyear the value of "2003"

Actual result:
--------------
It will print "error1" for both and assign them the value of "".

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-11 13:13 UTC] chregu@php.net
you are using xpath-expressions and not simple element-names. This may had worked with older php versions, but the internal code was changed later. 

If you want to use something like "timeopen/year" then use the appropriate xpath methods (see manual..)

chregu
 [2003-11-11 13:14 UTC] chregu@php.net
soooorrrryyyy

auto-form-completion went crazy and changed the summary...

changing back
 [2003-11-25 01:54 UTC] megazone at cyphermint dot com
Someone should remove the comment in the online documentation that shows XPath being used if it is not valid:
http://us2.php.net/manual/en/function.domelement-get-elements-by-tagname.php
 [2003-11-25 03:25 UTC] chregu@php.net
It is deleted now
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 20:01:30 2025 UTC