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"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?