From 78f1481f3882695bc72ece3b4a0d46da7610f75c Mon Sep 17 00:00:00 2001 From: jaimeagudo Date: Tue, 3 Nov 2015 19:01:14 +0100 Subject: [PATCH 1/2] Do not generate an empty string JSON value for an empty XML tag --- XML.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/XML.java b/XML.java index 23a991906..57c3a5107 100755 --- a/XML.java +++ b/XML.java @@ -243,9 +243,11 @@ private static boolean parse(XMLTokener x, JSONObject context, } if (jsonobject.length() > 0) { context.accumulate(tagName, jsonobject); - } else { - context.accumulate(tagName, ""); } + // We do not want to consider empty tags + // else { + // context.accumulate(tagName, ""); + // } return false; // Content, between <...> and @@ -473,7 +475,7 @@ public static String toString(Object object, String tagName) if (object.getClass().isArray()) { object = new JSONArray(object); } - + if (object instanceof JSONArray) { ja = (JSONArray)object; length = ja.length(); @@ -487,6 +489,6 @@ public static String toString(Object object, String tagName) return (tagName == null) ? "\"" + string + "\"" : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName + ">" + string + ""; - + } } From 20d96f8ec3d06ad0f4d1adfdc29014f2fe6b29d0 Mon Sep 17 00:00:00 2001 From: jaimeagudo Date: Tue, 3 Nov 2015 20:07:28 +0100 Subject: [PATCH 2/2] Update javadoc --- XML.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/XML.java b/XML.java index 57c3a5107..01f58e5d5 100755 --- a/XML.java +++ b/XML.java @@ -120,6 +120,9 @@ public static void noSpace(String string) throws JSONException { /** * Scan the content following the named tag, attaching it to the context. + * + * It does NOT generate an empty string JSON value for an empty XML tag. + * * @param x The XMLTokener containing the source string. * @param context The JSONObject that will include the new material. * @param name The tag name.