dongyou7472 2014-06-12 06:53
浏览 51
已采纳

php xml with xsd foreach,找出哪个块

i read out a xml file with xsd, with this code:

 foreach ($xpath->evaluate('//caaml:validAspect') as $expositons) {
    echo $xpath->evaluate('string(@xlink:href)', $expositons)."<br>";
 }

here i get all results but i can not assign them in which block they are. and i also tried this:

foreach ($xpath->evaluate('//caaml:DangerRating') as $dangerRating) {
    echo $xpath->evaluate('string(caaml:validAspect/@xlink:href)', $dangerRating)."<br>";
}

here i only get the first value of the validAspect field.

and here is the xml structure:

enter image description here

and now my problem is that how can i find out in with block the data is?

Thanks!

now i tried this:

foreach ($xpath->evaluate('//caaml:DangerRating') as $i => $block) {
  echo "block $i
";
  foreach ($xpath->evaluate('/caaml:validTime/caaml:validAspect', $block) as $expositions) {
    echo $xpath->evaluate('string(@xlink:href)', $expositons)."<br>";
  }
}

but i do not get any result …

  • 写回答

1条回答 默认 最新

  • doukanzhuo4297 2014-06-12 07:03
    关注

    You could get the block first then the section

    <?php
    $xml = new DOMDocument;
    $xml->load("test.xml"); 
    $xpath = new DOMXPath($xml);
    foreach ($xpath->evaluate('//caaml:DangerRating') as $i => $block) {
        echo "block $i
    ";
        foreach ($xpath->evaluate('./caaml:validAspect', $block) as $expositions) {
            echo $xpath->evaluate('string(@xlink:href)', $expositions) . "
    ";
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染