We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › proXML & UTF-16
Page Index Toggle Pages: 1
proXML & UTF-16? (Read 401 times)
proXML & UTF-16?
Jan 6th, 2009, 4:05am
 
Hi, I'm not able to load in an XML file that is encoded in UTF-16 using the proXML library. When I run this code:

Code:
 xmlIO = new XMLInOut(this);
xmlIO.loadElement(dataPath("utf16.xml"));


I get the following error:

Code:
java.lang.NullPointerException
at proxml.XMLInOut$Loader.parseDocument(XMLInOut.java:118)
at proxml.XMLInOut$Loader.run(XMLInOut.java:452)
(etc...)


Any ideas?

Thanks, Angus
Re: proXML & UTF-16?
Reply #1 - Jan 6th, 2009, 9:30am
 
In case anyone is interested, this workaround was successful and much faster than I expected it would be. After the xml file has been converted it can be opened with the processing XML libraries. I think the nanoXML and proXML libraries should be able to read UTF-16 encoded xml files though. So if there's a simpler way to do this let me know!

-Angus

Code:
//make sure to import java.io.*;


File readFrom = new File(dataPath("myUTF16.xml"));
File writeTo = new File(dataPath("myASCII.xml"));

try
{
InputStreamReader isr = new InputStreamReader(new FileInputStream(readFrom), "UTF16");
BufferedReader in = new BufferedReader(isr);
FileOutputStream fos = new FileOutputStream(writeTo);
Writer out = new OutputStreamWriter(fos, "ASCII");

String line;
while ((line = in.readLine()) != null)
{
line += "\n";
out.write(line);
}

in.close();
out.close();
}
catch(IOException ioe)
{
ioe.printStackTrace();
}
   
Re: proXML & UTF-16?
Reply #2 - Jan 6th, 2009, 12:20pm
 
Is your XML file correct Does it has a Bom And/or an encoding attribute
See opentag.com - XML FAQ: Encoding for details.

Side question: does proXML have any advantage over built-in XML support I haven't studied them enough to tell.

[EDIT] Actually, I looked at the source of proXML, and indeed it does a manual parsing, expecting the file to start with "<?xml"! So UTF-16 is out, apparently. And Processing's native XML support (coming from nanoXML IIRC) explicitly rules out anything but UTF-8 (ie. default encoding).
Page Index Toggle Pages: 1