/**
* Construct an XML Document with a default namespace with the given
* root element.
*
* @param name
* the name of the document's root element.
* @param namespaceURI
* default namespace URI for document, ignored if null or empty.
* @param enableExternalEntities
* enable external entities; beware of XML External Entity (XXE) injection.
* @param isNamespaceAware
* enable or disable namespace awareness in the underlying
* {@link DocumentBuilderFactory}
* @return
* an XML Document.
*
* @throws FactoryConfigurationError
* @throws ParserConfigurationException
*/
protected static Document createDocumentImpl(
String name, String namespaceURI, boolean enableExternalEntities,
boolean isNamespaceAware)
throws ParserConfigurationException, FactoryConfigurationError
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(isNamespaceAware);
enableOrDisableExternalEntityParsing(factory, enableExternalEntities);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
Element rootElement = null;
if (namespaceURI != null && namespaceURI.length() > 0) {
rootElement = document.createElementNS(namespaceURI, name);
} else {
rootElement = document.createElement(name);
}
document.appendChild(rootElement);
return document;
}
BaseXMLBuilder.java 文件源码
java
阅读 42
收藏 0
点赞 0
评论 0
项目:java-xmlbuilder
作者:
评论列表
文章目录