|  | Posted by skrebbel on 04/24/07 10:23 
On Tue, 24 Apr 2007 11:55:27 +0200, Sean  =
 <sean.anderson@[nospam]oakleafgroup.biz> wrote:
 
 >
 > "skrebbel" <e.pear.teeselink@student.apple.tue.banana.nl> wrote in  =
 
 > message
 > news:op.tq95l61r18tlcy@s011169.mshome.net...
 > Is there any faster/easier way of finding a child node of a certain
 > DOMNode object than doing something like
 >
 > function getChildByTagname($curnode, $name)
 > {
 > foreach($curnode->childNodes as $node)
 > {
 > if($node->nodeName=3D=3D$name)
 > {
 > return $node;
 > }
 > }
 > }
 >
 > ?
 >
 > it seems fairly slow and cumbersome. i was thinking xpath, but i can
 > hardly imagine that to be a lot faster, with all the DOMXpath object
 > creation and all, though I didn't benchmark.
 >
 > -egbert
 >
 >
 >
 >
 > I would have thought that you could probably narrow it down with an XP=
 ATH
 > query, but without seeing the XML and what you're after, it's a little=
 =
 
 > hard
 > to consider what you are looking for.
 >
 >
 >
 
 What I'm after is a method that gets a child node of a certain "current =
 =
 
 node" that has a certain name. It is for a general purpose solution I'm =
 =
 
 making.
 
 As an example, in
 
 <books>
 <book>
 <title>Bananas, and how to peel them</title>
 <author>John Doe</author>
 <review>
 <author>Perry White</author>
 <title>New banana peeling book revolutionalises world of banana  =
 
 peeling</title>
 </review>
 </book>
 </books>
 
 if i have a DOMNode object $book that refers to the above book node, i'd=
 =
 
 want the fastest way to get me a DOMNode object that refers to its title=
 =
 
 child (but of course not to the review's title, which is what  =
 
 $document->getElementsByTagName would give me).
 
 With SimpleXML, I could of course just do $doc->books->book->title, but =
 I  =
 
 don't want to use SimpleXML because it is so awfully terrible at anythin=
 g  =
 
 other than reading out some data (try deleting a node or adding features=
 ,  =
 
 for instance). So, what's the fastest/best/etc way to do it with DOM?
 
 -egbert
 =
 [Back to original message] |