Example usage for org.w3c.dom.html HTMLDocument appendChild

List of usage examples for org.w3c.dom.html HTMLDocument appendChild

Introduction

In this page you can find the example usage for org.w3c.dom.html HTMLDocument appendChild.

Prototype

public Node appendChild(Node newChild) throws DOMException;

Source Link

Document

Adds the node newChild to the end of the list of children of this node.

Usage

From source file:de.innovationgate.wga.server.api.Html.java

/**
 * Parses HTML text and returns it as DOM document object. The returned document represents only the parsed fragment.
 * The HTML parser NekoHTML is responsible for parsing the HTML document as a DOM tree. It is tolerant against most "common errors" done on HTML documents and may parse a wide range of HTML structures. 
 * Note: NekoHTML converts all HTML tags name to uppercase even if they were specified as lowercase in the source code. This is important when querying the DOM via XPath.
 * @param html/*from   ww  w. j  a  v  a2  s  . c o m*/
 * @return The DOM document of the parsed HTML
 * @throws SAXException
 * @throws IOException
 */
public Document parseFragment(String html) throws WGException, SAXException, IOException {

    HTMLDocument document = new HTMLDocumentImpl();
    DOMFragmentParser parser = new DOMFragmentParser();
    DocumentFragment frag = document.createDocumentFragment();
    parser.parse(new InputSource(new StringReader(html)), frag);
    document.appendChild(frag);
    DOMReader xmlReader = new DOMReader();
    return xmlReader.read(document);

}