diff --git a/src/main/java/org/json/XML.java b/src/main/java/org/json/XML.java index 69782cbdd..bb614d4ac 100644 --- a/src/main/java/org/json/XML.java +++ b/src/main/java/org/json/XML.java @@ -752,6 +752,28 @@ public static String toString(final Object object, final String tagName) { */ public static String toString(final Object object, final String tagName, final XMLParserConfiguration config) throws JSONException { + return toString(object, tagName, config, 0, 0); + } + + /** + * Convert a JSONObject into a well-formed, element-normal XML string, + * either pretty print or single-lined depending on indent factor. + * + * @param object + * A JSONObject. + * @param tagName + * The optional name of the enclosing tag. + * @param config + * Configuration that can control output to XML. + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @param indent + * The current ident level in spaces. + * @return + * @throws JSONException + */ + private static String toString(final Object object, final String tagName, final XMLParserConfiguration config, int indentFactor, int indent) + throws JSONException { StringBuilder sb = new StringBuilder(); JSONArray ja; JSONObject jo; @@ -761,9 +783,14 @@ public static String toString(final Object object, final String tagName, final X // Emit if (tagName != null) { + sb.append(indent(indent)); sb.append('<'); sb.append(tagName); sb.append('>'); + if(indentFactor > 0){ + sb.append("\n"); + indent += indentFactor; + } } // Loop thru the keys. @@ -806,31 +833,39 @@ public static String toString(final Object object, final String tagName, final X sb.append('<'); sb.append(key); sb.append('>'); - sb.append(toString(val, null, config)); + sb.append(toString(val, null, config, indentFactor, indent)); sb.append("'); } else { - sb.append(toString(val, key, config)); + sb.append(toString(val, key, config, indentFactor, indent)); } } } else if ("".equals(value)) { + sb.append(indent(indent)); sb.append('<'); sb.append(key); sb.append("/>"); + if(indentFactor > 0){ + sb.append("\n"); + } // Emit a new tag } else { - sb.append(toString(value, key, config)); + sb.append(toString(value, key, config, indentFactor, indent)); } } if (tagName != null) { // Emit the close tag + sb.append(indent(indent - indentFactor)); sb.append("'); + if(indentFactor > 0){ + sb.append("\n"); + } } return sb.toString(); @@ -849,15 +884,85 @@ public static String toString(final Object object, final String tagName, final X // XML does not have good support for arrays. If an array // appears in a place where XML is lacking, synthesize an // element. - sb.append(toString(val, tagName == null ? "array" : tagName, config)); + sb.append(toString(val, tagName == null ? "array" : tagName, config, indentFactor, indent)); } return sb.toString(); } + string = (object == null) ? "null" : escape(object.toString()); - return (tagName == null) ? "\"" + string + "\"" - : (string.length() == 0) ? "<" + tagName + "/>" : "<" + tagName - + ">" + string + ""; + if(tagName == null){ + return indent(indent) + "\"" + string + "\"" + ((indentFactor > 0) ? "\n" : ""); + } else if(string.length() == 0){ + return indent(indent) + "<" + tagName + "/>" + ((indentFactor > 0) ? "\n" : ""); + } else { + return indent(indent) + "<" + tagName + + ">" + string + "" + ((indentFactor > 0) ? "\n" : ""); + } + } + + /** + * Convert a JSONObject into a well-formed, pretty printed element-normal XML string. + * + * @param object + * A JSONObject. + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return A string. + * @throws JSONException Thrown if there is an error parsing the string + */ + public static String toString(Object object, int indentFactor){ + return toString(object, null, XMLParserConfiguration.ORIGINAL, indentFactor); + } + + /** + * Convert a JSONObject into a well-formed, pretty printed element-normal XML string. + * + * @param object + * A JSONObject. + * @param tagName + * The optional name of the enclosing tag. + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return A string. + * @throws JSONException Thrown if there is an error parsing the string + */ + public static String toString(final Object object, final String tagName, int indentFactor) { + return toString(object, tagName, XMLParserConfiguration.ORIGINAL, indentFactor); + } + + /** + * Convert a JSONObject into a well-formed, pretty printed element-normal XML string. + * + * @param object + * A JSONObject. + * @param tagName + * The optional name of the enclosing tag. + * @param config + * Configuration that can control output to XML. + * @param indentFactor + * The number of spaces to add to each level of indentation. + * @return A string. + * @throws JSONException Thrown if there is an error parsing the string + */ + public static String toString(final Object object, final String tagName, final XMLParserConfiguration config, int indentFactor) + throws JSONException { + return toString(object, tagName, config, indentFactor, 0); + } + + /** + * Return a String consisting of a number of space characters specified by indent + * + * @param indent + * The number of spaces to be appended to the String. + * @return + */ + private static final String indent(int indent) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < indent; i++) { + sb.append(' '); + } + return sb.toString(); } } diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java index 906924df3..937658e86 100644 --- a/src/test/java/org/json/junit/XMLTest.java +++ b/src/test/java/org/json/junit/XMLTest.java @@ -21,13 +21,7 @@ import java.util.HashMap; import java.util.Map; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONTokener; -import org.json.XML; -import org.json.XMLParserConfiguration; -import org.json.XMLXsiTypeConverter; +import org.json.*; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -1049,4 +1043,211 @@ public void testXSITypeMapNotModifiable() { fail("Expected to be unable to modify the config"); } catch (Exception ignored) { } } + + @Test + public void testIndentComplicatedJsonObject(){ + String str = "{\n" + + " \"success\": true,\n" + + " \"error\": null,\n" + + " \"response\": [\n" + + " {\n" + + " \"timestamp\": 1664917200,\n" + + " \"dateTimeISO\": \"2022-10-05T00:00:00+03:00\",\n" + + " \"loc\": {\n" + + " \"lat\": 39.91987,\n" + + " \"long\": 32.85427\n" + + " },\n" + + " \"place\": {\n" + + " \"name\": \"ankara\",\n" + + " \"state\": \"an\",\n" + + " \"country\": \"tr\"\n" + + " },\n" + + " \"profile\": {\n" + + " \"tz\": \"Europe/Istanbul\"\n" + + " },\n" + + " \"sun\": {\n" + + " \"rise\": 1664941721,\n" + + " \"riseISO\": \"2022-10-05T06:48:41+03:00\",\n" + + " \"set\": 1664983521,\n" + + " \"setISO\": \"2022-10-05T18:25:21+03:00\",\n" + + " \"transit\": 1664962621,\n" + + " \"transitISO\": \"2022-10-05T12:37:01+03:00\",\n" + + " \"midnightSun\": false,\n" + + " \"polarNight\": false,\n" + + " \"twilight\": {\n" + + " \"civilBegin\": 1664940106,\n" + + " \"civilBeginISO\": \"2022-10-05T06:21:46+03:00\",\n" + + " \"civilEnd\": 1664985136,\n" + + " \"civilEndISO\": \"2022-10-05T18:52:16+03:00\",\n" + + " \"nauticalBegin\": 1664938227,\n" + + " \"nauticalBeginISO\": \"2022-10-05T05:50:27+03:00\",\n" + + " \"nauticalEnd\": 1664987015,\n" + + " \"nauticalEndISO\": \"2022-10-05T19:23:35+03:00\",\n" + + " \"astronomicalBegin\": 1664936337,\n" + + " \"astronomicalBeginISO\": \"2022-10-05T05:18:57+03:00\",\n" + + " \"astronomicalEnd\": 1664988905,\n" + + " \"astronomicalEndISO\": \"2022-10-05T19:55:05+03:00\"\n" + + " }\n" + + " },\n" + + " \"moon\": {\n" + + " \"rise\": 1664976480,\n" + + " \"riseISO\": \"2022-10-05T16:28:00+03:00\",\n" + + " \"set\": 1664921520,\n" + + " \"setISO\": \"2022-10-05T01:12:00+03:00\",\n" + + " \"transit\": 1664994240,\n" + + " \"transitISO\": \"2022-10-05T21:24:00+03:00\",\n" + + " \"underfoot\": 1664949360,\n" + + " \"underfootISO\": \"2022-10-05T08:56:00+03:00\",\n" + + " \"phase\": {\n" + + " \"phase\": 0.3186,\n" + + " \"name\": \"waxing gibbous\",\n" + + " \"illum\": 71,\n" + + " \"age\": 9.41,\n" + + " \"angle\": 0.55\n" + + " }\n" + + " }\n" + + " }\n" + + " ]\n" + + "}" ; + JSONObject jsonObject = new JSONObject(str); + String actualIndentedXmlString = XML.toString(jsonObject, 1); + String expected = "true\n" + + "\n" + + " 2022-10-05T00:00:00+03:00\n" + + " \n" + + " 39.91987\n" + + " 32.85427\n" + + " \n" + + " \n" + + " \n" + + " 0.3186\n" + + " waxing gibbous\n" + + " 0.55\n" + + " 71\n" + + " 9.41\n" + + " \n" + + " 2022-10-05T01:12:00+03:00\n" + + " 1664949360\n" + + " 1664921520\n" + + " 1664994240\n" + + " 2022-10-05T21:24:00+03:00\n" + + " 2022-10-05T16:28:00+03:00\n" + + " 1664976480\n" + + " 2022-10-05T08:56:00+03:00\n" + + " \n" + + " \n" + + " Europe/Istanbul\n" + + " \n" + + " \n" + + " tr\n" + + " ankara\n" + + " an\n" + + " \n" + + " \n" + + " 2022-10-05T18:25:21+03:00\n" + + " false\n" + + " 1664983521\n" + + " 1664962621\n" + + " false\n" + + " 2022-10-05T12:37:01+03:00\n" + + " 2022-10-05T06:48:41+03:00\n" + + " 1664941721\n" + + " \n" + + " 1664985136\n" + + " 1664936337\n" + + " 1664988905\n" + + " 2022-10-05T05:18:57+03:00\n" + + " 1664940106\n" + + " 2022-10-05T19:23:35+03:00\n" + + " 2022-10-05T19:55:05+03:00\n" + + " 1664938227\n" + + " 1664987015\n" + + " 2022-10-05T05:50:27+03:00\n" + + " 2022-10-05T06:21:46+03:00\n" + + " 2022-10-05T18:52:16+03:00\n" + + " \n" + + " \n" + + " 1664917200\n" + + "\n" + + "null\n"; + assertEquals(actualIndentedXmlString, expected); + + + } + @Test + public void testIndentSimpleJsonObject(){ + String str = "{ \"employee\": { \n" + + " \"name\": \"sonoo\", \n" + + " \"salary\": 56000, \n" + + " \"married\": true \n" + + " }}"; + JSONObject jsonObject = new JSONObject(str); + String actual = XML.toString(jsonObject, "Test", 2); + String expected = "\n" + + " \n" + + " sonoo\n" + + " 56000\n" + + " true\n" + + " \n" + + "\n"; + assertEquals(actual, expected); + } + + @Test + public void testIndentSimpleJsonArray(){ + String str = "[ \n" + + " {\"name\":\"Ram\", \"email\":\"Ram@gmail.com\"}, \n" + + " {\"name\":\"Bob\", \"email\":\"bob32@gmail.com\"} \n" + + "] "; + JSONArray jsonObject = new JSONArray(str); + String actual = XML.toString(jsonObject, 2); + String expected = "\n" + + " Ram\n" + + " Ram@gmail.com\n" + + "\n" + + "\n" + + " Bob\n" + + " bob32@gmail.com\n" + + "\n"; + assertEquals(actual, expected); + + + } + + @Test + public void testIndentComplicatedJsonObjectWithArrayAndWithConfig(){ + try { + InputStream jsonStream = null; + try { + jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.json"); + final JSONObject object = new JSONObject(new JSONTokener(jsonStream)); + String actualString = XML.toString(object, null, XMLParserConfiguration.KEEP_STRINGS,2); + InputStream xmlStream = null; + try { + xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.xml"); + int bufferSize = 1024; + char[] buffer = new char[bufferSize]; + StringBuilder expected = new StringBuilder(); + Reader in = new InputStreamReader(xmlStream, "UTF-8"); + for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) { + expected.append(buffer, 0, numRead); + } + assertEquals(expected.toString(), actualString.replaceAll("\\n|\\r\\n", System.getProperty("line.separator"))); + } finally { + if (xmlStream != null) { + xmlStream.close(); + } + } + } finally { + if (jsonStream != null) { + jsonStream.close(); + } + } + } catch (IOException e) { + fail("file writer error: " +e.getMessage()); + } + } } + + + diff --git a/src/test/resources/Issue593.json b/src/test/resources/Issue593.json new file mode 100644 index 000000000..213625af2 --- /dev/null +++ b/src/test/resources/Issue593.json @@ -0,0 +1,704 @@ +{ + "success": true, + "error": null, + "response": [ + { + "loc": { + "long": 31.25, + "lat": 30.063 + }, + "interval": "day", + "place": { + "name": "cairo", + "state": "qh", + "country": "eg" + }, + "periods": [ + { + "timestamp": 1665032400, + "validTime": "2022-10-06T07:00:00+02:00", + "dateTimeISO": "2022-10-06T07:00:00+02:00", + "maxTempC": 32, + "maxTempF": 90, + "minTempC": 19, + "minTempF": 66, + "avgTempC": 25, + "avgTempF": 78, + "tempC": null, + "tempF": null, + "maxFeelslikeC": 32, + "maxFeelslikeF": 89, + "minFeelslikeC": 21, + "minFeelslikeF": 70, + "avgFeelslikeC": 26, + "avgFeelslikeF": 80, + "feelslikeC": 21, + "feelslikeF": 70, + "maxDewpointC": 17, + "maxDewpointF": 63, + "minDewpointC": 11, + "minDewpointF": 52, + "avgDewpointC": 14, + "avgDewpointF": 58, + "dewpointC": 17, + "dewpointF": 63, + "maxHumidity": 77, + "minHumidity": 29, + "humidity": 77, + "pop": 0, + "precipMM": 0, + "precipIN": 0, + "iceaccum": null, + "iceaccumMM": null, + "iceaccumIN": null, + "snowCM": 0, + "snowIN": 0, + "pressureMB": 1015, + "pressureIN": 29.97, + "windDir": "N", + "windDirDEG": 353, + "windSpeedKTS": 5, + "windSpeedKPH": 9, + "windSpeedMPH": 6, + "windGustKTS": 21, + "windGustKPH": 40, + "windGustMPH": 25, + "windDirMax": "NNW", + "windDirMaxDEG": 342, + "windSpeedMaxKTS": 9, + "windSpeedMaxKPH": 16, + "windSpeedMaxMPH": 10, + "windDirMin": "N", + "windDirMinDEG": 353, + "windSpeedMinKTS": 1, + "windSpeedMinKPH": 2, + "windSpeedMinMPH": 1, + "windDir80m": "N", + "windDir80mDEG": 11, + "windSpeed80mKTS": 12, + "windSpeed80mKPH": 22, + "windSpeed80mMPH": 13, + "windGust80mKTS": 22, + "windGust80mKPH": 41, + "windGust80mMPH": 25, + "windDirMax80m": "NNW", + "windDirMax80mDEG": 343, + "windSpeedMax80mKTS": 22, + "windSpeedMax80mKPH": 41, + "windSpeedMax80mMPH": 25, + "windDirMin80m": "E", + "windDirMin80mDEG": 95, + "windSpeedMin80mKTS": 8, + "windSpeedMin80mKPH": 15, + "windSpeedMin80mMPH": 10, + "sky": 22, + "cloudsCoded": "FW", + "weather": "Mostly Sunny", + "weatherCoded": [], + "weatherPrimary": "Mostly Sunny", + "weatherPrimaryCoded": "::FW", + "icon": "fair.png", + "visibilityKM": 24.135, + "visibilityMI": 15, + "uvi": 6, + "solradWM2": 5608, + "solradMinWM2": 0, + "solradMaxWM2": 778, + "isDay": true, + "maxCoverage": "", + "sunrise": 1665028274, + "sunset": 1665070502, + "sunriseISO": "2022-10-06T05:51:14+02:00", + "sunsetISO": "2022-10-06T17:35:02+02:00" + }, + { + "timestamp": 1665118800, + "validTime": "2022-10-07T07:00:00+02:00", + "dateTimeISO": "2022-10-07T07:00:00+02:00", + "maxTempC": 30, + "maxTempF": 86, + "minTempC": 19, + "minTempF": 66, + "avgTempC": 24, + "avgTempF": 76, + "tempC": null, + "tempF": null, + "maxFeelslikeC": 29, + "maxFeelslikeF": 85, + "minFeelslikeC": 19, + "minFeelslikeF": 67, + "avgFeelslikeC": 24, + "avgFeelslikeF": 76, + "feelslikeC": 19, + "feelslikeF": 67, + "maxDewpointC": 15, + "maxDewpointF": 60, + "minDewpointC": 10, + "minDewpointF": 50, + "avgDewpointC": 12, + "avgDewpointF": 54, + "dewpointC": 15, + "dewpointF": 60, + "maxHumidity": 77, + "minHumidity": 30, + "humidity": 77, + "pop": 0, + "precipMM": 0, + "precipIN": 0, + "iceaccum": null, + "iceaccumMM": null, + "iceaccumIN": null, + "snowCM": 0, + "snowIN": 0, + "pressureMB": 1014, + "pressureIN": 29.95, + "windDir": "NW", + "windDirDEG": 325, + "windSpeedKTS": 1, + "windSpeedKPH": 2, + "windSpeedMPH": 1, + "windGustKTS": 16, + "windGustKPH": 29, + "windGustMPH": 18, + "windDirMax": "WNW", + "windDirMaxDEG": 298, + "windSpeedMaxKTS": 7, + "windSpeedMaxKPH": 13, + "windSpeedMaxMPH": 8, + "windDirMin": "NW", + "windDirMinDEG": 325, + "windSpeedMinKTS": 1, + "windSpeedMinKPH": 2, + "windSpeedMinMPH": 1, + "windDir80m": "NNW", + "windDir80mDEG": 347, + "windSpeed80mKTS": 6, + "windSpeed80mKPH": 10, + "windSpeed80mMPH": 6, + "windGust80mKTS": 20, + "windGust80mKPH": 37, + "windGust80mMPH": 23, + "windDirMax80m": "NW", + "windDirMax80mDEG": 316, + "windSpeedMax80mKTS": 20, + "windSpeedMax80mKPH": 37, + "windSpeedMax80mMPH": 23, + "windDirMin80m": "NNW", + "windDirMin80mDEG": 347, + "windSpeedMin80mKTS": 6, + "windSpeedMin80mKPH": 10, + "windSpeedMin80mMPH": 6, + "sky": 30, + "cloudsCoded": "FW", + "weather": "Mostly Sunny", + "weatherCoded": [], + "weatherPrimary": "Mostly Sunny", + "weatherPrimaryCoded": "::FW", + "icon": "fair.png", + "visibilityKM": 24.135, + "visibilityMI": 15, + "uvi": 6, + "solradWM2": 5486, + "solradMinWM2": 0, + "solradMaxWM2": 742, + "isDay": true, + "maxCoverage": "", + "sunrise": 1665114710, + "sunset": 1665156831, + "sunriseISO": "2022-10-07T05:51:50+02:00", + "sunsetISO": "2022-10-07T17:33:51+02:00" + }, + { + "timestamp": 1665205200, + "validTime": "2022-10-08T07:00:00+02:00", + "dateTimeISO": "2022-10-08T07:00:00+02:00", + "maxTempC": 30, + "maxTempF": 87, + "minTempC": 19, + "minTempF": 66, + "avgTempC": 25, + "avgTempF": 76, + "tempC": null, + "tempF": null, + "maxFeelslikeC": 30, + "maxFeelslikeF": 86, + "minFeelslikeC": 19, + "minFeelslikeF": 67, + "avgFeelslikeC": 25, + "avgFeelslikeF": 76, + "feelslikeC": 19, + "feelslikeF": 67, + "maxDewpointC": 15, + "maxDewpointF": 59, + "minDewpointC": 11, + "minDewpointF": 52, + "avgDewpointC": 13, + "avgDewpointF": 56, + "dewpointC": 15, + "dewpointF": 59, + "maxHumidity": 76, + "minHumidity": 32, + "humidity": 76, + "pop": 0, + "precipMM": 0, + "precipIN": 0, + "iceaccum": null, + "iceaccumMM": null, + "iceaccumIN": null, + "snowCM": 0, + "snowIN": 0, + "pressureMB": 1014, + "pressureIN": 29.94, + "windDir": "NNE", + "windDirDEG": 21, + "windSpeedKTS": 1, + "windSpeedKPH": 2, + "windSpeedMPH": 1, + "windGustKTS": 17, + "windGustKPH": 32, + "windGustMPH": 20, + "windDirMax": "WNW", + "windDirMaxDEG": 301, + "windSpeedMaxKTS": 7, + "windSpeedMaxKPH": 13, + "windSpeedMaxMPH": 8, + "windDirMin": "NNE", + "windDirMinDEG": 21, + "windSpeedMinKTS": 1, + "windSpeedMinKPH": 2, + "windSpeedMinMPH": 1, + "windDir80m": "NW", + "windDir80mDEG": 309, + "windSpeed80mKTS": 5, + "windSpeed80mKPH": 9, + "windSpeed80mMPH": 5, + "windGust80mKTS": 17, + "windGust80mKPH": 31, + "windGust80mMPH": 19, + "windDirMax80m": "NW", + "windDirMax80mDEG": 322, + "windSpeedMax80mKTS": 17, + "windSpeedMax80mKPH": 31, + "windSpeedMax80mMPH": 19, + "windDirMin80m": "NW", + "windDirMin80mDEG": 309, + "windSpeedMin80mKTS": 5, + "windSpeedMin80mKPH": 9, + "windSpeedMin80mMPH": 5, + "sky": 47, + "cloudsCoded": "SC", + "weather": "Partly Cloudy", + "weatherCoded": [], + "weatherPrimary": "Partly Cloudy", + "weatherPrimaryCoded": "::SC", + "icon": "pcloudy.png", + "visibilityKM": 24.135, + "visibilityMI": 15, + "uvi": 7, + "solradWM2": 4785, + "solradMinWM2": 0, + "solradMaxWM2": 682, + "isDay": true, + "maxCoverage": "", + "sunrise": 1665201146, + "sunset": 1665243161, + "sunriseISO": "2022-10-08T05:52:26+02:00", + "sunsetISO": "2022-10-08T17:32:41+02:00" + }, + { + "timestamp": 1665291600, + "validTime": "2022-10-09T07:00:00+02:00", + "dateTimeISO": "2022-10-09T07:00:00+02:00", + "maxTempC": 31, + "maxTempF": 87, + "minTempC": 19, + "minTempF": 67, + "avgTempC": 25, + "avgTempF": 77, + "tempC": null, + "tempF": null, + "maxFeelslikeC": 30, + "maxFeelslikeF": 86, + "minFeelslikeC": 20, + "minFeelslikeF": 67, + "avgFeelslikeC": 25, + "avgFeelslikeF": 77, + "feelslikeC": 20, + "feelslikeF": 67, + "maxDewpointC": 17, + "maxDewpointF": 63, + "minDewpointC": 11, + "minDewpointF": 52, + "avgDewpointC": 14, + "avgDewpointF": 57, + "dewpointC": 17, + "dewpointF": 63, + "maxHumidity": 86, + "minHumidity": 31, + "humidity": 86, + "pop": 0, + "precipMM": 0, + "precipIN": 0, + "iceaccum": null, + "iceaccumMM": null, + "iceaccumIN": null, + "snowCM": 0, + "snowIN": 0, + "pressureMB": 1016, + "pressureIN": 29.99, + "windDir": "N", + "windDirDEG": 356, + "windSpeedKTS": 2, + "windSpeedKPH": 4, + "windSpeedMPH": 2, + "windGustKTS": 19, + "windGustKPH": 36, + "windGustMPH": 22, + "windDirMax": "NNW", + "windDirMaxDEG": 343, + "windSpeedMaxKTS": 8, + "windSpeedMaxKPH": 14, + "windSpeedMaxMPH": 9, + "windDirMin": "N", + "windDirMinDEG": 356, + "windSpeedMinKTS": 2, + "windSpeedMinKPH": 4, + "windSpeedMinMPH": 2, + "windDir80m": "NW", + "windDir80mDEG": 316, + "windSpeed80mKTS": 5, + "windSpeed80mKPH": 9, + "windSpeed80mMPH": 6, + "windGust80mKTS": 20, + "windGust80mKPH": 36, + "windGust80mMPH": 23, + "windDirMax80m": "N", + "windDirMax80mDEG": 354, + "windSpeedMax80mKTS": 20, + "windSpeedMax80mKPH": 36, + "windSpeedMax80mMPH": 23, + "windDirMin80m": "NW", + "windDirMin80mDEG": 316, + "windSpeedMin80mKTS": 5, + "windSpeedMin80mKPH": 9, + "windSpeedMin80mMPH": 6, + "sky": 47, + "cloudsCoded": "SC", + "weather": "Partly Cloudy", + "weatherCoded": [], + "weatherPrimary": "Partly Cloudy", + "weatherPrimaryCoded": "::SC", + "icon": "pcloudy.png", + "visibilityKM": 24.135, + "visibilityMI": 15, + "uvi": 7, + "solradWM2": 4768, + "solradMinWM2": 0, + "solradMaxWM2": 726, + "isDay": true, + "maxCoverage": "", + "sunrise": 1665287583, + "sunset": 1665329491, + "sunriseISO": "2022-10-09T05:53:03+02:00", + "sunsetISO": "2022-10-09T17:31:31+02:00" + }, + { + "timestamp": 1665378000, + "validTime": "2022-10-10T07:00:00+02:00", + "dateTimeISO": "2022-10-10T07:00:00+02:00", + "maxTempC": 31, + "maxTempF": 87, + "minTempC": 21, + "minTempF": 70, + "avgTempC": 26, + "avgTempF": 78, + "tempC": null, + "tempF": null, + "maxFeelslikeC": 30, + "maxFeelslikeF": 86, + "minFeelslikeC": 21, + "minFeelslikeF": 69, + "avgFeelslikeC": 25, + "avgFeelslikeF": 78, + "feelslikeC": 21, + "feelslikeF": 69, + "maxDewpointC": 16, + "maxDewpointF": 61, + "minDewpointC": 13, + "minDewpointF": 55, + "avgDewpointC": 14, + "avgDewpointF": 58, + "dewpointC": 16, + "dewpointF": 61, + "maxHumidity": 75, + "minHumidity": 35, + "humidity": 75, + "pop": 0, + "precipMM": 0, + "precipIN": 0, + "iceaccum": null, + "iceaccumMM": null, + "iceaccumIN": null, + "snowCM": 0, + "snowIN": 0, + "pressureMB": 1017, + "pressureIN": 30.03, + "windDir": "N", + "windDirDEG": 358, + "windSpeedKTS": 2, + "windSpeedKPH": 4, + "windSpeedMPH": 2, + "windGustKTS": 16, + "windGustKPH": 30, + "windGustMPH": 19, + "windDirMax": "N", + "windDirMaxDEG": 10, + "windSpeedMaxKTS": 8, + "windSpeedMaxKPH": 15, + "windSpeedMaxMPH": 9, + "windDirMin": "N", + "windDirMinDEG": 358, + "windSpeedMinKTS": 2, + "windSpeedMinKPH": 4, + "windSpeedMinMPH": 2, + "windDir80m": "N", + "windDir80mDEG": 8, + "windSpeed80mKTS": 7, + "windSpeed80mKPH": 13, + "windSpeed80mMPH": 8, + "windGust80mKTS": 19, + "windGust80mKPH": 36, + "windGust80mMPH": 22, + "windDirMax80m": "N", + "windDirMax80mDEG": 10, + "windSpeedMax80mKTS": 19, + "windSpeedMax80mKPH": 36, + "windSpeedMax80mMPH": 22, + "windDirMin80m": "E", + "windDirMin80mDEG": 91, + "windSpeedMin80mKTS": 7, + "windSpeedMin80mKPH": 13, + "windSpeedMin80mMPH": 8, + "sky": 64, + "cloudsCoded": "SC", + "weather": "Partly Cloudy", + "weatherCoded": [], + "weatherPrimary": "Partly Cloudy", + "weatherPrimaryCoded": "::SC", + "icon": "pcloudy.png", + "visibilityKM": 24.135, + "visibilityMI": 15, + "uvi": 6, + "solradWM2": 4494, + "solradMinWM2": 0, + "solradMaxWM2": 597, + "isDay": true, + "maxCoverage": "", + "sunrise": 1665374020, + "sunset": 1665415821, + "sunriseISO": "2022-10-10T05:53:40+02:00", + "sunsetISO": "2022-10-10T17:30:21+02:00" + }, + { + "timestamp": 1665464400, + "validTime": "2022-10-11T07:00:00+02:00", + "dateTimeISO": "2022-10-11T07:00:00+02:00", + "maxTempC": 31, + "maxTempF": 87, + "minTempC": 21, + "minTempF": 70, + "avgTempC": 26, + "avgTempF": 78, + "tempC": null, + "tempF": null, + "maxFeelslikeC": 31, + "maxFeelslikeF": 87, + "minFeelslikeC": 22, + "minFeelslikeF": 72, + "avgFeelslikeC": 26, + "avgFeelslikeF": 79, + "feelslikeC": 22, + "feelslikeF": 72, + "maxDewpointC": 17, + "maxDewpointF": 62, + "minDewpointC": 11, + "minDewpointF": 51, + "avgDewpointC": 13, + "avgDewpointF": 55, + "dewpointC": 17, + "dewpointF": 62, + "maxHumidity": 71, + "minHumidity": 30, + "humidity": 71, + "pop": 0, + "precipMM": 0, + "precipIN": 0, + "iceaccum": null, + "iceaccumMM": null, + "iceaccumIN": null, + "snowCM": 0, + "snowIN": 0, + "pressureMB": 1015, + "pressureIN": 29.98, + "windDir": "NNE", + "windDirDEG": 13, + "windSpeedKTS": 8, + "windSpeedKPH": 15, + "windSpeedMPH": 9, + "windGustKTS": 15, + "windGustKPH": 28, + "windGustMPH": 17, + "windDirMax": "NNE", + "windDirMaxDEG": 28, + "windSpeedMaxKTS": 15, + "windSpeedMaxKPH": 28, + "windSpeedMaxMPH": 18, + "windDirMin": "NNE", + "windDirMinDEG": 14, + "windSpeedMinKTS": 7, + "windSpeedMinKPH": 14, + "windSpeedMinMPH": 8, + "windDir80m": "NNE", + "windDir80mDEG": 16, + "windSpeed80mKTS": 10, + "windSpeed80mKPH": 19, + "windSpeed80mMPH": 12, + "windGust80mKTS": 17, + "windGust80mKPH": 31, + "windGust80mMPH": 19, + "windDirMax80m": "NNE", + "windDirMax80mDEG": 28, + "windSpeedMax80mKTS": 17, + "windSpeedMax80mKPH": 31, + "windSpeedMax80mMPH": 19, + "windDirMin80m": "NNE", + "windDirMin80mDEG": 13, + "windSpeedMin80mKTS": 9, + "windSpeedMin80mKPH": 18, + "windSpeedMin80mMPH": 11, + "sky": 0, + "cloudsCoded": "CL", + "weather": "Sunny", + "weatherCoded": [], + "weatherPrimary": "Sunny", + "weatherPrimaryCoded": "::CL", + "icon": "sunny.png", + "visibilityKM": 24.135, + "visibilityMI": 15, + "uvi": null, + "solradWM2": 5450, + "solradMinWM2": 0, + "solradMaxWM2": 758, + "isDay": true, + "maxCoverage": "", + "sunrise": 1665460458, + "sunset": 1665502153, + "sunriseISO": "2022-10-11T05:54:18+02:00", + "sunsetISO": "2022-10-11T17:29:13+02:00" + }, + { + "timestamp": 1665550800, + "validTime": "2022-10-12T07:00:00+02:00", + "dateTimeISO": "2022-10-12T07:00:00+02:00", + "maxTempC": 31, + "maxTempF": 88, + "minTempC": 21, + "minTempF": 69, + "avgTempC": 26, + "avgTempF": 79, + "tempC": null, + "tempF": null, + "maxFeelslikeC": 31, + "maxFeelslikeF": 88, + "minFeelslikeC": 22, + "minFeelslikeF": 72, + "avgFeelslikeC": 26, + "avgFeelslikeF": 80, + "feelslikeC": 22, + "feelslikeF": 72, + "maxDewpointC": 16, + "maxDewpointF": 60, + "minDewpointC": 11, + "minDewpointF": 51, + "avgDewpointC": 13, + "avgDewpointF": 55, + "dewpointC": 16, + "dewpointF": 60, + "maxHumidity": 68, + "minHumidity": 29, + "humidity": 68, + "pop": 0, + "precipMM": 0, + "precipIN": 0, + "iceaccum": null, + "iceaccumMM": null, + "iceaccumIN": null, + "snowCM": 0, + "snowIN": 0, + "pressureMB": 1014, + "pressureIN": 29.95, + "windDir": "NNE", + "windDirDEG": 12, + "windSpeedKTS": 8, + "windSpeedKPH": 15, + "windSpeedMPH": 9, + "windGustKTS": 15, + "windGustKPH": 28, + "windGustMPH": 17, + "windDirMax": "E", + "windDirMaxDEG": 96, + "windSpeedMaxKTS": 14, + "windSpeedMaxKPH": 26, + "windSpeedMaxMPH": 16, + "windDirMin": "NNE", + "windDirMinDEG": 12, + "windSpeedMinKTS": 7, + "windSpeedMinKPH": 13, + "windSpeedMinMPH": 8, + "windDir80m": "NNE", + "windDir80mDEG": 15, + "windSpeed80mKTS": 10, + "windSpeed80mKPH": 19, + "windSpeed80mMPH": 12, + "windGust80mKTS": 18, + "windGust80mKPH": 33, + "windGust80mMPH": 21, + "windDirMax80m": "E", + "windDirMax80mDEG": 96, + "windSpeedMax80mKTS": 18, + "windSpeedMax80mKPH": 33, + "windSpeedMax80mMPH": 21, + "windDirMin80m": "NNE", + "windDirMin80mDEG": 15, + "windSpeedMin80mKTS": 10, + "windSpeedMin80mKPH": 18, + "windSpeedMin80mMPH": 11, + "sky": 27, + "cloudsCoded": "FW", + "weather": "Mostly Sunny", + "weatherCoded": [], + "weatherPrimary": "Mostly Sunny", + "weatherPrimaryCoded": "::FW", + "icon": "fair.png", + "visibilityKM": 24.135, + "visibilityMI": 15, + "uvi": null, + "solradWM2": 4740, + "solradMinWM2": 0, + "solradMaxWM2": 743, + "isDay": true, + "maxCoverage": "", + "sunrise": 1665546895, + "sunset": 1665588484, + "sunriseISO": "2022-10-12T05:54:55+02:00", + "sunsetISO": "2022-10-12T17:28:04+02:00" + } + ], + "profile": { + "tz": "Africa/Cairo", + "elevM": 23, + "elevFT": 75 + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/Issue593.xml b/src/test/resources/Issue593.xml new file mode 100644 index 000000000..0c6c038b6 --- /dev/null +++ b/src/test/resources/Issue593.xml @@ -0,0 +1,691 @@ +true + + + 31.25 + 30.063 + + + 23 + Africa/Cairo + 75 + + + 2022-10-06T07:00:00+02:00 + E + 95 + 21 + 15 + 10 + 353 + N + 2022-10-06T05:51:14+02:00 + null + 9 + null + 66 + 0 + Mostly Sunny + 2022-10-06T17:35:02+02:00 + 32 + 77 + N + 89 + 0 + 22 + 25 + 25 + Mostly Sunny + 41 + 58 + 41 + 22 + 14 + 0 + 22 + 353 + 16 + 8 + 70 + 2022-10-06T07:00:00+02:00 + 10 + 778 + 25 + 15 + ::FW + 1665028274 + 78 + N + + fair.png + 21 + 17 + FW + 70 + 29 + 63 + 12 + 0 + 0 + NNW + 13 + 22 + 11 + 32 + 1015 + 24.135 + 1665032400 + 90 + null + 11 + 0 + 1 + 343 + 21 + 2 + 63 + 1 + 26 + 6 + NNW + 17 + 29.97 + 80 + null + true + 19 + 52 + 5 + 1665070502 + 5608 + 9 + 25 + 77 + 6 + 40 + 342 + null + + + 2022-10-07T07:00:00+02:00 + NNW + 347 + 19 + 15 + 8 + 325 + NW + 2022-10-07T05:51:50+02:00 + null + 7 + null + 66 + 0 + Mostly Sunny + 2022-10-07T17:33:51+02:00 + 29 + 77 + NNW + 85 + 0 + 30 + 23 + 23 + Mostly Sunny + 37 + 54 + 37 + 20 + 12 + 0 + 20 + 325 + 13 + 6 + 67 + 2022-10-07T07:00:00+02:00 + 6 + 742 + 24 + 10 + ::FW + 1665114710 + 76 + NW + + fair.png + 19 + 15 + FW + 67 + 30 + 60 + 6 + 0 + 0 + WNW + 6 + 10 + 347 + 30 + 1014 + 24.135 + 1665118800 + 86 + null + 10 + 0 + 1 + 316 + 16 + 2 + 60 + 1 + 24 + 6 + NW + 15 + 29.95 + 76 + null + true + 19 + 50 + 1 + 1665156831 + 5486 + 2 + 18 + 77 + 1 + 29 + 298 + null + + + 2022-10-08T07:00:00+02:00 + NW + 309 + 19 + 15 + 8 + 21 + NNE + 2022-10-08T05:52:26+02:00 + null + 7 + null + 66 + 0 + Partly Cloudy + 2022-10-08T17:32:41+02:00 + 30 + 76 + NW + 86 + 0 + 47 + 19 + 19 + Partly Cloudy + 31 + 56 + 31 + 17 + 13 + 0 + 17 + 21 + 13 + 5 + 67 + 2022-10-08T07:00:00+02:00 + 5 + 682 + 25 + 9 + ::SC + 1665201146 + 76 + NNE + + pcloudy.png + 19 + 15 + SC + 67 + 32 + 59 + 5 + 0 + 0 + WNW + 5 + 9 + 309 + 30 + 1014 + 24.135 + 1665205200 + 87 + null + 11 + 0 + 1 + 322 + 17 + 2 + 59 + 1 + 25 + 7 + NW + 15 + 29.94 + 76 + null + true + 19 + 52 + 1 + 1665243161 + 4785 + 2 + 20 + 76 + 1 + 32 + 301 + null + + + 2022-10-09T07:00:00+02:00 + NW + 316 + 20 + 15 + 9 + 356 + N + 2022-10-09T05:53:03+02:00 + null + 8 + null + 67 + 0 + Partly Cloudy + 2022-10-09T17:31:31+02:00 + 30 + 86 + NW + 86 + 0 + 47 + 23 + 23 + Partly Cloudy + 36 + 57 + 36 + 20 + 14 + 0 + 20 + 356 + 14 + 5 + 67 + 2022-10-09T07:00:00+02:00 + 6 + 726 + 25 + 9 + ::SC + 1665287583 + 77 + N + + pcloudy.png + 20 + 17 + SC + 67 + 31 + 63 + 5 + 0 + 0 + NNW + 6 + 9 + 316 + 31 + 1016 + 24.135 + 1665291600 + 87 + null + 11 + 0 + 2 + 354 + 19 + 4 + 63 + 2 + 25 + 7 + N + 17 + 29.99 + 77 + null + true + 19 + 52 + 2 + 1665329491 + 4768 + 4 + 22 + 86 + 2 + 36 + 343 + null + + + 2022-10-10T07:00:00+02:00 + E + 91 + 21 + 15 + 9 + 358 + N + 2022-10-10T05:53:40+02:00 + null + 8 + null + 70 + 0 + Partly Cloudy + 2022-10-10T17:30:21+02:00 + 30 + 75 + N + 86 + 0 + 64 + 22 + 22 + Partly Cloudy + 36 + 58 + 36 + 19 + 14 + 0 + 19 + 358 + 15 + 7 + 69 + 2022-10-10T07:00:00+02:00 + 8 + 597 + 26 + 13 + ::SC + 1665374020 + 78 + N + + pcloudy.png + 21 + 16 + SC + 69 + 35 + 61 + 7 + 0 + 0 + N + 8 + 13 + 8 + 31 + 1017 + 24.135 + 1665378000 + 87 + null + 13 + 0 + 2 + 10 + 16 + 4 + 61 + 2 + 25 + 6 + N + 16 + 30.03 + 78 + null + true + 21 + 55 + 2 + 1665415821 + 4494 + 4 + 19 + 75 + 2 + 30 + 10 + null + + + 2022-10-11T07:00:00+02:00 + NNE + 13 + 22 + 15 + 18 + 13 + NNE + 2022-10-11T05:54:18+02:00 + null + 15 + null + 70 + 0 + Sunny + 2022-10-11T17:29:13+02:00 + 31 + 71 + NNE + 87 + 0 + 0 + 19 + 19 + Sunny + 31 + 55 + 31 + 17 + 13 + 0 + 17 + 14 + 28 + 9 + 72 + 2022-10-11T07:00:00+02:00 + 11 + 758 + 26 + 18 + ::CL + 1665460458 + 78 + NNE + + sunny.png + 22 + 17 + CL + 72 + 30 + 62 + 10 + 0 + 0 + NNE + 12 + 19 + 16 + 31 + 1015 + 24.135 + 1665464400 + 87 + null + 11 + 0 + 7 + 28 + 15 + 14 + 62 + 8 + 26 + null + NNE + 17 + 29.98 + 79 + null + true + 21 + 51 + 8 + 1665502153 + 5450 + 15 + 17 + 71 + 9 + 28 + 28 + null + + + 2022-10-12T07:00:00+02:00 + NNE + 15 + 22 + 15 + 16 + 12 + NNE + 2022-10-12T05:54:55+02:00 + null + 14 + null + 69 + 0 + Mostly Sunny + 2022-10-12T17:28:04+02:00 + 31 + 68 + NNE + 88 + 0 + 27 + 21 + 21 + Mostly Sunny + 33 + 55 + 33 + 18 + 13 + 0 + 18 + 12 + 26 + 10 + 72 + 2022-10-12T07:00:00+02:00 + 11 + 743 + 26 + 18 + ::FW + 1665546895 + 79 + NNE + + fair.png + 22 + 16 + FW + 72 + 29 + 60 + 10 + 0 + 0 + E + 12 + 19 + 15 + 31 + 1014 + 24.135 + 1665550800 + 88 + null + 11 + 0 + 7 + 96 + 15 + 13 + 60 + 8 + 26 + null + E + 16 + 29.95 + 80 + null + true + 21 + 51 + 8 + 1665588484 + 4740 + 15 + 17 + 68 + 9 + 28 + 96 + null + + day + + eg + cairo + qh + + +null