My code was working fine yesterday, but I start it up again today and am getting the error
org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: not well-formed (invalid token)
The xml in question doesn’t have any funky characters. It is stored in a String variable called “xml”. To be fair, I wasn’t really sure how to deal with that and was just going off of some tutorials, but here was my attempt.
out = new PrintWriter(mySocket.getOutputStream(), true);
BufferedReader br = new BufferedReader(new InputStreamReader(mySocket.getInputStream(), "US-ASCII"));
InputStream is = mySocket.getInputStream();
...
String xml = the stuff that was read in with br.read();
...
SAXParserFactory saxPF = SAXParserFactory.newInstance();
SAXParser saxP = saxPF.newSAXParser();
XMLReader xmlR = saxP.getXMLReader();
DataHandler myDataHandler = new DataHandler();
xmlR.setContentHandler(myDataHandler);
xmlR.parse(new InputSource(new StringReader(xml)));
myData = myDataHandler.getData();
Where did I go wrong?
Update: The xml starts with
<?xml version="1.0" standalone="yes"?>
so it doesn’t seem that “line 1, column 0” actually has anything wrong with it.
Update 2: I found that is.available() is returning 0…. How do I make do with the fixing?
I’m not sure what the problem was in the end, but I changed several things and have it somewhat working. Here’s what I changed:
I changed
to
And I didn’t include this in the original question (it was part of the “…”), but I got rid of the condition
because it was returning 0 even though read() worked just find without it. This is probably just a temporary hack though, and I’ll need to figure out why it’s returning 0 and find a legitimate fix…