Web services response looks suspect, simplexml_load_string()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tropis
Forum Newbie
Posts: 1
Joined: Fri May 15, 2009 8:00 pm

Web services response looks suspect, simplexml_load_string()

Post 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!
Last edited by Benjamin on Fri May 15, 2009 10:39 pm, edited 2 times in total.
Reason: Changed code type from text to xml.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Web services response looks suspect, simplexml_load_string()

Post 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.
Post Reply