Search in sources :

Example 1 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project jOOQ by jOOQ.

the class XMLasDOMBinding method fromString.

/**
     * Create a new DOM element in an independent document
     */
public static Document fromString(String name) {
    Document document = builder().newDocument();
    DocumentFragment fragment = createContent(document, name);
    if (fragment != null) {
        document.appendChild(fragment);
    } else {
        document.appendChild(document.createElement(name));
    }
    return document;
}
Also used : Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 2 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project robovm by robovm.

the class ImportNode method testImportNode8.

// Assumes validation.
//    public void testImportNode7() throws Throwable {
//        Document doc;
//        Document aNewDoc;
//        Element element;
//        Node aNode;
//        NamedNodeMap attributes;
//        String name;
//        Node attr;
//        String lname;
//        String namespaceURI = "http://www.nist.gov";
//        String qualifiedName = "emp:employee";
//        doc = (Document) load("staffNS", builder);
//        aNewDoc = (Document) load("staff", builder);
//        element = aNewDoc.createElementNS(namespaceURI, qualifiedName);
//        aNode = doc.importNode(element, false);
//        attributes = aNode.getAttributes();
//        assertEquals("throw_Size", 1, attributes.getLength());
//        name = aNode.getNodeName();
//        assertEquals("nodeName", "emp:employee", name);
//        attr = attributes.item(0);
//        lname = attr.getLocalName();
//        assertEquals("lname", "defaultAttr", lname);
//    }
public void testImportNode8() throws Throwable {
    Document doc;
    Document aNewDoc;
    DocumentFragment docFrag;
    Node aNode;
    boolean hasChild;
    Document ownerDocument;
    DocumentType docType;
    String system;
    doc = (Document) load("staffNS", builder);
    aNewDoc = (Document) load("staffNS", builder);
    docFrag = aNewDoc.createDocumentFragment();
    aNode = doc.importNode(docFrag, false);
    hasChild = aNode.hasChildNodes();
    assertFalse("hasChild", hasChild);
    ownerDocument = aNode.getOwnerDocument();
    docType = ownerDocument.getDoctype();
    system = docType.getSystemId();
    assertURIEquals("system", null, null, null, "staffNS.dtd", null, null, null, null, system);
}
Also used : Node(org.w3c.dom.Node) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 3 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project robovm by robovm.

the class NodeSetPrefix method testSetPrefix1.

/**
     * Runs the test case.
     *
     * @throws Throwable
     *             Any uncaught exception causes test to fail
     */
public void testSetPrefix1() throws Throwable {
    Document doc;
    DocumentFragment docFragment;
    Element element;
    String elementTagName;
    String elementNodeName;
    doc = (Document) load("staff", builder);
    docFragment = doc.createDocumentFragment();
    element = doc.createElementNS("http://www.w3.org/DOM/Test", "emp:address");
    docFragment.appendChild(element);
    element.setPrefix("dmstc");
    elementTagName = element.getTagName();
    elementNodeName = element.getNodeName();
    assertEquals("nodesetprefix01_tagname", "dmstc:address", elementTagName);
    assertEquals("nodesetprefix01_nodeName", "dmstc:address", elementNodeName);
}
Also used : Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) DocumentFragment(org.w3c.dom.DocumentFragment)

Example 4 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project translationstudio8 by heartsome.

the class MessageParser method htmlToText.

/**
	 * 将 html 格式的文本过滤掉标签.
	 * @param html
	 *            html 格式的字符串
	 * @return String
	 * 			  过滤掉 html 标签后的文本。如果 html 为空,返回空串""
	 */
private String htmlToText(String html) {
    if (html == null) {
        return "";
    }
    DOMFragmentParser parser = new DOMFragmentParser();
    CoreDocumentImpl codeDoc = new CoreDocumentImpl();
    InputSource inSource = new InputSource(new ByteArrayInputStream(html.getBytes()));
    inSource.setEncoding(textCharset);
    DocumentFragment doc = codeDoc.createDocumentFragment();
    try {
        parser.parse(inSource, doc);
    } catch (Exception e) {
        return "";
    }
    textBuffer = new StringBuffer();
    processNode(doc);
    return textBuffer.toString();
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) CoreDocumentImpl(org.apache.xerces.dom.CoreDocumentImpl) DOMFragmentParser(org.cyberneko.html.parsers.DOMFragmentParser) DocumentFragment(org.w3c.dom.DocumentFragment) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with DocumentFragment

use of org.w3c.dom.DocumentFragment in project XobotOS by xamarin.

the class InnerNodeImpl method insertChildAt.

/**
     * Inserts {@code newChild} at {@code index}. If it is already child of
     * another node, it is removed from there.
     */
Node insertChildAt(Node newChild, int index) throws DOMException {
    if (newChild instanceof DocumentFragment) {
        NodeList toAdd = newChild.getChildNodes();
        for (int i = 0; i < toAdd.getLength(); i++) {
            insertChildAt(toAdd.item(i), index + i);
        }
        return newChild;
    }
    LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
    if (toInsert.document != null && document != null && toInsert.document != document) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
    }
    if (toInsert.isParentOf(this)) {
        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
    }
    if (toInsert.parent != null) {
        int oldIndex = toInsert.index;
        toInsert.parent.children.remove(oldIndex);
        toInsert.parent.refreshIndices(oldIndex);
    }
    children.add(index, toInsert);
    toInsert.parent = this;
    refreshIndices(index);
    return newChild;
}
Also used : DOMException(org.w3c.dom.DOMException) NodeList(org.w3c.dom.NodeList) DocumentFragment(org.w3c.dom.DocumentFragment)

Aggregations

DocumentFragment (org.w3c.dom.DocumentFragment)32 Document (org.w3c.dom.Document)20 NodeList (org.w3c.dom.NodeList)17 Node (org.w3c.dom.Node)13 Element (org.w3c.dom.Element)10 Text (org.w3c.dom.Text)4 IOException (java.io.IOException)3 LinkedHashMap (java.util.LinkedHashMap)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DOMException (org.w3c.dom.DOMException)3 HashMap (java.util.HashMap)2 DTM (org.apache.xml.dtm.DTM)2 NodeSetDTM (org.apache.xpath.NodeSetDTM)2 InputSource (org.xml.sax.InputSource)2 SAXException (org.xml.sax.SAXException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 MessagingException (javax.mail.MessagingException)1