Java XML DOM Parse parseDom(Reader reader)

Here you can find the source of parseDom(Reader reader)

Description

Creates a DOM from a file representation of an xml record

License

Apache License

Parameter

Parameter Description
reader the xml reader

Return

the DOM document

Declaration

public static Document parseDom(Reader reader) 

Method Source Code

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

import java.io.Reader;

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

import org.w3c.dom.Document;

public class Main {
    /**// w w w  . jav  a 2s.c  o  m
     * Document builder factory
     */
    private static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    /**
     * Creates a DOM from a file representation of an xml record
     *
     * @param reader the xml reader
     * @return the DOM document
     */
    public static Document parseDom(Reader reader) {
        try {
            DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(new org.xml.sax.InputSource(reader));
        } catch (Exception e) {
            throw new RuntimeException("Could not parse DOM for '" + reader.toString() + "'!", e);
        }
    }
}

Related

  1. parse_XML_String_and_create_DOM(String xmlData)
  2. parseDom(InputStream byteArrayInputStream)
  3. parseDOMConfigFile(String folderPath, String configFileName)
  4. parseDomFromFile(File doc)
  5. parseFileToXML(Transformer transformer, DOMSource source, File file)
  6. parseToDOM(InputStream stream)