<?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.
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);
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?
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?
$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.