/** * 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 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)); }
System.out.println(); j = JSONML.toJSONObject(s); System.out.println(j.toString()); System.out.println(JSONML.toString(j)); j = JSONML.toJSONObject(s); System.out.println(j.toString(4)); System.out.println(JSONML.toString(j)); j = JSONML.toJSONObject(s); System.out.println(j); ja = JSONML.toJSONArray(s);
System.out.println(); j = JSONML.toJSONObject(s); System.out.println(j.toString()); System.out.println(JSONML.toString(j)); j = JSONML.toJSONObject(s); System.out.println(j.toString(4)); System.out.println(JSONML.toString(j)); j = JSONML.toJSONObject(s); System.out.println(j); ja = JSONML.toJSONArray(s);