A
Arne Vajhøj
I personally am still looking for an SSCCE, as your last one didn't
reproduce the error for me.
Did you try my 1 2 3 example?
Arne
I personally am still looking for an SSCCE, as your last one didn't
reproduce the error for me.
Did you try my 1 2 3 example?
No that errors on me too. Really all the OP did was cut and paste the
example code from his link as his SSCCE, it didn't even contain his data
file. There's no way I'm going to bother writing code for anyone who is
that lazy.
(Your code throws an exception because I have no directory named
"/work". Look up StringReader or ByteArrayInputStream. Use those
instead of relying on actual files and a file system.)
The code actually writes the files.
Yeah, I'd also rather not have artifacts on my hard drive too, thanks.
The why ask for an SSCCE?
No that errors on me too. Really all the OP did was cut and paste the
example code from his link as his SSCCE, it didn't even contain his data
file. There's no way I'm going to bother writing code for anyone who is
that lazy.
I would consider it tempting to rewrite that app to use a standard
XML parser.
It would solve this problem and possibly also some future problems.
What about just reading the first few lines until you have the
XML declaration.
Parsing the encoding out of that should be simple.
private static final Pattern encpat =
Pattern.compile("encoding\\s*=\\s*['\"]([^'\"]+)['\"]");
private static String detectSimple(String fnm) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(fnm));
String firstpart = "";
while(!firstpart.contains(">")) firstpart += br.readLine();
br.close();
Matcher m = encpat.matcher(firstpart);
if(m.find()) {
return m.group(1);
} else {
return "Unknown";
}
}
I do not like the solution, but given the restrictions in the
context, then maybe it is what you need.
file. There's no way I'm going to bother writing code for anyone who is
that lazy.
Does anyone have an idea why that is so? And how I could
go about making some XML parser determine the correct encoding?
Sussed it! (Come to think of it, I feel I've sussed this before...)
The charset returned by the locator changes during parsing. At
startDocument(), it is the assumed charset, possibly based on the first
four-or-so bytes. At endDocument(), it is reset to null. On the first
call to startElement, it has the correct value. There might be an
earlier event where it is correct - I didn't investigate.
[snip]SSCCE...
Sussed it! (Come to think of it, I feel I've sussed this before...)
The charset returned by the locator changes during parsing. At
startDocument(), it is the assumed charset, possibly based on the first
four-or-so bytes. At endDocument(), it is reset to null. On the first
call to startElement, it has the correct value.
Am 25.11.2012 03:02, schrieb markspace:
I did include an XML file with my original post, and said to use
Elliotte Rusty's code to see what it (wrongly) says about the encoding.
What else wouldyou require? Both Arne Vajhøj and Steven Simpson could
reproduce the phenomenon that way.
I did include an XML file with my original post, and said to use
Elliotte Rusty's code to see what it (wrongly) says about the encoding.
What else wouldyou require?
Because it can be done with out using files.
It isn't self-contained if it depends on my file-system. I have no
/work directory, so the example program fails, but not in the the way
intended. Ergo, it's not an SSCCE.
If you don't want input files, then ask for a MSSSCCE and link ^^^^^^^
to the rules for that.
[snip]
If you don't want input files, then ask for a MSSSCCE and link ^^^^^^^
to the rules for that.
Please expand your new acronym.
Arne said:MarkSpace SSCCE
Apparently the OP gave up on getting help and was unwilling to provide the
materials requested.
Does anyone have an idea why that is so? And how I could
go about making some XML parser determine the correct encoding?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.