SimpleXML change to encoding="utf-16"

2,178 views
Skip to first unread message

Jimboidaho

unread,
Jun 24, 2011, 5:58:43 PM6/24/11
to Professional PHP Developers
I am working with a sope web service and there only option is sending
XML back encoding="utf-16". I can't find a way to change the encoding
for simpleXML. Am I missing something or am I going to have to do
this the harder way?

Thanks.

Robert Gonzalez

unread,
Jun 24, 2011, 6:03:32 PM6/24/11
to professi...@googlegroups.com
Its a dirty hack, but you could always call the asXML method then take the full xml string and replace the first '>' with ' encoding="utf-16">'.

Like I said, dirty.

--
This group is managed and maintained by the development staff at 360 PSG. An enterprise application development company utilizing open-source technologies for todays small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the Google Groups "Professional PHP Developers" group.
To post to this group, send email to Professi...@googlegroups.com
To unsubscribe from this group, send email to Professional-P...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Professional-PHP



--
Robert Gonzalez

James Blackburn

unread,
Jun 24, 2011, 6:31:02 PM6/24/11
to professi...@googlegroups.com
Hi Robert.

I just looked up asXML and it looks like this is called after SimpleXMLElement() and is failing. 
        $retval = $cc->CheckAvailability($uid);
         if I don't do the str_replace() then the next line errors. 
        $cxml = str_replace('UTF-16', 'UTF-8',$retval->CheckAvailabilityResult);
        $xml = new SimpleXMLElement($cxml);

Robert Gonzalez

unread,
Jun 24, 2011, 7:38:46 PM6/24/11
to professi...@googlegroups.com
Are you trying to change the encoding before you read it or as your create it?

Ovidiu Alexa

unread,
Jun 25, 2011, 8:20:32 AM6/25/11
to professi...@googlegroups.com

Jimboidaho

unread,
Jun 25, 2011, 11:54:35 AM6/25/11
to Professional PHP Developers
I am getting the XML from a SOAP web service and it is encoded as
UTF-16. I asked the service provider if there was a way to change the
encoding and they said no. So that means I have to change the
encoding before I load it or us some other way of handling the XML.
SimpleXMLElement() errors with encoding is UTF-16 not UTF-8
otherwise.

On Jun 24, 5:38 pm, Robert Gonzalez
<robert.anthony.gonza...@gmail.com> wrote:
> Are you trying to change the encoding before you read it or as your create
> it?
>
> On Fri, Jun 24, 2011 at 3:31 PM, James Blackburn <jimboid...@gmail.com>wrote:
>
>
>
> > Hi Robert.
>
> > I just looked up asXML and it looks like this is called after
> > SimpleXMLElement() and is failing.
> >         $retval = $cc->CheckAvailability($uid);
> >          if I don't do the str_replace() then the next line errors.
> >         $cxml = str_replace('UTF-16',
> > 'UTF-8',$retval->CheckAvailabilityResult);
> >         $xml = new SimpleXMLElement($cxml);
>
> > On Fri, Jun 24, 2011 at 4:03 PM, Robert Gonzalez <
> > robert.anthony.gonza...@gmail.com> wrote:
>
> >> Its a dirty hack, but you could always call the asXML method then take the
> >> full xml string and replace the first '>' with ' encoding="utf-16">'.
>
> >> Like I said, dirty.
>

Jimboidaho

unread,
Jun 25, 2011, 11:56:34 AM6/25/11
to Professional PHP Developers
That thread deals with creating XML not consuming XML.

On Jun 25, 6:20 am, Ovidiu Alexa <ovidiu.al...@gmail.com> wrote:
> http://stackoverflow.com/questions/869650/getting-simplexmlelement-to...
>
> There's your problem.
>
> I'm not always right,
> but I'm never wrong.
> Please visit my site <http://bit.ly/fT24vu>

Jimboidaho

unread,
Jun 28, 2011, 4:42:59 PM6/28/11
to Professional PHP Developers

I thought I would report back on the resolution of this issue. I have
been working the Godaddy reseller API at www.wildwestdomains.com/. As
it turns out, I was not reading the error message correctly and the
problem was Godaddy was sending my utf-8 data with a utf-16 encoding
setting. After a lot of back and forth conversations with support,
the finally agreed that this was their bug but no idea when it will be
fixed. In the meantime I will continue to hack the xml to make it
work.

Thanks.
Reply all
Reply to author
Forward
0 new messages