Package org.opencms.json
Class JSONML
java.lang.Object
org.opencms.json.JSONML
This provides static methods to convert an XML text into a JSONObject,
and to convert a JSONObject into an XML text using the JsonML transform.
-
Method Summary
Modifier and TypeMethodDescriptionstatic JSONArraytoJSONArray(String string) Convert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform.static JSONArrayConvert a well-formed (but not necessarily valid) XML string into a JSONArray using the JsonML transform.static StringReverse the JSONML transformation, making an XML text from a JSONArray.
-
Method Details
-
toJSONArray
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
<[ [ ]]>are ignored.- Parameters:
string- the source string- Returns:
- a JSONArray containing the structured data from the XML string.
- Throws:
JSONException- if something goes wrong
-
toJSONArray
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
<[ [ ]]>are ignored.- Parameters:
x- an XMLTokener- Returns:
- a JSONArray containing the structured data from the XML string
- Throws:
JSONException- if something goes wrong
-
toString
Reverse the JSONML transformation, making an XML text from a JSONArray.- Parameters:
ja- a JSONArray- Returns:
- an XML string
- Throws:
JSONException- if something goes wrong
-