Search in sources :

Example 51 with Text

use of org.w3c.dom.Text in project jabref by JabRef.

the class OpenDocumentRepresentation method addTableCell.

private void addTableCell(Document doc, Element parent, String content) {
    Element cell = doc.createElement("table:table-cell");
    Element text = doc.createElement("text:p");
    Text textNode = doc.createTextNode(content);
    text.appendChild(textNode);
    //text.setTextContent(content);
    cell.appendChild(text);
    parent.appendChild(cell);
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Example 52 with Text

use of org.w3c.dom.Text in project JMRI by JMRI.

the class XMLUtil method normalize.

/**
     * Try to normalize a document by removing nonsignificant whitespace.
     *
     * @see "#62006"
     */
private static Document normalize(Document orig) throws IOException {
    DocumentBuilder builder = null;
    DocumentBuilderFactory factory = getFactory(false, false);
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        //NOI18N
        throw new IOException("Cannot create parser satisfying configuration parameters: " + e, e);
    }
    DocumentType doctype = null;
    NodeList nl = orig.getChildNodes();
    for (int i = 0; i < nl.getLength(); i++) {
        if (nl.item(i) instanceof DocumentType) {
            // We cannot import DocumentType's, so we need to manually copy it.
            doctype = (DocumentType) nl.item(i);
        }
    }
    Document doc;
    if (doctype != null) {
        doc = builder.getDOMImplementation().createDocument(orig.getDocumentElement().getNamespaceURI(), orig.getDocumentElement().getTagName(), builder.getDOMImplementation().createDocumentType(orig.getDoctype().getName(), orig.getDoctype().getPublicId(), orig.getDoctype().getSystemId()));
        // XXX what about entity decls inside the DOCTYPE?
        doc.removeChild(doc.getDocumentElement());
    } else {
        doc = builder.newDocument();
    }
    for (int i = 0; i < nl.getLength(); i++) {
        Node node = nl.item(i);
        if (!(node instanceof DocumentType)) {
            try {
                doc.appendChild(doc.importNode(node, true));
            } catch (DOMException x) {
                // Thrown in NB-Core-Build #2896 & 2898 inside GeneratedFilesHelper.applyBuildExtensions
                throw new IOException("Could not import or append " + node + " of " + node.getClass(), x);
            }
        }
    }
    doc.normalize();
    // NOI18N
    nl = doc.getElementsByTagName("*");
    for (int i = 0; i < nl.getLength(); i++) {
        Element e = (Element) nl.item(i);
        removeXmlBase(e);
        NodeList nl2 = e.getChildNodes();
        for (int j = 0; j < nl2.getLength(); j++) {
            Node n = nl2.item(j);
            if (n instanceof Text && ((Text) n).getNodeValue().trim().length() == 0) {
                e.removeChild(n);
                // since list is dynamic
                j--;
            }
        }
    }
    return doc;
}
Also used : DOMException(org.w3c.dom.DOMException) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) DocumentType(org.w3c.dom.DocumentType) Text(org.w3c.dom.Text) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document)

Example 53 with Text

use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.

the class XMLUtils method selectNodeText.

/**
     * @param sibling
     * @param uri
     * @param nodeName
     * @param number
     * @return nodes with the constrain
     */
public static Text selectNodeText(Node sibling, String uri, String nodeName, int number) {
    Node n = selectNode(sibling, uri, nodeName, number);
    if (n == null) {
        return null;
    }
    n = n.getFirstChild();
    while (n != null && n.getNodeType() != Node.TEXT_NODE) {
        n = n.getNextSibling();
    }
    return (Text) n;
}
Also used : Node(org.w3c.dom.Node) Text(org.w3c.dom.Text)

Example 54 with Text

use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.

the class ElementProxy method addText.

/**
     * Method addText
     *
     * @param text
     */
public void addText(String text) {
    if (text != null) {
        Text t = this.doc.createTextNode(text);
        this.constructionElement.appendChild(t);
    }
}
Also used : Text(org.w3c.dom.Text)

Example 55 with Text

use of org.w3c.dom.Text in project jdk8u_jdk by JetBrains.

the class Base64 method encodeToElement.

/**
     * Method encodeToElement
     *
     * @param doc
     * @param localName
     * @param bytes
     * @return an Element with the base64 encoded in the text.
     *
     */
public static final Element encodeToElement(Document doc, String localName, byte[] bytes) {
    Element el = XMLUtils.createElementInSignatureSpace(doc, localName);
    Text text = doc.createTextNode(encode(bytes));
    el.appendChild(text);
    return el;
}
Also used : Element(org.w3c.dom.Element) Text(org.w3c.dom.Text)

Aggregations

Text (org.w3c.dom.Text)166 Element (org.w3c.dom.Element)93 Document (org.w3c.dom.Document)64 Node (org.w3c.dom.Node)58 NodeList (org.w3c.dom.NodeList)35 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)23 DocumentBuilder (javax.xml.parsers.DocumentBuilder)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)17 IOException (java.io.IOException)14 Attr (org.w3c.dom.Attr)14 InputSource (org.xml.sax.InputSource)11 StringReader (java.io.StringReader)10 SAXException (org.xml.sax.SAXException)8 ArrayList (java.util.ArrayList)7 DOMException (org.w3c.dom.DOMException)7 Test (org.junit.Test)6 DOMSource (javax.xml.transform.dom.DOMSource)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)5 HashMap (java.util.HashMap)4 DocumentFragment (org.w3c.dom.DocumentFragment)4