Answer the question
In order to leave comments, you need to log in
How to get a property from this object?
I work with Yandex Metrica.
I get this answer
<?xml version="1.0" encoding="UTF-8"?>
<doc xmlns="http://api.yandex.ru/metrika/">
<id>-------------</id>
<date1>20151023</date1>
<date2>20151029</date2>
<data count="3">
<row>
<exit>0</exit>
<page_views>1</page_views>
<id>508974949722839696</id>
<entrance>0</entrance>
<url><![CDATA[http://example.com/1]]></url>
</row>
<row>
<exit>1</exit>
<page_views>1</page_views>
<id>2290409950598088779</id>
<entrance>0</entrance>
<url><![CDATA[http://example.com/2]]></url>
</row>
<row>
<exit>0</exit>
<page_views>1</page_views>
<id>16120082494497546606</id>
<entrance>1</entrance>
<url><![CDATA[http://example.com/3]]></url>
</row>
</data>
<totals>
<exit>1</exit>
<page_views>3</page_views>
<entrance>1</entrance>
</totals>
</doc>
simplexml_load_string()
I load the whole thing into an objectobject(SimpleXMLElement)#31 (5) {
["id"]=>
string(8) "----------"
["date1"]=>
string(8) "20151023"
["date2"]=>
string(8) "20151029"
["data"]=>
object(SimpleXMLElement)#32 (2) {
["@attributes"]=>
array(1) {
["count"]=>
string(1) "3"
}
["row"]=>
array(3) {
[0]=>
object(SimpleXMLElement)#34 (5) {
["exit"]=>
string(1) "0"
["page_views"]=>
string(1) "1"
["id"]=>
string(18) "508974949722839696"
["entrance"]=>
string(1) "0"
["url"]=>
object(SimpleXMLElement)#37 (0) {
}
}
[1]=>
object(SimpleXMLElement)#35 (5) {
["exit"]=>
string(1) "1"
["page_views"]=>
string(1) "1"
["id"]=>
string(19) "2290409950598088779"
["entrance"]=>
string(1) "0"
["url"]=>
object(SimpleXMLElement)#37 (0) {
}
}
[2]=>
object(SimpleXMLElement)#36 (5) {
["exit"]=>
string(1) "0"
["page_views"]=>
string(1) "1"
["id"]=>
string(20) "16120082494497546606"
["entrance"]=>
string(1) "1"
["url"]=>
object(SimpleXMLElement)#37 (0) {
}
}
}
}
["totals"]=>
object(SimpleXMLElement)#33 (3) {
["exit"]=>
string(1) "1"
["page_views"]=>
string(1) "3"
["entrance"]=>
string(1) "1"
}
}
$xml->data->row[0]->url
object(SimpleXMLElement)#34 (1) {
[0]=>
object(SimpleXMLElement)#32 (0) {
}
}
$xml->data->row[0]->url[0]
object(SimpleXMLElement)#32 (0) {
}
Answer the question
In order to leave comments, you need to log in
you can see in the dump that the URL is empty, you call it correctly, the parser does not correctly parse the url value I
read a little, CDATA can be parsed through the DOM Documentation , google simpleXML DOM
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question