-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue while converting xml to json #537
Comments
Can you provide some context? Perhaps a small XML doc that demonstrates the problem? |
|
Is the problem that the XML-to-JSON parser does not properly handle hex-encoded XML escape sequences? |
@stleary , I believe that @venkat-natsoft is pointing out that our parser is case sensitive when it should not be.
Current code: if (e.charAt(1) == 'x') { Should be: if (e.charAt(1) == 'x' || e.charAt(1) == 'X') { |
@stleary, I'm not able to reproduce with just the <tag>Neutrophils.Hypersegmented | Bld-Ser-Plas</tag> sample. It appears we already lowercase the entity:
|
Maybe OP is using an old JSON-Java release? |
ok, I used the full file, and got a slightly different issue:
So for some reason it parsed it properly in the smaller sample, but in the larger sample it left it as the encoded entity. |
ok, the issue with my test was that the source file had At this time, for random XML input I don't think we need any change. However, since If you agree, I'll make the PR. At this time I have a branch with tests showing that there is no error on parsing. |
Exactly that's what happening with a smaller portion and the whole document. Please trace the issue . |
xml: Hypersegmented | Bld-Ser-Pla
Caller method:
JSONObject xmlJSONObj = XML.toJSONObject(xml, true);
Error:
Caused by: java.lang.NumberFormatException: For input string: "X7C"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_201]
at java.lang.Integer.parseInt(Integer.java:580) ~[na:1.8.0_201]
at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_201]
at org.json.XML.unescape(XML.java:200) ~[json-20170516.jar:na]
at org.json.XML.parse(XML.java:398) ~[json-20170516.jar:na]
at org.json.XML.parse(XML.java:403) ~[json-20170516.jar:na]
at org.json.XML.toJSONObject(XML.java:485) ~[json-20170516.jar:na]
Error at calle:
at org.json.XML. public static String unescape(String string)
Error prone code piece
if (entity.charAt(1) == 'x') {
// hex encoded unicode
cp = Integer.parseInt(entity.substring(2), 16);
} else {
// decimal encoded unicode
cp = Integer.parseInt(entity.substring(1));
}
The text was updated successfully, but these errors were encountered: