Package nu.xom

Examples of nu.xom.DocType


     * @throws XMLException if the DOM <code>DocumentType</code>
     *     is not a well-formed XML document type declaration
     */
    public static DocType convert(org.w3c.dom.DocumentType doctype) {

        DocType result =
            new DocType(
                doctype.getName(),
                doctype.getPublicId(),
                doctype.getSystemId());
        result.setInternalDTDSubset(doctype.getInternalSubset());
       
        return result;

    }
View Full Code Here


      DOMImplementation impl) {

        Element root = document.getRootElement();
        String rootName = root.getQualifiedName();
        String rootNamespace = root.getNamespaceURI();
        DocType doctype = document.getDocType();    
        DocumentType domDOCTYPE = null;
        if (doctype != null) {
            domDOCTYPE = impl.createDocumentType(rootName,
            doctype.getPublicID(), doctype.getSystemID());  
        }     
       
        org.w3c.dom.Document domDoc
         = impl.createDocument(rootNamespace, rootName, domDOCTYPE);
        org.w3c.dom.Element domRoot = domDoc.getDocumentElement();
View Full Code Here

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        builder = factory.newDocumentBuilder();
        impl = builder.getDOMImplementation();       

        DocType type = new DocType("test");
        Element root = new Element("test");         
        xomDocument = new Document(root);
        xomDocument.insertChild(type, 0);
        xomDocument.insertChild(new ProcessingInstruction(
         "xml-stylesheet", "href=\"file.css\" type=\"text/css\""), 1);
View Full Code Here

   
    public void testToXOM() {
       
        Document xomDoc = DOMConverter.convert(domDocument);
        DocType doctype = xomDoc.getDocType();
        Element root = xomDoc.getRootElement();

        assertEquals("test", root.getQualifiedName());
        assertEquals("test", root.getLocalName());
        assertEquals("", root.getNamespaceURI());
       
        assertNotNull(doctype);
        assertTrue(xomDoc.getChild(0) instanceof DocType);
        assertTrue(xomDoc.getChild(4) instanceof nu.xom.Comment);
        assertTrue(xomDoc.getChild(2) instanceof nu.xom.Comment);
        assertEquals(" test ", xomDoc.getChild(2).getValue());
        assertEquals("epilog", xomDoc.getChild(4).getValue());
        assertTrue(
          xomDoc.getChild(1) instanceof nu.xom.ProcessingInstruction);
        assertEquals("test", doctype.getRootElementName());
        assertNull(doctype.getPublicID());
        assertNull(doctype.getSystemID());
      
    }
View Full Code Here

        byte[] data = "<!DOCTYPE root ><element />".getBytes();
        org.w3c.dom.Document doc = builder.parse(new ByteArrayInputStream(data));
         
        org.w3c.dom.DocumentType type = doc.getDoctype();
        DocType xomType = DOMConverter.convert(type);
        assertEquals(type.getName(), xomType.getRootElementName());
                
    }
View Full Code Here

        byte[] data = "<!DOCTYPE root [<!ELEMENT element EMPTY>]><element />".getBytes();
        org.w3c.dom.Document doc = builder.parse(new ByteArrayInputStream(data));
         
        org.w3c.dom.DocumentType type = doc.getDoctype();
        DocType xomType = DOMConverter.convert(type);
        assertEquals(type.getName(), xomType.getRootElementName());
        assertEquals(type.getInternalSubset(), xomType.getInternalDTDSubset());
                
    }
View Full Code Here

        File inputDir = new File("data");
        File f = new File(inputDir, "dtdtest.xhtml");
        org.w3c.dom.Document doc = builder.parse(f);
         
        org.w3c.dom.DocumentType type = doc.getDoctype();
        DocType xomType = DOMConverter.convert(type);
        assertEquals(type.getName(), xomType.getRootElementName());
        assertEquals(type.getSystemId(), xomType.getSystemID());
        assertEquals(type.getPublicId(), xomType.getPublicID());
                
    }
View Full Code Here

   
    public void testToDocumentWithDocType() {
    
        Nodes input = new Nodes();
        Element root = new Element("root");
        DocType doctype = new DocType("root");
        Comment comment = new Comment("data");
        ProcessingInstruction pi = new ProcessingInstruction("target", "data");
        input.append(comment);
        input.append(doctype);
        input.append(root);
View Full Code Here

   
    public void testToDocumentWithDocTypeInEpilog() {
    
        Nodes input = new Nodes();
        Element root = new Element("root");
        DocType doctype = new DocType("root");
        Comment comment = new Comment("data");
        ProcessingInstruction pi = new ProcessingInstruction("target", "data");
        input.append(comment);
        input.append(root);
        input.append(doctype);
View Full Code Here

    }
   
   
    public void testSetMalformedInternalDTDSubset() {
       
        DocType doctype = new DocType("root");
        try {
            doctype.setInternalDTDSubset("<!ELEMENT test (PCDATA>");
            fail("Allowed malformed internal DTD subset");
        }
        catch (WellformednessException success) {
            assertNotNull(success.getMessage());
        }
View Full Code Here

TOP

Related Classes of nu.xom.DocType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.