Java XML Document Create getDocument(String xmlDocument)

Here you can find the source of getDocument(String xmlDocument)

Description

get Document

License

Apache License

Declaration

public static Document getDocument(String xmlDocument) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;

public class Main {
    public static Document getDocument(String xmlDocument) {
        try {//w  w w.j  av a  2 s .  co  m
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new ByteArrayInputStream(xmlDocument.getBytes("UTF-8")));
        } catch (Exception e) {
            throw new RuntimeException("Error parsing XML document", e);
        }
    }
}

Related

  1. getDocument(String fileName)
  2. getDocument(String filePath)
  3. getDocument(String payload)
  4. getDocument(String xml)
  5. getDocument(String xml)
  6. getDocument(String xslName)
  7. getDocument(URL location, boolean validating, boolean namespaceAware)
  8. getNewDocument()
  9. getNewDocument()