Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

simplexml_load_file, asXML returns empty string

945 views
Skip to first unread message

Flint ZA

unread,
Feb 25, 2009, 3:55:55 PM2/25/09
to
Hi,
I'm trying to read an XML response on a remote server and echo that
back. My current code looks something like this:

<?php
$query = "url_to_xml_file";

// Perform the XML call
$xml = simplexml_load_file($query);

foreach ($xml->match as $match) {
foreach ($match->attributes() as $a => $b) {
echo $a,'="',$b,"\"\n";
}
}

echo "<br><hr><br>";

echo $xml->asXML();

?>

Now the foreach loop successfully echoes all the "match" elements in
the XML response and their attributes, but the echo $xml->asXML();
echoes nothing at all. Am I misunderstanding the intended use of asXML
()? Is there another way to do this?

Thanks in advance.

Curtis Dyer

unread,
Feb 25, 2009, 5:58:59 PM2/25/09
to

Does $xml->asXML() return false? Make sure to check return values.

<http://php.net/manual/en/function.simplexml-element-asXML.php>

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);

Flint ZA

unread,
Feb 26, 2009, 1:08:21 AM2/26/09
to
On Feb 26, 12:58 am, Curtis Dyer <dye...@sig.invalid> wrote:

I haven't checked the output, I'll do that and report back. What could
possible reasons for failure be if the $xml object contains valid data?

Flint ZA

unread,
Mar 17, 2009, 4:22:21 PM3/17/09
to

Sorry for the delay, I just had a chance to work on this again now.
simplexml_load_file is indeed returning false.
I have checked and the url being passed to simplexml_load_file returns
"<results type="search"/>", which should be acceptble as far as I can
tell? Any suggestions on what I'm doing wrong?

Flint ZA

unread,
Mar 17, 2009, 4:33:28 PM3/17/09
to
Just an additional note. I've replaced the basic call with the
following:

$xml = simplexml_load_file($query);
if (false != $xml) echo $xml;
else {
$errstring = "";
$errors = libxml_get_errors();
foreach ($errors as $error) {
$errstring = $errstring . '\n' . $error;
}

libxml_clear_errors();
exit('Failed to open '.$query.' ( '.$errstring.')');
}

And the resulting string it empty.

0 new messages