note 100330 added to domdocument.getelementsbytagname

From: Date: Fri, 08 Oct 2010 12:28:12 +0000
Subject: note 100330 added to domdocument.getelementsbytagname
Groups: php.notes 
Request: Send a blank email to php-notes+get-173080@lists.php.net to get a copy of this message
My first try to get a stable solution with this function, failed with this Exception: "Fatal error: Call to undefined method DOMNodeList::getElementsByTagName()" This is the xml snipplet: <?xml version="1.0" encoding="UTF-8"?> <root> <component> <properties> ....<any element> </properties> </component> </root> So the php code to climb along the elements is: <?php $src = new DOMDocument('1.0', 'utf-8'); $src->formatOutput = true; $src->preserveWhiteSpace = false; //Loading extern file $src->load('../xml/Item_component.xml'); //Check each child of first indexed branch node of: <component> //First get element after root element: <component> //1st level $component = $src->getElementsByTagName('component')->item(0); //2nd level, get next element after component, here it fails!! $properties = $component->getElementsByTagName('properties')->item(0); ... ?> I realised, that there is a different when using different libxml2 versions on Apache2. This code will fail with libxml2 version 2.6.23 and PHP version 5.2.6 -- ->It works fine with libxml2 version 2.6.32 and PHP version 5.2.6-3ubuntu4.6 ->...and finally it also works with libxml2 2.7.7 and PHP >= 5.3 So if you bored to search for solutions with DOM like I did, please ensure that your www environment has the correct libxml2 / PHP Version installed on your apache2 server. ---- Server IP: 69.147.83.197 Probable Submitter: 139.17.189.50 ---- Manual Page -- http://www.php.net/manual/en/domdocument.getelementsbytagname.php Edit -- https://master.php.net/note/edit/100330 Del: integrated -- https://master.php.net/note/delete/100330/integrated Del: useless -- https://master.php.net/note/delete/100330/useless Del: bad code -- https://master.php.net/note/delete/100330/bad+code Del: spam -- https://master.php.net/note/delete/100330/spam Del: non-english -- https://master.php.net/note/delete/100330/non-english Del: in docs -- https://master.php.net/note/delete/100330/in+docs Del: other reasons-- https://master.php.net/note/delete/100330 Reject -- https://master.php.net/note/reject/100330 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173080) next »