Page 1 of 1

Web services response looks suspect, simplexml_load_string()

Posted: Fri May 15, 2009 8:34 pm
by tropis
I am having a difference of opinion with a client about the XML he is sending me from his web service.

What I expect to get is something like this:

Code: Select all

<?xml version="1.0" encoding="UTF-16"?>
  <Foo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <User ID="200" TOKEN="2343DD9C" />
</Foo>
But what I get is like this. ( Actually it was full of & lt; and & gt; entities but I ran it through html_entity_decode() after the curl fetch.)

Code: Select all

<?xml version="1.0" encoding="utf-8" ?> 
  <string xmlns="http://foo.example.com/Authentication/">
    <?xml version="1.0" encoding="UTF-16"?>
      <Foo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <User ID="200" TOKEN="2343DD9C" />
      </Foo>
  </string>
Parsing this with simplexml_load_string(), I get a warning: "XML declaration allowed only at the start of the document".

Questions:
1. It looks like their server is wrapping the xml doc with another xml wrapper, right? String tag? If so, would that likely to be caused by a server misconfiguration, or a programmer? I think that would explain the encoded brackets too.

2. When testing, I used Firefox to submit a request, then 'view source' to check the response. Is that valid? Will I see the actual response without artifacts, encoding, etc?

thx!

Re: Web services response looks suspect, simplexml_load_string()

Posted: Fri May 15, 2009 10:01 pm
by requinix
Go ahead and submit the request with Firefox. If it's supposed to be POSTed then make yourself a quick HTML page with a <form>.

If you get the same stuff back (that's what I would guess) then whatever is happening is probably their fault.