Java Utililty Methods XML Parse String

List of utility methods to do XML Parse String

Description

The list of methods to do XML Parse String are organized into topic(s).

Method

Documentparse(String xml)
parse
return newBuilder().parse(new InputSource(new StringReader(xml)));
Documentparse(String xml)
Parses a XML document.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(xml)));
removeWhitespaces((Element) document.getChildNodes().item(0));
return document;
Documentparse(String xml)
parse
if ((xml == null) || (xml.length() == 0))
    return null;
try {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    StringReader reader = new StringReader(xml);
    InputSource source = new InputSource(reader);
    source.setEncoding("UTF-8"); 
...
Documentparse(String xml)
Parse a XML document from string
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
return builder.parse(is);
ListparseAccessNumber(String line)
parse Access Number
List<String> result = new ArrayList<String>();
String[] subids = line.split("\\s");
for (String subid : subids) {
    subid = subid.trim();
    if (subid.endsWith(",")) {
        subid = subid.substring(0, subid.length() - 1);
    if (subid.length() > 1) {
...
ArrayListparseAddressLines(String[] addressLines)
parse Address Lines
ArrayList<String> fields = new ArrayList<String>();
for (String addressLine : addressLines) {
    String[] addresses = addressLine.split(",");
    for (String address : addresses) {
        address = address.trim().replaceAll("\t", "").replaceAll("\n", "").replaceAll("\r", "");
        fields.add(address);
return fields;
ListparseArg(String arg)
Given an argument of the form "-option1 AAAAA -option2 -option3 "BBBB" -option4="CCCC" ...", separate each individual argument and return them as a list, if there are double quotes around a value argument they will be removed
ArrayList<String> answer = new ArrayList<String>();
if (arg != null) {
    arg = arg.trim();
    StringBuilder remaining = new StringBuilder(arg);
    while (remaining.length() > 0) {
        if (remaining.charAt(0) == '-') {
            answer.add(readOptionToken(remaining));
        } else {
...
ListparseArgs(String text)
parse Args
List<String> args = new ArrayList<String>();
boolean inQuotes = false;
boolean inEscape = false;
StringBuilder element = new StringBuilder();
char[] charArray = text.toCharArray();
for (int i = 0; i < charArray.length; i++) {
    char c = charArray[i];
    if (c == '"' && !inEscape) {
...
String[]parseArgs(String[] args)
parse Args
ArrayList list = new ArrayList();
for (int i = 0; i < args.length; i++) {
    try {
        repeatCount = Integer.parseInt(args[i]);
    } catch (NumberFormatException e) {
        list.add(args[i]);
return (String[]) list.toArray(new String[list.size()]);
String[]parseArgs(String[] args)
Parses the command line arguments.
List<String> col = new ArrayList<String>();
for (String arg : args) {
    String narg = arg.trim();
    if (narg.contains("=")) {
        for (String n : narg.split("=")) {
            col.add(n);
    } else
...