Ben bu yapıya sahip bir xml dosyasını ayrıştırmak çalışıyorum:
<?xml version="1.0" encoding="UTF-8" ?>
- <uclassify xmlns="http://api.uclassify.com/1/ResponseSchema" version="1.00">
<status success="true" statusCode="2000" />
- <readCalls>
- <classify id="cls1">
- <classification>
<class className="Arts" p="0.920034" />
<class className="Business" p="2.81823e-005" />
<class className="Computers" p="0.0040341" />
<class className="Games" p="0.00846496" />
<class className="Health" p="0.00203198" />
<class className="Home" p="0.00136572" />
<class className="Recreation" p="0.000526926" />
<class className="Science" p="0.000160703" />
<class className="Society" p="0.0611354" />
<class className="Sports" p="0.00221835" />
</classification>
</classify>
</readCalls>
</uclassify>
I am trying to access the properties className and p in class. This is the code that I have so far:
$resXml = simplexml_load_file($requestUrl); //$requestUrl is where the xml file is located
$children = $resXml->children('http://api.uclassify.com/1/ResponseSchema');
foreach ($children->readCalls->classify->classification->class as $d) {
$currClassificationName = $d['className'];
$currClassificationRating = (float) $d['p'];
echo "$currClassificationName: $currClassificationRating" . "</br>";
}
Bu çıkış:
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
Ben almaya çalışıyorum çıktı:
Arts: 0.920034
Business: 2.81823e-005
...
Society: 0.0611354
Sports: 0.00221835
Bir süre için farklı şeyler çalışıyor ve bu anlamaya olamaz. Lütfen Yardım.