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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