Search in sources :

Example 16 with ProcessingInstruction

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

the class SimpleBuilderTest method testGoodFile1.

public void testGoodFile1() throws Exception {
    Document document = builder.parse(getClass().getResourceAsStream("/SimpleBuilderTest.xml"));
    Element root = document.getDocumentElement();
    assertNotNull(root);
    assertEquals("http://www.foo.bar", root.getNamespaceURI());
    assertEquals("t", root.getPrefix());
    assertEquals("stuff", root.getLocalName());
    NodeList list = root.getElementsByTagName("nestedStuff");
    assertNotNull(list);
    assertEquals(list.getLength(), 4);
    Element one = (Element) list.item(0);
    Element two = (Element) list.item(1);
    Element three = (Element) list.item(2);
    Element four = (Element) list.item(3);
    assertEquals("This space intentionally left blank.", getTextContent(one));
    assertEquals("Nothing to see here - please get along!", getTextContent(two));
    assertEquals("Rent this space!", getTextContent(three));
    assertEquals("", getTextContent(four));
    assertEquals("eins", one.getAttribute("one"));
    assertEquals("zwei", two.getAttribute("two"));
    assertEquals("drei", three.getAttribute("three"));
    assertEquals("vier", four.getAttribute("t:four"));
    assertEquals("vier", four.getAttributeNS("http://www.foo.bar", "four"));
    list = document.getChildNodes();
    assertNotNull(list);
    String proinst = "";
    String comment = "";
    for (int i = 0; i < list.getLength(); i++) {
        Node node = list.item(i);
        if (node instanceof ProcessingInstruction) {
            proinst = proinst + node.getNodeValue();
        } else if (node instanceof Comment) {
            comment = comment + node.getNodeValue();
        }
    }
    assertEquals("The quick brown fox jumps over the lazy dog.", proinst);
    assertEquals(" Fragile!  Handle me with care! ", comment);
}
Also used : Comment(org.w3c.dom.Comment) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Example 17 with ProcessingInstruction

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

the class NormalizeTest method testInvalidCharactersProcessingInstructionData.

public void testInvalidCharactersProcessingInstructionData() throws Exception {
    ErrorRecorder errorRecorder = new ErrorRecorder();
    domConfiguration.setParameter("error-handler", errorRecorder);
    domConfiguration.setParameter("namespaces", false);
    Element root = document.createElement("foo");
    document.appendChild(root);
    ProcessingInstruction pi = document.createProcessingInstruction("foo", "");
    root.appendChild(pi);
    for (int c = 0; c <= Character.MAX_VALUE; c++) {
        pi.setData(new String(new char[] { 'A', 'B', (char) c }));
        document.normalizeDocument();
        if (isValid((char) c)) {
            assertEquals(Collections.<DOMError>emptyList(), errorRecorder.errors);
        } else {
            errorRecorder.assertAllErrors("For character " + c, DOMError.SEVERITY_ERROR, "wf-invalid-character");
        }
    }
}
Also used : Element(org.w3c.dom.Element) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Example 18 with ProcessingInstruction

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

the class ImportNode method testImportNode14.

