Search in sources :

Example 1 with CharacterData

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

the class Normalize method testNormalize.

/**
    * Runs the test case.
    * @throws Throwable Any uncaught exception causes test to fail
    */
public void testNormalize() throws Throwable {
    Document doc;
    Element root;
    NodeList elementList;
    Node firstChild;
    NodeList textList;
    CharacterData textNode;
    String data;
    doc = (Document) load("staff", builder);
    root = doc.getDocumentElement();
    root.normalize();
    elementList = root.getElementsByTagName("name");
    firstChild = elementList.item(2);
    textList = firstChild.getChildNodes();
    textNode = (CharacterData) textList.item(0);
    data = textNode.getData();
    assertEquals("data", "Roger\n Jones", data);
}
Also used : CharacterData(org.w3c.dom.CharacterData) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document)

Example 2 with CharacterData

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

the class CitationStyle method createCitationStyleFromSource.

/**
     * Creates an CitationStyle instance out of the style string
     */
private static CitationStyle createCitationStyleFromSource(final String source, final String filename) {
    try {
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(source));
        Document doc = db.parse(is);
        NodeList nodes = doc.getElementsByTagName("info");
        NodeList titleNode = ((Element) nodes.item(0)).getElementsByTagName("title");
        String title = ((CharacterData) titleNode.item(0).getFirstChild()).getData();
        return new CitationStyle(filename, title, source);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        LOGGER.error("Error while parsing source", e);
    }
    return null;
}
Also used : InputSource(org.xml.sax.InputSource) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) CharacterData(org.w3c.dom.CharacterData) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with CharacterData

use of org.w3c.dom.CharacterData in project webtools.sourceediting by eclipse.

the class TextTest2 method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        Element a = document.createElement("a");
        document.appendChild(a);
        CharacterData text = document.createTextNode("text");
        a.appendChild(text);
        text.setNodeValue("hello <");
        printSource(model);
        printTree(model);
        fOutputWriter.writeln(text.getNodeValue());
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : CharacterData(org.w3c.dom.CharacterData) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 4 with CharacterData

use of org.w3c.dom.CharacterData in project webtools.sourceediting by eclipse.

the class TextTest method testModel.

public void testModel() {
    IDOMModel model = createXMLModel();
    try {
        Document document = model.getDocument();
        Element a = document.createElement("a");
        document.appendChild(a);
        CharacterData text = document.createTextNode("text");
        a.appendChild(text);
        text.setData("hello <");
        printSource(model);
        printTree(model);
        fOutputWriter.writeln(text.getData());
        saveAndCompareTestResults();
    } finally {
        model.releaseFromEdit();
    }
}
Also used : CharacterData(org.w3c.dom.CharacterData) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 5 with CharacterData

use of org.w3c.dom.CharacterData in project aries by apache.

the class SpringOsgiNamespaceHandler method getTextValue.

public static String getTextValue(Element valueEle) {
    Assert.notNull(valueEle, "Element must not be null");
    StringBuilder sb = new StringBuilder();
    NodeList nl = valueEle.getChildNodes();
    for (int i = 0, l = nl.getLength(); i < l; ++i) {
        Node item = nl.item(i);
        if (item instanceof CharacterData && !(item instanceof Comment) || item instanceof EntityReference) {
            sb.append(item.getNodeValue());
        }
    }
    return sb.toString();
}
Also used : Comment(org.w3c.dom.Comment) CharacterData(org.w3c.dom.CharacterData) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) EntityReference(org.w3c.dom.EntityReference)

Aggregations

CharacterData (org.w3c.dom.CharacterData)21 Node (org.w3c.dom.Node)15 NodeList (org.w3c.dom.NodeList)15 Comment (org.w3c.dom.Comment)10 EntityReference (org.w3c.dom.EntityReference)10 Element (org.w3c.dom.Element)8 Document (org.w3c.dom.Document)5 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 org.apache.aries.blueprint (org.apache.aries.blueprint)1 SVGStylableElement (org.apache.batik.anim.dom.SVGStylableElement)1 GenericCDATASection (org.apache.batik.dom.GenericCDATASection)1 GenericText (org.apache.batik.dom.GenericText)1 Attr (org.w3c.dom.Attr)1