Package com.x2j.converter
Class XMLToJSONConverter
java.lang.Object
com.x2j.converter.XMLToJSONConverter
The class XMLToJSONConverter is the starting point.
This exposes various methods for the XML to JSON conversion.
It accepts the input XML and the schema JSON as String or as a File object.
Before initiating the conversion logic, this class tries to figure out the JSON schema, if not explicitly passed as argument.
If the JSON schema is not found, the default conversion logic will be applied.
This exposes various methods for the XML to JSON conversion.
It accepts the input XML and the schema JSON as String or as a File object.
Before initiating the conversion logic, this class tries to figure out the JSON schema, if not explicitly passed as argument.
If the JSON schema is not found, the default conversion logic will be applied.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionorg.json.JSONObject
convertToJson
(File inputXmlFile) Convert XML to JSON.org.json.JSONObject
convertToJson
(File inputXmlFile, File jsonSchemaFile) Convert XML to JSON.org.json.JSONObject
convertToJson
(File inputXmlFile, String jsonSchema) Convert XML to JSON.org.json.JSONObject
convertToJson
(File inputXmlFile, org.json.JSONObject jsonSchemaObj) Convert XML to JSON.org.json.JSONObject
convertToJson
(String inputXml) Convert XML to JSON.org.json.JSONObject
convertToJson
(String inputXml, String jsonSchema) Convert XML to JSON.org.json.JSONObject
convertToJson
(String inputXml, org.json.JSONObject jsonSchemaObj) Convert XML to JSON.org.json.JSONObject
convertToJson
(Document inDoc) Convert XML to JSON.org.json.JSONObject
convertToJson
(Document inDoc, String jsonSchema) Convert XML to JSON.org.json.JSONObject
convertToJson
(Document inDoc, org.json.JSONObject jsonSchemaObj) Convert XML to JSON.
-
Constructor Details
-
XMLToJSONConverter
public XMLToJSONConverter()
-
-
Method Details
-
convertToJson
Convert XML to JSON. The schema should be part of the XML element.
If the schema definition is present as a child of the root element, under the tag JSONSchema, then that schema definition will be considered for conversion.
Otherwise, the default conversion logic will be applied.- Parameters:
inDoc
- the input XML document- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
Convert XML to JSON. The schema is explicitly passed as a String argument.
The default conversion logic will only get applied when the schema string is null or empty.- Parameters:
inDoc
- the input XML documentjsonSchema
- the JSON schema object- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
public org.json.JSONObject convertToJson(Document inDoc, org.json.JSONObject jsonSchemaObj) throws X2JException Convert XML to JSON. The schema is explicitly passed as a JSONObject argument.
The default conversion logic will only get applied when the schema is null.- Parameters:
inDoc
- the input XML documentjsonSchemaObj
- the JSON schema object- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
Convert XML to JSON. The schema should be part of the XML element.
The input XML is stored in a file and the corresponding File object is passed as an argument to this method.
If the schema definition is present as a child of the root element, under the tag JSONSchema, then that schema definition will be considered for conversion.
Otherwise, the default conversion logic will be applied.- Parameters:
inputXmlFile
- the input XML file- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
Convert XML to JSON. The schema is explicitly passed as a String argument.
The input XML is stored in a file and the corresponding File object is passed as an argument to this method.
The default conversion logic will only get applied when the schema string is null or empty.- Parameters:
inputXmlFile
- the input XML filejsonSchema
- the JSON schema- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
public org.json.JSONObject convertToJson(File inputXmlFile, org.json.JSONObject jsonSchemaObj) throws X2JException Convert XML to JSON. The schema is explicitly passed as a JSONObject argument.
The input XML is stored in a file and the corresponding File object is passed as an argument to this method.
The default conversion logic will only get applied when the schema is null.- Parameters:
inputXmlFile
- the input XML filejsonSchemaObj
- the JSON schema- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
Convert XML to JSON. The schema should be part of the XML element.
The input XML is a String and is passed as an argument to this method.
If the schema definition is present as a child of the root element, under the tag JSONSchema, then that schema definition will be considered for conversion.
Otherwise, the default conversion logic will be applied.- Parameters:
inputXml
- the input XML String- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
Convert XML to JSON. The schema is explicitly passed as a String argument.
The input XML is a String as well which is passed as an argument to this method.
The default conversion logic will only get applied when the schema string is null or empty.- Parameters:
inputXml
- the input XML StringjsonSchema
- the JSON schema- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
public org.json.JSONObject convertToJson(String inputXml, org.json.JSONObject jsonSchemaObj) throws X2JException Convert XML to JSON. The schema is explicitly passed as a JSONObject argument.
The input XML is a String and is passed as an argument to this method.
The default conversion logic will only get applied when the schema is null.- Parameters:
inputXml
- the input XML StringjsonSchemaObj
- the JSON schema- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-
convertToJson
public org.json.JSONObject convertToJson(File inputXmlFile, File jsonSchemaFile) throws X2JException Convert XML to JSON. The schema is explicitly passed as a JSONObject argument.
The input XML and the schema JSON are stored in 2 separate files and the corresponding File objects are passed as arguments to this method.
The default conversion logic will only get applied when the schema is null.- Parameters:
inputXmlFile
- the input XML filejsonSchemaFile
- the JSON schema file- Returns:
- the converted JSON object
- Throws:
X2JException
- if there is any error during the conversion process.
-