// Assumes validation
//    public void testImportNode11() throws Throwable {
//        Document doc;
//        Document aNewDoc;
//        EntityReference entRef;
//        Node aNode;
//        String name;
//        Node child;
//        String childValue;
//        doc = (Document) load("staff", builder);
//        aNewDoc = (Document) load("staff", builder);
//        entRef = aNewDoc.createEntityReference("ent3");
//        assertNotNull("createdEntRefNotNull", entRef);
//        aNode = doc.importNode(entRef, true);
//        name = aNode.getNodeName();
//        assertEquals("entityName", "ent3", name);
//        child = aNode.getFirstChild();
//        assertNotNull("child", child);
//        childValue = child.getNodeValue();
//        assertEquals("childValue", "Texas", childValue);
//    }
// Assumes validation.
//    public void testImportNode12() throws Throwable {
//        Document doc;
//        Document aNewDoc;
//        DocumentType doc1Type;
//        NamedNodeMap entityList;
//        Entity entity2;
//        Entity entity1;
//        Document ownerDocument;
//        DocumentType docType;
//        String system;
//        String entityName;
//        Node child;
//        String childName;
//        doc = (Document) load("staffNS", builder);
//        aNewDoc = (Document) load("staffNS", builder);
//        doc1Type = aNewDoc.getDoctype();
//        entityList = doc1Type.getEntities();
//        assertNotNull("entitiesNotNull", entityList);
//        entity2 = (Entity) entityList.getNamedItem("ent4");
//        entity1 = (Entity) doc.importNode(entity2, true);
//        ownerDocument = entity1.getOwnerDocument();
//        docType = ownerDocument.getDoctype();
//        system = docType.getSystemId();
//        assertURIEquals("systemId", null, null, null, "staffNS.dtd", null,
//                null, null, null, system);
//        entityName = entity1.getNodeName();
//        assertEquals("entityName", "ent4", entityName);
//        child = entity1.getFirstChild();
//        assertNotNull("notnull", child);
//        childName = child.getNodeName();
//        assertEquals("childName", "entElement1", childName);
//    }
// Assumes validation
//    public void testImportNode13() throws Throwable {
//        Document doc;
//        Document aNewDoc;
//        DocumentType doc1Type;
//        NamedNodeMap notationList;
//        Notation notation;
//        Notation aNode;
//        Document ownerDocument;
//        DocumentType docType;
//        String system;
//        String publicVal;
//        doc = (Document) load("staffNS", builder);
//        aNewDoc = (Document) load("staffNS", builder);
//        doc1Type = aNewDoc.getDoctype();
//        notationList = doc1Type.getNotations();
//        assertNotNull("notationsNotNull", notationList);
//        notation = (Notation) notationList.getNamedItem("notation1");
//        aNode = (Notation) doc.importNode(notation, false);
//        ownerDocument = aNode.getOwnerDocument();
//        docType = ownerDocument.getDoctype();
//        system = docType.getSystemId();
//        assertURIEquals("systemId", null, null, null, "staffNS.dtd", null,
//                null, null, null, system);
//        publicVal = aNode.getPublicId();
//        assertEquals("publicId", "notation1File", publicVal);
//        system = aNode.getSystemId();
//        assertNull("notationSystemId", system);
//    }
public void testImportNode14() throws Throwable {
    Document doc;
    Document aNewDoc;
    ProcessingInstruction pi;
    ProcessingInstruction aNode;
    Document ownerDocument;
    DocumentType docType;
    String system;
    String target;
    String data;
    doc = (Document) load("staffNS", builder);
    aNewDoc = (Document) load("staffNS", builder);
    pi = aNewDoc.createProcessingInstruction("target1", "data1");
    aNode = (ProcessingInstruction) doc.importNode(pi, false);
    ownerDocument = aNode.getOwnerDocument();
    assertNotNull("ownerDocumentNotNull", ownerDocument);
    docType = ownerDocument.getDoctype();
    system = docType.getSystemId();
    assertURIEquals("systemId", null, null, null, "staffNS.dtd", null, null, null, null, system);
    target = aNode.getTarget();
    assertEquals("piTarget", "target1", target);
    data = aNode.getData();
    assertEquals("piData", "data1", data);
}
Also used : DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Example 19 with ProcessingInstruction

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

the class DocumentImportNode method testImportNode18.

public void testImportNode18() throws Throwable {
    Document doc;
    ProcessingInstruction piImport;
    ProcessingInstruction piToImport;
    String piData;
    String piTarget;
    doc = (Document) load("staffNS", builder);
    piToImport = doc.createProcessingInstruction("Target", "Data");
    piImport = (ProcessingInstruction) doc.importNode(piToImport, false);
    piTarget = piImport.getTarget();
    piData = piImport.getData();
    assertEquals("documentimportnode18_Target", "Target", piTarget);
    assertEquals("documentimportnode18_Data", "Data", piData);
}
Also used : Document(org.w3c.dom.Document) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Example 20 with ProcessingInstruction

use of org.w3c.dom.ProcessingInstruction in project spring-framework by spring-projects.

the class DomContentHandler method processingInstruction.

@Override
public void processingInstruction(String target, String data) throws SAXException {
    Node parent = getParent();
    ProcessingInstruction pi = document.createProcessingInstruction(target, data);
    parent.appendChild(pi);
}
Also used : Node(org.w3c.dom.Node) ProcessingInstruction(org.w3c.dom.ProcessingInstruction)

Aggregations

ProcessingInstruction (org.w3c.dom.ProcessingInstruction)20 Element (org.w3c.dom.Element)10 NamedNodeMap (org.w3c.dom.NamedNodeMap)9 Node (org.w3c.dom.Node)8 Document (org.w3c.dom.Document)7 EntityReference (org.w3c.dom.EntityReference)6 Locator (org.xml.sax.Locator)4 LexicalHandler (org.xml.sax.ext.LexicalHandler)4 DOMException (org.w3c.dom.DOMException)3 DocumentType (org.w3c.dom.DocumentType)3 AttList (org.apache.xml.serializer.utils.AttList)2 Attr (org.w3c.dom.Attr)2 Comment (org.w3c.dom.Comment)2 NodeList (org.w3c.dom.NodeList)2 CDATASection (org.w3c.dom.CDATASection)1 DOMImplementation (org.w3c.dom.DOMImplementation)1 Text (org.w3c.dom.Text)1