Hi there I have the following XML code:
<?xml version="1.0" encoding="UTF-8"?>
<connector_ret>
   <function name="search">
     <row id="1">
         <col id="1">AAA</col>
         <col id="2">243168</col>
         <col id="3">090828-000300</col>
         <col id="4">Subject</col>
     </row>
     <row id="2">
         <col id="1">BBB</col>
         <col id="2">243515</col>
         <col id="3">090831-000116</col>
         <col id="4">Subject</col>
     </row>
     <row id="3">
         <col id="1">BBB</col>
         <col id="2">244913</col>
         <col id="3">090905-000022</col>
         <col id="4">Subject</col>
     </row>
     <row id="4">
         <col id="1">CCC</col>
         <col id="2">245323</col>
         <col id="3">090907-000253</col>
         <col id="4">Subject</col>
     </row>
     <row id="5">
         <col id="1">CCC</col>
         <col id="2">245323</col>开发者_开发百科;
         <col id="3">090907-000253</col>
         <col id="4">Subject</col>
     </row>
   </function>
</connector_ret>
I was wondering if it was possible to loop through this in PHP4 and only display certain rows when given a variable.
For example if the variable given is BBB then only display rows where the first column id is also equal to BBB.
So the output would be:
BBB - 243515 - 090831-000116 - Subject BBB - 244913 - 090905-000022 - Subject
and the other rows are just ignored.
If the variable given is AAA the output would be:
AAA - 243168 - 090828-000300 - Subject
You get the idea :)
If you can help that'd be fantastic. Thanks so much.
you should use xpath to do such processing
$dom    =domxml_open_mem($xml); 
$calcX = &$dom->xpath_new_context();
$xml_parsed["match"]= node_content(
   $calcX->xpath_eval("//row/col[@id=1][text()='BBB']")
);
You might look at XSL-T as your solution to this. It's easy enough to select the nodes you want and transform the results.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论