當前位置: 首頁>>代碼示例>>Java>>正文


Java DocumentType類代碼示例

本文整理匯總了Java中org.w3c.dom.DocumentType的典型用法代碼示例。如果您正苦於以下問題:Java DocumentType類的具體用法?Java DocumentType怎麽用?Java DocumentType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DocumentType類屬於org.w3c.dom包,在下文中一共展示了DocumentType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: saveDocumentTo

import org.w3c.dom.DocumentType; //導入依賴的package包/類
private void saveDocumentTo() throws XMLException {
	try {
		TransformerFactory tfactory = TransformerFactory.newInstance();
		Transformer transf = tfactory.newTransformer();
		
		transf.setOutputProperty( OutputKeys.INDENT, "yes" );
		transf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
		transf.setOutputProperty( OutputKeys.OMIT_XML_DECLARATION, "no" );
		transf.setOutputProperty( OutputKeys.METHOD, "xml" );
		
		DOMImplementation impl = doc.getImplementation();
		DocumentType doctype = impl.createDocumentType( "doctype", 
				"-//Recordare//DTD MusicXML 3.0 Partwise//EN", "http://www.musicxml.org/dtds/partwise.dtd" );
		
		transf.setOutputProperty( OutputKeys.DOCTYPE_PUBLIC, doctype.getPublicId() );
		transf.setOutputProperty( OutputKeys.DOCTYPE_SYSTEM, doctype.getSystemId() );
		
		DOMSource src = new DOMSource( doc );
		StreamResult resultS = new StreamResult( file );
		transf.transform( src, resultS );
		
	} catch ( TransformerException e ) {
		throw new XMLException( "Could not save the File" );
	}
}
 
開發者ID:Paulpanther,項目名稱:Random-Music-Generator,代碼行數:26,代碼來源:XMLGenerator.java

示例2: getDocumentType

import org.w3c.dom.DocumentType; //導入依賴的package包/類
private static DocumentType getDocumentType(Document doc) {
    DOMImplementation domImpl = doc.getImplementation();
    // <!DOCTYPE datafile PUBLIC "-//Logiqx//DTD ROM Management Datafile//EN" "http://www.logiqx.com/Dats/datafile.dtd">
    DocumentType doctype = domImpl.createDocumentType("datafile",
            "-//Logiqx//DTD ROM Management Datafile//EN",
            "http://www.logiqx.com/Dats/datafile.dtd");
    return doctype;
}
 
開發者ID:phweda,項目名稱:MFM,代碼行數:9,代碼來源:PersistUtils.java

示例3: testDocType

import org.w3c.dom.DocumentType; //導入依賴的package包/類
/** Test that read/write DOCTYPE works too. */
public void testDocType() throws Exception {
    String data = "<!DOCTYPE foo PUBLIC \"The foo DTD\" \"http://nowhere.net/foo.dtd\"><foo><x/><x/></foo>";
    Document doc = XMLUtil.parse(new InputSource(new StringReader(data)), true, true, new Handler(), new Resolver());
    DocumentType t = doc.getDoctype();
    assertNotNull(t);
    assertEquals("foo", t.getName());
    assertEquals("The foo DTD", t.getPublicId());
    assertEquals("http://nowhere.net/foo.dtd", t.getSystemId());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLUtil.write(doc, baos, "UTF-8");
    String data2 = baos.toString("UTF-8");
    //System.err.println("data2:\n" + data2);
    assertTrue(data2, data2.indexOf("foo") != -1);
    assertTrue(data2, data2.indexOf('x') != -1);
    assertTrue(data2, data2.indexOf("DOCTYPE") != -1);
    assertTrue(data2, data2.indexOf("The foo DTD") != -1);
    assertTrue(data2, data2.indexOf("http://nowhere.net/foo.dtd") != -1);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:XMLUtilTest.java

示例4: write

import org.w3c.dom.DocumentType; //導入依賴的package包/類
public static void write(Document doc, OutputStream out) throws IOException {
    // XXX note that this may fail to write out namespaces correctly if the document
    // is created with namespaces and no explicit prefixes; however no code in
    // this package is likely to be doing so
    try {
        Transformer t = TransformerFactory.newInstance().newTransformer(
                new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
        DocumentType dt = doc.getDoctype();
        if (dt != null) {
            String pub = dt.getPublicId();
            if (pub != null) {
                t.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, pub);
            }
            t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, dt.getSystemId());
        }
        t.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); // NOI18N
        Source source = new DOMSource(doc);
        Result result = new StreamResult(out);
        t.transform(source, result);
    } catch (Exception | TransformerFactoryConfigurationError e) {
        throw new IOException(e);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:XMLUtil.java

示例5: write

import org.w3c.dom.DocumentType; //導入依賴的package包/類
/**
 * Write.
 *
 * @param node
 *            the node
 * @throws ShellException
 *             the shell exception
 */
protected void write(DocumentType node) throws ShellException {
    printWriter.print("<!DOCTYPE "); //$NON-NLS-1$
    printWriter.print(node.getName());
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    if (publicId != null) {
        printWriter.print(" PUBLIC \""); //$NON-NLS-1$
        printWriter.print(publicId);
        printWriter.print("\" \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('\"');
    } else if (systemId != null) {
        printWriter.print(" SYSTEM \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('"');
    }

    String internalSubset = node.getInternalSubset();
    if (internalSubset != null) {
        printWriter.println(" ["); //$NON-NLS-1$
        printWriter.print(internalSubset);
        printWriter.print(']');
    }
    printWriter.println('>');
}
 
開發者ID:bandaotixi,項目名稱:generator_mybatis,代碼行數:34,代碼來源:DomWriter.java

示例6: write

import org.w3c.dom.DocumentType; //導入依賴的package包/類
protected void write(DocumentType node) throws ShellException {
    printWriter.print("<!DOCTYPE "); //$NON-NLS-1$
    printWriter.print(node.getName());
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    if (publicId != null) {
        printWriter.print(" PUBLIC \""); //$NON-NLS-1$
        printWriter.print(publicId);
        printWriter.print("\" \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('\"');
    } else if (systemId != null) {
        printWriter.print(" SYSTEM \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('"');
    }
    
    String internalSubset = node.getInternalSubset();
    if (internalSubset != null) {
        printWriter.println(" ["); //$NON-NLS-1$
        printWriter.print(internalSubset);
        printWriter.print(']');
    }
    printWriter.println('>');
}
 
開發者ID:ajtdnyy,項目名稱:PackagePlugin,代碼行數:26,代碼來源:DomWriter.java

示例7: whichDoctypePublic

import org.w3c.dom.DocumentType; //導入依賴的package包/類
/**
 * Returns the document type public identifier
 * specified for this document, or null.
 */
public static String whichDoctypePublic( Document doc )
{
    DocumentType doctype;

       /*  DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getPublicId();
       } catch ( Error except ) {  }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLPublicId;
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:OutputFormat.java

示例8: whichDoctypeSystem

import org.w3c.dom.DocumentType; //導入依賴的package包/類
/**
 * Returns the document type system identifier
 * specified for this document, or null.
 */
public static String whichDoctypeSystem( Document doc )
{
    DocumentType doctype;

    /* DOM Level 2 was introduced into the code base*/
       doctype = doc.getDoctype();
       if ( doctype != null ) {
       // Note on catch: DOM Level 1 does not specify this method
       // and the code will throw a NoSuchMethodError
       try {
       return doctype.getSystemId();
       } catch ( Error except ) { }
       }

    if ( doc instanceof HTMLDocument )
        return DTD.XHTMLSystemId;
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:OutputFormat.java

示例9: saveXMLDoctoFile

import org.w3c.dom.DocumentType; //導入依賴的package包/類
public static void saveXMLDoctoFile(Document doc, DocumentType documentType, String path)
        throws TransformerException {
    // Save DOM XML doc to File
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();

    doc.setXmlVersion("1.0");
    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, documentType.getPublicId());
    transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, documentType.getSystemId());

    transformer.transform(new DOMSource(doc), new StreamResult(new File(path)));
}
 
開發者ID:phweda,項目名稱:MFM,代碼行數:14,代碼來源:PersistUtils.java

示例10: saveDATtoFile

import org.w3c.dom.DocumentType; //導入依賴的package包/類
public static void saveDATtoFile(Datafile datafile, String path)
            throws ParserConfigurationException, JAXBException, TransformerException, FileNotFoundException {

        JAXBContext jc = JAXBContext.newInstance(Datafile.class);

        // Create the Document
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.newDocument();
        DocumentType docType = getDocumentType(document);

        // Marshal the Object to a Document formatted so human readable
        Marshaller marshaller = jc.createMarshaller();
/*
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, docType.getSystemId());
*/

        marshaller.marshal(datafile, document);
        document.setXmlStandalone(true);
        // NOTE could output with marshaller but cannot set DTD document type
/*
        OutputStream os = new FileOutputStream(path);
        marshaller.marshal(datafile, os);
*/

        // Output the Document
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        //    transformerFactory.setAttribute("indent-number", "4");
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
        //   transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "8");
        transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, docType.getPublicId());
        transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, docType.getSystemId());
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(new File(path));
        transformer.transform(source, result);
    }
 
開發者ID:phweda,項目名稱:MFM,代碼行數:41,代碼來源:PersistUtils.java

示例11: endNode

import org.w3c.dom.DocumentType; //導入依賴的package包/類
/**
 * End processing of given node
 *
 *
 * @param node Node we just finished processing
 *
 * @throws org.xml.sax.SAXException
 */
protected void endNode(Node node) throws org.xml.sax.SAXException {

    switch (node.getNodeType()) {
        case Node.DOCUMENT_NODE :
            break;
        case Node.DOCUMENT_TYPE_NODE :
            serializeDocType((DocumentType) node, false);
            break;
        case Node.ELEMENT_NODE :
            serializeElement((Element) node, false);
            break;
        case Node.CDATA_SECTION_NODE :
            break;
        case Node.ENTITY_REFERENCE_NODE :
            serializeEntityReference((EntityReference) node, false);
            break;
        default :
            }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:DOM3TreeWalker.java

示例12: getDocumentTypeDeclarationSystemIdentifier

import org.w3c.dom.DocumentType; //導入依賴的package包/類
/**
 *   A document type declaration information item has the following properties:
 *
 *     1. [system identifier] The system identifier of the external subset, if
 *        it exists. Otherwise this property has no value.
 *
 * @return the system identifier String object, or null if there is none.
 */
public String getDocumentTypeDeclarationSystemIdentifier()
{

  Document doc;

  if (m_root.getNodeType() == Node.DOCUMENT_NODE)
    doc = (Document) m_root;
  else
    doc = m_root.getOwnerDocument();

  if (null != doc)
  {
    DocumentType dtd = doc.getDoctype();

    if (null != dtd)
    {
      return dtd.getSystemId();
    }
  }

  return null;
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:31,代碼來源:DOM2DTM.java

示例13: getDocumentTypeDeclarationPublicIdentifier

import org.w3c.dom.DocumentType; //導入依賴的package包/類
/**
 * Return the public identifier of the external subset,
 * normalized as described in 4.2.2 External Entities [XML]. If there is
 * no external subset or if it has no public identifier, this property
 * has no value.
 *
 * @return the public identifier String object, or null if there is none.
 */
public String getDocumentTypeDeclarationPublicIdentifier()
{

  Document doc;

  if (m_root.getNodeType() == Node.DOCUMENT_NODE)
    doc = (Document) m_root;
  else
    doc = m_root.getOwnerDocument();

  if (null != doc)
  {
    DocumentType dtd = doc.getDoctype();

    if (null != dtd)
    {
      return dtd.getPublicId();
    }
  }

  return null;
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:31,代碼來源:DOM2DTM.java

示例14: writeDocumentType

import org.w3c.dom.DocumentType; //導入依賴的package包/類
private void writeDocumentType(DocumentType docType, Writer writer, int depth) throws IOException {
    String publicId = docType.getPublicId();
    String internalSubset = docType.getInternalSubset();

    for (int i = 0; i < depth; ++i) { writer.append(' '); }
    writer.append("<!DOCTYPE ").append(docType.getName());
    if (publicId != null) {
        writer.append(" PUBLIC '").append(publicId).append("' ");
    } else {
        writer.write(" SYSTEM ");
    }
    writer.append("'").append(docType.getSystemId()).append("'");
    if (internalSubset != null) {
        writer.append(" [").append(internalSubset).append("]");
    }
    writer.append('>').append(lineSeparator);
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:18,代碼來源:DOMSerializer.java

示例15: write

import org.w3c.dom.DocumentType; //導入依賴的package包/類
protected void write(DocumentType node) throws ShellException {
    printWriter.print("<!DOCTYPE "); //$NON-NLS-1$
    printWriter.print(node.getName());
    String publicId = node.getPublicId();
    String systemId = node.getSystemId();
    if (publicId != null) {
        printWriter.print(" PUBLIC \""); //$NON-NLS-1$
        printWriter.print(publicId);
        printWriter.print("\" \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('\"');
    } else if (systemId != null) {
        printWriter.print(" SYSTEM \""); //$NON-NLS-1$
        printWriter.print(systemId);
        printWriter.print('"');
    }

    String internalSubset = node.getInternalSubset();
    if (internalSubset != null) {
        printWriter.println(" ["); //$NON-NLS-1$
        printWriter.print(internalSubset);
        printWriter.print(']');
    }
    printWriter.println('>');
}
 
開發者ID:funny5258,項目名稱:autocode,代碼行數:26,代碼來源:DomWriter.java


注:本文中的org.w3c.dom.DocumentType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。