当前位置: 首页>>代码示例>>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;未经允许,请勿转载。