doufen5175 2013-07-16 15:44
浏览 51
已采纳

根据属性选择一个节点,然后在php中返回兄弟节点属性

I am trying to get the content of the field[@value] attribute when the sibling node has field[@value='SIM Identification (ICCID)'. I need to do this with multiple xml docs and the parent node is not always located in the same array position so i need to use relative paths.

here is an example of the xml doc.

     <views>
       <view name="Summary">
         <item>
           <field name="Subject" value="Date Created" class=""/>
           <field name="Data" value="6/24/2013 11:06:54 AM" class=""/>
         </item>
       <view name="Case Data">
         <item>
           <field name="Subject" value="Case Reference" class=""/>
         </item>
       <view name="General Information">
         <item>
           <field name="Attribute" value="Device Name" class=""/>
           <field name="Data" value="SIM Card" class=""/>
         </item>
         <item>
           <field name="Attribute" value="SIM Identification (ICCID)" class=""/>
           <field name="Data" value="8935301120426207248" class=""/>
         </item>
       </view>
     </views>

Here is what I have come up with so far but can't quite get it to work.

    $doc = new DOMDocument;
    $doc->load('../SIMxml/207248.xml');
    $xpath = new DOMXPath($doc);

    $SIM_num_query = "/views/view[@name='General Information']/item [field[@name='Attribute' and @value='SIM Identification (ICCID)' and preceding-sibling::field[@value]]]/";

    echo $xpath->query($SIM_num_query),"<br/>";

This does not work, any suggestions?

  • 写回答

1条回答 默认 最新

  • dtzh131555 2013-07-16 16:05
    关注

    If it is always the following field you are looking for try this:

    "//field[@value='SIM Identification (ICCID)']/following-sibling::field/@value"
    

    If it the position is not fix you may try something like this:

    "//field[@value='SIM Identification (ICCID)']/../field[@name='Data']/@value"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Android Studio中如何把H5逻辑放在Assets 文件夹中以实现将h5代码打包为apk
  • ¥15 使用小程序wx.createWebAudioContext()开发节拍器
  • ¥15 关于#爬虫#的问题:请问HMDB代谢物爬虫的那个工具可以提供一下吗
  • ¥15 vue3+electron打包获取本地视频属性,文件夹里面有ffprobe.exe 文件还会报错这是什么原因呢?
  • ¥20 用51单片机控制急停。
  • ¥15 孟德尔随机化结果不一致
  • ¥15 在使用pyecharts时出现问题
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0