Package org.json
Class XMLParserConfiguration
java.lang.Object
org.json.ParserConfiguration
org.json.XMLParserConfiguration
Configuration object for the XML parser. The configuration is immutable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final XMLParserConfigurationOriginal configuration of the XML Parser except that values are kept as strings.static final XMLParserConfigurationOriginal Configuration of the XML Parser.Fields inherited from class org.json.ParserConfiguration
DEFAULT_MAXIMUM_NESTING_DEPTH, keepStrings, maxNestingDepth, UNDEFINED_MAXIMUM_NESTING_DEPTH -
Constructor Summary
ConstructorsConstructorDescriptionDefault parser configuration.XMLParserConfiguration(boolean keepStrings) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration.XMLParserConfiguration(boolean keepStrings, String cDataTagName) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration.XMLParserConfiguration(boolean keepStrings, String cDataTagName, boolean convertNilAttributeToNull) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration.XMLParserConfiguration(String cDataTagName) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected XMLParserConfigurationclone()Provides a new instance of the same configuration.The name of the key in a JSON Object that indicates a CDATA section.When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>to parse the provided tags' values as arraysWhen parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as stringbooleanChecks if the parser should automatically close empty XML tags.booleanWhen parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false), or they should be converted tonull(true)booleanChecks if the parser should trim white spaces from XML content.withcDataTagName(String newVal) The name of the key in a JSON Object that indicates a CDATA section.withCloseEmptyTag(boolean closeEmptyTag) To enable explicit end tag with empty value.withConvertNilAttributeToNull(boolean newVal) When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false), or they should be converted tonull(true)withForceList(Set<String> forceList) When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>to parse the provided tags' values as arrayswithKeepStrings(boolean newVal) When parsing the XML into JSON, specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string)withMaxNestingDepth(int maxNestingDepth) Defines the maximum nesting depth that the parser will descend before throwing an exception when parsing the XML into JSON.withShouldTrimWhitespace(boolean shouldTrimWhiteSpace) Sets whether whitespace should be trimmed inside of tags.withXsiTypeMap(Map<String, XMLXsiTypeConverter<?>> xsiTypeMap) When parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as stringMethods inherited from class org.json.ParserConfiguration
getMaxNestingDepth, isKeepStrings
-
Field Details
-
ORIGINAL
Original Configuration of the XML Parser. -
KEEP_STRINGS
Original configuration of the XML Parser except that values are kept as strings.
-
-
Constructor Details
-
XMLParserConfiguration
public XMLParserConfiguration()Default parser configuration. Does not keep strings (tries to implicitly convert values), and the CDATA Tag Name is "content". Trims whitespace. -
XMLParserConfiguration
Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed in a future release.Configure the parser string processing and use the default CDATA Tag Name as "content".- Parameters:
keepStrings-trueto parse all values as string.falseto try and convert XML string values into a JSON value.
-
XMLParserConfiguration
Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed in a future release.Configure the parser string processing to try and convert XML values to JSON values and use the passed CDATA Tag Name the processing value. Passnullto disable CDATA processing- Parameters:
cDataTagName-nullto disable CDATA processing. Any other value to use that value as the JSONObject key name to process as CDATA.
-
XMLParserConfiguration
Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed in a future release.Configure the parser to use custom settings.- Parameters:
keepStrings-trueto parse all values as string.falseto try and convert XML string values into a JSON value.cDataTagName-nullto disable CDATA processing. Any other value to use that value as the JSONObject key name to process as CDATA.
-
XMLParserConfiguration
@Deprecated public XMLParserConfiguration(boolean keepStrings, String cDataTagName, boolean convertNilAttributeToNull) Deprecated.This constructor has been deprecated in favor of using the new builder pattern for the configuration. This constructor may be removed or marked private in a future release.Configure the parser to use custom settings.- Parameters:
keepStrings-trueto parse all values as string.falseto try and convert XML string values into a JSON value.cDataTagName-nullto disable CDATA processing. Any other value to use that value as the JSONObject key name to process as CDATA.convertNilAttributeToNull-trueto parse values with attribute xsi:nil="true" as null.falseto parse values with attribute xsi:nil="true" as {"xsi:nil":true}.
-
-
Method Details
-
clone
Provides a new instance of the same configuration.- Overrides:
clonein classParserConfiguration
-
withKeepStrings
When parsing the XML into JSON, specifies if values should be kept as strings (true), or if they should try to be guessed into JSON values (numeric, boolean, string)- Overrides:
withKeepStringsin classParserConfiguration- Parameters:
newVal- new value to use for thekeepStringsconfiguration option.- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
getcDataTagName
The name of the key in a JSON Object that indicates a CDATA section. Historically this has been the value "content" but can be changed. Usenullto indicate no CDATA processing.- Returns:
- The
cDataTagNameconfiguration value.
-
withcDataTagName
The name of the key in a JSON Object that indicates a CDATA section. Historically this has been the value "content" but can be changed. Usenullto indicate no CDATA processing.- Parameters:
newVal- new value to use for thecDataTagNameconfiguration option.- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
isConvertNilAttributeToNull
public boolean isConvertNilAttributeToNull()When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false), or they should be converted tonull(true)- Returns:
- The
convertNilAttributeToNullconfiguration value.
-
withConvertNilAttributeToNull
When parsing the XML into JSON, specifies if values with attribute xsi:nil="true" should be kept as attribute(false), or they should be converted tonull(true)- Parameters:
newVal- new value to use for theconvertNilAttributeToNullconfiguration option.- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
getXsiTypeMap
When parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as string- Returns:
xsiTypeMapunmodifiable configuration map.
-
withXsiTypeMap
When parsing the XML into JSON, specifies that the values with attribute xsi:type will be converted to target type defined to client in this configurationMap<String, XMLXsiTypeConverter<?>>to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as string- Parameters:
xsiTypeMap-new HashMap<String, XMLXsiTypeConverter<?>>()to parse values with attribute xsi:type="integer" as integer, xsi:type="string" as string- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
getForceList
When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>to parse the provided tags' values as arrays- Returns:
forceListunmodifiable configuration set.
-
withForceList
When parsing the XML into JSON, specifies that tags that will be converted to arrays in this configurationSet<String>to parse the provided tags' values as arrays- Parameters:
forceList-new HashSet<String>()to parse the provided tags' values as arrays- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
withMaxNestingDepth
Defines the maximum nesting depth that the parser will descend before throwing an exception when parsing the XML into JSON. The default max nesting depth is 512, which means the parser will throw a JsonException if the maximum depth is reached. Using any negative value as a parameter is equivalent to setting no limit to the nesting depth, which means the parses will go as deep as the maximum call stack size allows.- Overrides:
withMaxNestingDepthin classParserConfiguration- Parameters:
maxNestingDepth- the maximum nesting depth allowed to the XML parser- Returns:
- The existing configuration will not be modified. A new configuration is returned.
-
withCloseEmptyTag
To enable explicit end tag with empty value.- Parameters:
closeEmptyTag- new value for the closeEmptyTag property- Returns:
- same instance of configuration with empty tag config updated
-
withShouldTrimWhitespace
Sets whether whitespace should be trimmed inside of tags. *NOTE* Do not use this if you expect your XML tags to have names that are the same as cDataTagName as this is unsupported. cDataTagName should be set to a distinct value in these cases.- Parameters:
shouldTrimWhiteSpace- boolean to set trimming on or off. Off is default.- Returns:
- same instance of configuration with empty tag config updated
-
isCloseEmptyTag
public boolean isCloseEmptyTag()Checks if the parser should automatically close empty XML tags.- Returns:
trueif empty XML tags should be automatically closed,falseotherwise.
-
shouldTrimWhiteSpace
public boolean shouldTrimWhiteSpace()Checks if the parser should trim white spaces from XML content.- Returns:
trueif white spaces should be trimmed,falseotherwise.
-