如何从xml文件读取和显示多个值?

时间:2018-08-21 09:38:35

标签: php xml

这是我的文件:

example.xml

<?php

function ibportal_cron(){
    $xml=simplexml_load_file("example.xml") or die("Error: Cannot create object");
    foreach($xml->children() as $child)
    {
        $childArray = (array)$child;
        echo "Opportunity Type :" .$childArray['Opportunity_type'] . "<br/>";
    }
}
?>

test.php

@Query("select pb.id,pp.max_borrow_amt,pp.min_borrow_amt
from product_loan_basic pb left join product_loan_price pp on pb.code=pp.product_code 
 where pb.code IN(?1) and pb.status='publish' order by  ?2 ",
nativeQuery = true)  
List<Object[]> findByCodesIn(List<String> codes,String orderby);

谢谢。

没有错误消息,但我无法使用echo或print向浏览器显示值。

1 个答案:

答案 0 :(得分:0)

    $xml = simplexml_load_file('simple.xml');
    $values = $xml->available_technology->Opportunity_type->item;
    $numberOfItems = count($values);
    for ($i = 0; $i < $numberOfItems; $i++) {
        echo "Opportunity Type :" . $values[$i]->value . "<br/>";
    }