本文整理匯總了Java中org.w3c.dom.DOMImplementation.createDocumentType方法的典型用法代碼示例。如果您正苦於以下問題:Java DOMImplementation.createDocumentType方法的具體用法?Java DOMImplementation.createDocumentType怎麽用?Java DOMImplementation.createDocumentType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.DOMImplementation
的用法示例。
在下文中一共展示了DOMImplementation.createDocumentType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: saveDocumentTo
import org.w3c.dom.DOMImplementation; //導入方法依賴的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" );
}
}
示例2: getDocumentType
import org.w3c.dom.DOMImplementation; //導入方法依賴的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;
}
示例3: PListBuilder
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
public PListBuilder() {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
builder = factory.newDocumentBuilder();
DOMImplementation di = builder.getDOMImplementation();
dt = di.createDocumentType("plist",
"-//Apple//DTD PLIST 1.0//EN",
"http://www.apple.com/DTDs/PropertyList-1.0.dtd");
doc = di.createDocument("", "plist", dt);
doc.setXmlStandalone(true);
root = doc.getDocumentElement();
root.setAttribute("version", "1.0");
rootDict = doc.createElement("dict");
root.appendChild(rootDict);
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
示例4: testCreateDocumentType01
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
@Test
public void testCreateDocumentType01() throws ParserConfigurationException {
final String name = "document:localName";
final String publicId = "pubid";
final String systemId = "sysid";
DOMImplementation domImpl = getDOMImplementation();
DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId);
verifyDocumentType(documentType, name, publicId, systemId);
}
示例5: testCreateDocumentType02
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
@Test
public void testCreateDocumentType02() throws ParserConfigurationException {
final String name = "document:localName";
final String publicId = "-//W3C//DTD HTML 4.0 Transitional//EN";
final String systemId = "http://www.w3.org/TR/REC-html40/loose.dtd";
DOMImplementation domImpl = getDOMImplementation();
DocumentType documentType = domImpl.createDocumentType(name, publicId, systemId);
Document document = domImpl.createDocument("http://www.document.com", "document:localName", documentType);
verifyDocumentType(document.getDoctype(), name, publicId, systemId);
}
示例6: newDocumentWithDocType
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Creates a new {@link Document} that has a doctype (a {@link DocumentType}
* ).
*
* @throws XMLException
* if the {@link Document} can't be created
*
* @param builder
* the {@link DocumentBuilder} to use when creating the
* {@link Document}, or <code>null</code> to use a
* {@link DocumentBuilder} from the internal pool
* @param docTypeQualifiedName
* the qualified name of the doctype
* @param docTypePublicId
* the public ID of the doctype
* @param docTypeSystemId
* the system ID of the doctype
* @param namespaceURI
* the namespace URI of the document root element, or
* <code>null</code>
* @param qualifiedName
* the qualified name of the document root element
* @return a new {@link Document} (never <code>null</code>)
*/
public static Document newDocumentWithDocType(
DocumentBuilder builder,
final String docTypeQualifiedName,
final String docTypePublicId,
final String docTypeSystemId,
final String namespaceURI,
final String qualifiedName) {
final boolean useCache = (builder == null);
if (useCache) {
builder = cache.takeDocumentBuilder();
}
try {
final DOMImplementation implementation = builder.getDOMImplementation();
final DocumentType doctype =
implementation.createDocumentType(docTypeQualifiedName, docTypePublicId, docTypeSystemId);
return implementation.createDocument(namespaceURI, qualifiedName, doctype);
} finally {
if (useCache) {
cache.releaseDocumentBuilder(builder);
}
}
}
示例7: createDocument
import org.w3c.dom.DOMImplementation; //導入方法依賴的package包/類
/**
* Creates an empty DOM document. E.g.:
* <p><pre>
* Document doc = createDocument("book", null, null, null);
* </pre><p>
* creates new DOM of a well-formed document with root element named book.
*
* @param rootQName qualified name of root element. e.g. <code>myroot</code> or <code>ns:myroot</code>
* @param namespaceURI URI of root element namespace or <code>null</code>
* @param doctypePublicID public ID of DOCTYPE or <code>null</code>
* @param doctypeSystemID system ID of DOCTYPE or <code>null</code> if no DOCTYPE
* required and doctypePublicID is also <code>null</code>
*
* @throws DOMException if new DOM with passed parameters can not be created
* @throws FactoryConfigurationError Application developers should never need to directly catch errors of this type.
*
* @return new DOM Document
*/
public static Document createDocument(
String rootQName, String namespaceURI, String doctypePublicID, String doctypeSystemID
) throws DOMException {
DOMImplementation impl = getDOMImplementation();
if ((doctypePublicID != null) && (doctypeSystemID == null)) {
throw new IllegalArgumentException("System ID cannot be null if public ID specified. "); //NOI18N
}
DocumentType dtd = null;
if (doctypeSystemID != null) {
dtd = impl.createDocumentType(rootQName, doctypePublicID, doctypeSystemID);
}
return impl.createDocument(namespaceURI, rootQName, dtd);
}