T
T
trall2014-05-04 11:59:12
PHP
trall, 2014-05-04 11:59:12

Why doesn't simplexml return what I need?

There is this XML:

<?xml version="1.0" encoding="utf-8"?>
<rainbowdash>
<response>1</response>
</rainbowdash>

And there's also this one:
<?xml version="1.0" encoding="utf-8"?>
<response>1</response>

All this should be handled by PHP code:
$test = simplexml_load_file("input.txt");
echo $test->response;

If in the first case it returns 1 (as it should), then in the second it returns nothing. What can you think of?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2014-05-04
@sashablashenkov

There is such a good function var_dump. Often leads to useful thoughts.
In the case of this xml, casting to a string is appropriate:

$xml = '<?xml version="1.0" encoding="utf-8"?>
<response>5</response>';
$test = simplexml_load_string($xml);
echo (string) $test;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question