1
if($xml = simplexml_load_file($validationURL . "&output=soap12"))
{
   echo "Success";  
}
else
{
    echo "Failed";
}

So This always fails. $validationURL is "http://validator.w3.org/check?uri=http://uvm.edu/~mfurland/cs148/assign1/projects.php"

http://validator.w3.org/check?uri=http://uvm.edu/~mfurland/cs148/assign1/nav.php&output=soap12 works in a browser, but it isn't working in my code. If I use file(), I get an array, but it's all strings with a bunch of characters I can't see. Like it has a twenty or thity character string that looked like " 0 ". What am I doing wrong here? Nobody else seems to have this issue.

Contents of the file when you look at in a browser:

    <m:uri>http://www.uvm.edu/~mfurland/cs148/assign1/projects.php</m:uri>
    <m:checkedby>http://validator.w3.org/</m:checkedby>
    <m:doctype>HTML5</m:doctype>
    <m:charset>utf-8</m:charset>
    <m:validity>true</m:validity>
    <m:errors>
        <m:errorcount>0</m:errorcount>
        <m:errorlist></m:errorlist>
    </m:errors>
    <m:warnings>
        <m:warningcount>1</m:warningcount>
        <m:warninglist></m:warninglist>
    </m:warnings>
</m:markupvalidationresponse>
</env:Body>
</env:Envelope>
Anas
  • 5,622
  • 5
  • 39
  • 71
mtfurlan
  • 1,024
  • 2
  • 14
  • 25

1 Answers1

0

I often have to communicate with web services that use namespaces. There's two options available to you; register the namespace with SimpleXML, or remove the : character from the tags.

Removing the : might be easier, but might not be the neatest option, depending on what you want to do with the data.

To remove the colon character:

$xml_content = file_get_contents($validationURL . '&output=soap12');
$xml_content = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $xml_content);
$xml = simplexml_load_string($xml_content);

Alternatively, to work with the namespaces, see this article Parse XML with Namespace using SimpleXML

Community
  • 1
  • 1
carlgarner
  • 89
  • 5
  • Okay, thank you greatly. I was thinking it was failing to get the data, and had no idea why. I'm going to use your method, as it currently makes more sense to me. I'll try to understand using the Namespace stuff later. Many Thanks – mtfurlan Sep 10 '12 at 23:11