G
G
grechnik2282016-03-14 00:03:39
PHP
grechnik228, 2016-03-14 00:03:39

Why does it output 0 when parsing Xml?

$rest_urls = 'myurl';
$xml_responses = file_get_contents($rest_urls);
$xml_records = simplexml_load_string($xml_responses);
$AntiBrakeSystem = $xml_records->atttoi->Anti-BrakeSystem;
echo 'AntiBrakeSystem:'.$AntiBrakeSystem.'<br/>';

<result>
<ddd>dfgdf</ddd>
<atttoi>
<Anti-BrakeSystem>4-Wheel ABS</Anti-BrakeSystem>
</attributes>
</result>

stupidly displays 0 and that's it ..
what do I do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Nikolaenko, 2016-03-14
@grechnik228

First, the XML contains errors (atttoi is not closed and attributes is not opened). The correct XML in your case should look like this:

<result>
<ddd>dfgdf</ddd>
<atttoi>
<Anti-BrakeSystem>4-Wheel ABS</Anti-BrakeSystem>
</atttoi>
</result>

Secondly, access to the Anti-BrakeSystem must be done as follows:
Smoke mana: php.net/manual/en/simplexml.examples-basic.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question