XML parsing, ISO8859-1 & UTF-8

Hello,

I have to use the information in a webservice which look like this :

<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="iso-8859-1"?> <Name>Test_Name</Name>

The problem is the two different encoding formats…

I first used REXML, but the .elements[…] method returns nil

Would someone have a solution to get the XML tags and the information it
contain ?

Thank you

On Wed, Sep 18, 2013 at 5:38 PM, tt rr [email protected] wrote:

The problem is the two different encoding formats…

I first used REXML, but the .elements[…] method returns nil

Would someone have a solution to get the XML tags and the information it
contain ?

Since you’re embedding XML in XML you need to parse twice. Btw. it
doesn’t really make much sense to have a different encoding in the
nested XML because from XML’s point of view the whole document is
encoded with UTF-8 and hence also the inner text needs to use that
encoding. If you want to use a different encoding you’ll have to
encode the inner text yourself, probably as binary (e.g. BASE64).

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs