-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of XMLParserConfig object for more flexible XM…
…L parsing
- Loading branch information
John J. Aylward
committed
Mar 22, 2018
1 parent
06e9ad2
commit 5fe48ef
Showing
2 changed files
with
145 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.json; | ||
/** | ||
* Configuration object for the XML parser. | ||
* @author AylwardJ | ||
* | ||
*/ | ||
public class XMLParserConfiguration { | ||
public static final XMLParserConfiguration ORIGINAL = new XMLParserConfiguration(); | ||
public static final XMLParserConfiguration KEEP_STRINGS = new XMLParserConfiguration(true); | ||
/** | ||
* 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) | ||
*/ | ||
public final boolean keepStrings; | ||
/** | ||
* The name of the key in a JSON Ojbect that indicates a CDATA section. Historically this has | ||
* been the value "content" but can be changed. Use <code>null</code> to indicate no CDATA | ||
* processing. | ||
*/ | ||
public final String cDataTagName; | ||
|
||
/** | ||
* Default parser configuration. Does not keep strings, and the CDATA Tag Name is "content". | ||
*/ | ||
public XMLParserConfiguration () { | ||
this(false, "content"); | ||
} | ||
|
||
/** | ||
* Configure the parser string processing and use the default CDATA Tag Name as "content". | ||
* @param keepStrings <code>true</code> to parse all values as string. | ||
* <code>false</code> to try and convert XML string values into a JSON value. | ||
*/ | ||
public XMLParserConfiguration (final boolean keepStrings) { | ||
this(keepStrings, "content"); | ||
} | ||
|
||
/** | ||
* Configure the parser string processing to try and convert XML values to JSON values and | ||
* use the passed CDATA Tag Name the processing value. Pass <code>null</code> to | ||
* disable CDATA processing | ||
* @param cDataTagName<code>null</code> to disable CDATA processing. Any other value | ||
* to use that value as the JSONObject key name to process as CDATA. | ||
*/ | ||
public XMLParserConfiguration (final String cDataTagName) { | ||
this(false, cDataTagName); | ||
} | ||
|
||
/** | ||
* Configure the parser to use custom settings. | ||
* @param keepStrings <code>true</code> to parse all values as string. | ||
* <code>false</code> to try and convert XML string values into a JSON value. | ||
* @param cDataTagName<code>null</code> to disable CDATA processing. Any other value | ||
* to use that value as the JSONObject key name to process as CDATA. | ||
*/ | ||
public XMLParserConfiguration (final boolean keepStrings, final String cDataTagName) { | ||
this.keepStrings = keepStrings; | ||
this.cDataTagName = cDataTagName; | ||
} | ||
} |