我有一个以cron身份运行的脚本,它将值从xml文档导入mysql,如:
$dbl1= $xml->xml1;
$dbl2= $xml->xml2;
$dbl3= $xml->xml3;
$dbl4= $xml->xml4;
来自xml,如:
<xml1>content</xml1>
<xml2>content</xml2>
<xml3>content</xml3>
<xml4>content</xml4>
这一切都很有效,但我在xml文件中有如下字段,我想知道如何正确导入成本限定符,例如:
<cost qualifier="Full Value" currency="GBP" display="yes">3000</cost>
我可以获得3000成本值而不是限定符吗?
任何帮助表示赞赏!
答案 0 :(得分:0)
知道了!只需要以下内容:
$dbl4= $xml->cost[qualifier];
答案 1 :(得分:0)
You may make use of the SimpleXMLElement::attributes function.
To get reference, you may refer to the following code as an example :
$xml = simplexml_load_string($string);
foreach($xml->cost[0]->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
It will get you print you the value of qualifier, currency and display attributes of cost