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

DocumentparseXml(Object obj)
parse Xml
if (domBuilderFactory == null) {
    domBuilderFactory = javax.xml.parsers.DocumentBuilderFactory.newInstance();
DocumentBuilder parser = domBuilderFactory.newDocumentBuilder();
Document doc = null;
if (obj instanceof String) {
    try {
        new URL(obj.toString());
...
DocumentparseXML(String path)
Parse XML file to Document model
try {
    DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    dbfac.setNamespaceAware(true);
    DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
    return docBuilder.parse(new File(path));
} catch (Exception e) {
    e.printStackTrace();
    return null;
...
DocumentparseXML(String pathToMap)
Given a path to an XML instance parse it into a Document.
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
domFactory.setValidating(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
builder.setErrorHandler(new ErrorHandler() {
    @Override
    public void error(SAXParseException exception) throws SAXException {
        throw exception;
    @Override
    public void fatalError(SAXParseException exception) throws SAXException {
        throw exception;
    @Override
    public void warning(SAXParseException exception) throws SAXException {
        throw exception;
});
return builder.parse(pathToMap);
StringparseXML(String resp, String name)
parse XML
String value = null;
try {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(resp)));
    doc.getDocumentElement().normalize();
    NodeList listOfProperties = doc.getElementsByTagName("ConfigCategory");
    for (int i = 0; i < listOfProperties.getLength(); i++) {
...
NodeparseXML(String text)
parse XML
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = dbf.newDocumentBuilder();
InputSource source = new InputSource(new StringReader(text));
Document doc = parser.parse(source);
if (doc == null) {
    throw new NullPointerException();
return doc.getFirstChild();
...
DocumentparseXml(String uri)
parse Xml
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(uri);
} catch (Exception e) {
    e.printStackTrace();
    return null;
DocumentparseXml(String xml)
parse Xml
try {
    DocumentBuilder dBuilder = getDocumentBuilder();
    return dBuilder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
} catch (Exception e) {
    throw new RuntimeException(e);
DocumentparseXML(String xml)
Parses the XML passed in as an argument and returns a Document object that represents the parsed XML
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document domDoc = db.parse(new ByteArrayInputStream(xml.getBytes()));
    domDoc.normalize();
    return domDoc;
} catch (ParserConfigurationException e) {
    e.printStackTrace();
...
DocumentparseXML(String xml)
parse XML
return DocumentBuilderFactory.newInstance().newDocumentBuilder()
        .parse(new InputSource(new StringReader(xml)));
DocumentparseXml(String xml)
parse Xml
try {
    final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    final StringReader reader = new StringReader(xml);
    final InputSource inputSource = new InputSource(reader);
    return documentBuilder.parse(inputSource);
} catch (IOException ioe) {
    log.severe("I/O Error while parsing XML: " + ioe.getMessage());
...