/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONArray using the JsonML transform. Each XML tag is represented as a * JSONArray in which the first element is the tag name. If the tag has * attributes, then the second element will be JSONObject containing the * name/value pairs. If the tag contains children, then strings and JSONArrays * will represent the child content and tags. Comments, prologs, DTDs, and * <code><[ [ ]]></code> are ignored. * * @param x * An XMLTokener. * @return A JSONArray containing the structured data from the XML string. * @throws JSONException */ public static JSONArray toJSONArray(XMLTokener x) throws JSONException { return (JSONArray) parse(x, true, null); }
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONArray using the JsonML transform. Each XML tag is represented as a * JSONArray in which the first element is the tag name. If the tag has * attributes, then the second element will be JSONObject containing the * name/value pairs. If the tag contains children, then strings and JSONArrays * will represent the child tags. Comments, prologs, DTDs, and * <code><[ [ ]]></code> are ignored. * * @param string * The source string. * @return A JSONArray containing the structured data from the XML string. * @throws JSONException */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new XMLTokener(string)); }
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONObject using the JsonML transform. Each XML tag is represented as a * JSONObject with a "tagName" property. If the tag has attributes, then the * attributes will be in the JSONObject as properties. If the tag contains * children, the object will have a "childNodes" property which will be an * array of strings and JsonML JSONObjects. * * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. * * @param string * The XML source text. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ public static JSONObject toJSONObject(String string) throws JSONException { return toJSONObject(new XMLTokener(string)); }
j = JSONML.toJSONObject(s); System.out.println(j.toString()); System.out.println(JSONML.toString(j)); System.out.println(); a = JSONML.toJSONArray(s); System.out.println(a.toString(4)); System.out.println(JSONML.toString(a)); System.out.println(); j = JSONML.toJSONObject(s); System.out.println(j.toString(4)); System.out.println(JSONML.toString(j)); System.out.println(); a = JSONML.toJSONArray(s); System.out.println(a.toString(4)); System.out.println(JSONML.toString(a)); System.out.println(); ja = JSONML.toJSONArray(s); System.out.println(ja.toString(4)); System.out.println(JSONML.toString(ja)); System.out.println(""); ja = JSONML.toJSONArray(s); System.out.println(ja.toString(4)); System.out.println(JSONML.toString(ja)); System.out.println("");
j = JSONML.toJSONObject(s); System.out.println(j.toString()); System.out.println(JSONML.toString(j)); System.out.println(); a = JSONML.toJSONArray(s); System.out.println(a.toString(4)); System.out.println(JSONML.toString(a)); System.out.println(); j = JSONML.toJSONObject(s); System.out.println(j.toString(4)); System.out.println(JSONML.toString(j)); System.out.println(); a = JSONML.toJSONArray(s); System.out.println(a.toString(4)); System.out.println(JSONML.toString(a)); System.out.println(); ja = JSONML.toJSONArray(s); System.out.println(ja.toString(4)); System.out.println(JSONML.toString(ja)); System.out.println(""); ja = JSONML.toJSONArray(s); System.out.println(ja.toString(4)); System.out.println(JSONML.toString(ja)); System.out.println("");
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONObject using the JsonML transform. Each XML tag is represented as a * JSONObject with a "tagName" property. If the tag has attributes, then the * attributes will be in the JSONObject as properties. If the tag contains * children, the object will have a "childNodes" property which will be an * array of strings and JsonML JSONObjects. * * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. * * @param x * An XMLTokener of the XML source text. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ public static JSONObject toJSONObject(XMLTokener x) throws JSONException { return (JSONObject) parse(x, false, null); }
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONArray using the JsonML transform. Each XML tag is represented as a * JSONArray in which the first element is the tag name. If the tag has * attributes, then the second element will be JSONObject containing the * name/value pairs. If the tag contains children, then strings and JSONArrays * will represent the child tags. Comments, prologs, DTDs, and * <code><[ [ ]]></code> are ignored. * * @param string * The source string. * @return A JSONArray containing the structured data from the XML string. * @throws JSONException */ public static JSONArray toJSONArray(String string) throws JSONException { return toJSONArray(new XMLTokener(string)); }
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONObject using the JsonML transform. Each XML tag is represented as a * JSONObject with a "tagName" property. If the tag has attributes, then the * attributes will be in the JSONObject as properties. If the tag contains * children, the object will have a "childNodes" property which will be an * array of strings and JsonML JSONObjects. * * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. * * @param string * The XML source text. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ public static JSONObject toJSONObject(String string) throws JSONException { return toJSONObject(new XMLTokener(string)); }
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONObject using the JsonML transform. Each XML tag is represented as a * JSONObject with a "tagName" property. If the tag has attributes, then the * attributes will be in the JSONObject as properties. If the tag contains * children, the object will have a "childNodes" property which will be an * array of strings and JsonML JSONObjects. * * Comments, prologs, DTDs, and <code><[ [ ]]></code> are ignored. * * @param x * An XMLTokener of the XML source text. * @return A JSONObject containing the structured data from the XML string. * @throws JSONException */ public static JSONObject toJSONObject(XMLTokener x) throws JSONException { return (JSONObject) parse(x, false, null); }
/** * Convert a well-formed (but not necessarily valid) XML string into a * JSONArray using the JsonML transform. Each XML tag is represented as a * JSONArray in which the first element is the tag name. If the tag has * attributes, then the second element will be JSONObject containing the * name/value pairs. If the tag contains children, then strings and JSONArrays * will represent the child content and tags. Comments, prologs, DTDs, and * <code><[ [ ]]></code> are ignored. * * @param x * An XMLTokener. * @return A JSONArray containing the structured data from the XML string. * @throws JSONException */ public static JSONArray toJSONArray(XMLTokener x) throws JSONException { return (JSONArray) parse(x, true, null); }
throw x.syntaxError("Misshaped tag"); closeTag = (String) parse(x, arrayForm, newja); if (closeTag != null) { if (!closeTag.equals(tagName)) {
throw x.syntaxError("Misshaped tag"); closeTag = (String) parse(x, arrayForm, newja); if (closeTag != null) { if (!closeTag.equals(tagName)) {