PHP4 - dom xml building xml from a xpath statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcmcom
Forum Newbie
Posts: 14
Joined: Thu Jan 31, 2008 7:23 am

PHP4 - dom xml building xml from a xpath statement

Post by mcmcom »

Hi all,
im using xpath to search for matches to a string and return results, however im having a bit of an issue doing it.

quick overview
the data to search has many tags - all children of a tag named block. Example :
<block>
<var1>..</var1>
...
<var55></var55>
</block>

So the search is performed on any node that is a child of block. if there is a match i want to build everything (including those <block> tags) in a in memory dom xml object and return that to the calling program

i have an example that looks like this

Code: Select all

 
function xpath_query($exp,$sourceDom){
        //$_SESSION["query_array"]
        $xpath = xpath_new_context($sourceDom);
        $query_xo = xpath_eval_expression($xpath, $exp);
        $query_ns = $query_xo->nodeset;
        $doc = domxml_new_doc("1.0");
        $rim_data = $doc->create_element("my_data");
        $doc->append_child( $my_data );
        foreach($query_xo->nodeset as $content){
            $block = $doc->create_element("block");
            $my_data->append_child( $block );
            $sn = $doc->create_element( "sn" );
            $title_array = $content->get_elements_by_tagname('sn');
            $sn->append_child($doc->create_text_node($title_array[0]->get_content()));
            $block->append_child($sn);
        }
        return  ($doc->dump_mem());
    }   
 
so this basically returns only ONE element of the results ($sn = $doc->create_element( "sn" )) ideally i want to get everything inbetween the block tags without having to manually code each tag (as they may change)
any one got any ideas?
TIA,
mcm
Post Reply