Re: XML_Tree extra features...

From: Date: Sat, 09 Aug 2003 15:07:34 +0000
Subject: Re: XML_Tree extra features...
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-19437@lists.php.net to get a copy of this message
Assigned -> cox ;) On Thursday, August 7, 2003 7:07, Alan Knowles wrote: > attached should be a patch to add a number of features to XML_Tree. > A) replacement nodes / callback processing. > This allows you to assign a callback to any XML tag, and call a function > to return a replacement node. > <transactions> > <transaction> > <member>A-123</member> > <value>12.34</value> > <date>27/07/03</date> > </transaction> > ... > </transactions> > $tree = &new XML_Tree('somefile.xml','1.0', > array( 'mapping' => array( > // call MyClass::parseTransaction on the transaction tag > 'transaction' => > array('MyClass', 'parseTransaction'), > 'transactions' => > array('MyClass', 'parseTransactions') > ))); $root = &$tree->>getTreeFromFile (); > echo "<PRE>";print_r($root); > the two methods.. > function parseTransaction(&$node) { > $ret = new StdClass; > foreach($node->children as $n) { > $ret->{$n->name} = $n->content; > } > return $ret; > } > function parseTransactions(&$node) { > return $node->children; > } > Array > ( > [0] => stdClass Object > ( > [date] => 27/07/03 > [member ] => A-123 > [value] => 12.34 > ) > ..... > Obviously you can return null, from the method, and process as you go > along... > B) buildNodes/search/ > This assigns parent and id's to all nodes, index/aliases them in a > nodes[] array, and enable you to do.. > $tree = &new XML_Tree('somefile.xml','1.0', > array( 'buildNodes' => true) > ); $node = &$tree->>search(0, array('member',array('id'=>123))); > look for > <member id="123"> node $node = &$tree->>search(0, array('member',array(),'A-123')); > look for > <member>A-123</member> $node = &$tree->>searchPath(0, > array('transaction','transaction', > array('member',array(),'A-123') > ) > ); > looks for > <transactions> > <transaction> > <member>A-123</member> $parent = &$tree->>parent($node); > retreives the parent node.. > Let me know your thoughts.. > Regards > Alan -- Tomas V.V.Cox mailto:cox@idecnet.com

« previous php.pear.dev (#19437) next »