本文整理汇总了Java中org.w3c.dom.Document类的典型用法代码示例。如果您正苦于以下问题:Java Document类的具体用法?Java Document怎么用?Java Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Document类属于org.w3c.dom包,在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertStringToDocument
import org.w3c.dom.Document; //导入依赖的package包/类
/**
*
* Convert XML string to {@link Document}
*
* @param xmlString
* @return {@link Document}
*/
public static Document convertStringToDocument(String xmlString) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder;
try
{
factory.setFeature(Constants.DISALLOW_DOCTYPE_DECLARATION,true);
builder = factory.newDocumentBuilder();
Document doc = builder.parse( new InputSource( new StringReader( xmlString ) ) );
return doc;
} catch (ParserConfigurationException| SAXException| IOException e) {
logger.debug("Unable to convert string to Document",e);
}
return null;
}
示例2: write
import org.w3c.dom.Document; //导入依赖的package包/类
static void write(
@NonNull final OutputStream out,
@NonNull final RemotePlatform platform) throws IOException {
Parameters.notNull("out", out); //NOI18N
Parameters.notNull("platform", platform); //NOI18N
final Document doc = XMLUtil.createDocument(
ELM_PLATFORM,
null,
REMOTE_PLATFORM_DTD_ID,
REMOTE_PLATFORM_SYSTEM_ID);
final Element platformElement = doc.getDocumentElement();
platformElement.setAttribute(ATTR_NAME, platform.getDisplayName());
final Map<String,String> props = platform.getProperties();
final Element propsElement = doc.createElement(ELM_PROPERTIES);
writeProperties(props, propsElement, doc);
platformElement.appendChild(propsElement);
final Map<String,String> sysProps = platform.getSystemProperties();
final Element sysPropsElement = doc.createElement(ELM_SYSPROPERTIES);
writeProperties(sysProps, sysPropsElement, doc);
platformElement.appendChild(sysPropsElement);
XMLUtil.write(doc, out, "UTF8");
}
示例3: readCustomScript
import org.w3c.dom.Document; //导入依赖的package包/类
/**
* Read a generated script if it exists, else create a skeleton.
* Imports jdk.xml if appropriate.
* @param scriptPath e.g. {@link #FILE_SCRIPT_PATH} or {@link #GENERAL_SCRIPT_PATH}
*/
Document readCustomScript(String scriptPath) throws IOException, SAXException {
// XXX if there is TAX support for rewriting XML files, use that here...
FileObject script = helper.getProjectDirectory().getFileObject(scriptPath);
Document doc;
if (script != null) {
InputStream is = script.getInputStream();
try {
doc = XMLUtil.parse(new InputSource(is), false, true, null, null);
} finally {
is.close();
}
} else {
doc = XMLUtil.createDocument("project", /*XXX:"antlib:org.apache.tools.ant"*/null, null, null); // NOI18N
Element root = doc.getDocumentElement();
String projname = ProjectUtils.getInformation(project).getDisplayName();
root.setAttribute("name", NbBundle.getMessage(JavaActions.class, "LBL_generated_script_name", projname));
}
if (helper.getProjectDirectory().getFileObject(JdkConfiguration.JDK_XML) != null) {
JdkConfiguration.insertJdkXmlImport(doc);
}
return doc;
}
示例4: testCreateStartDocument_DOMWriter
import org.w3c.dom.Document; //导入依赖的package包/类
/**
* @bug 8139584
* Verifies that the resulting XML contains the standalone setting.
*/
@Test
public void testCreateStartDocument_DOMWriter()
throws ParserConfigurationException, XMLStreamException {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc));
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
eventWriter.add(event);
eventWriter.flush();
Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15");
Assert.assertEquals(doc.getXmlVersion(), "1.0");
Assert.assertTrue(doc.getXmlStandalone());
}
示例5: supplementAlvisNLPDocElement
import org.w3c.dom.Document; //导入依赖的package包/类
private void supplementAlvisNLPDocElement(Document doc) throws XPathExpressionException {
Element alvisnlpDocElt = XMLUtils.evaluateElement(alvisnlpDocExpression, doc);
if (alvisnlpDocElt == null) {
alvisnlpDocElt = XMLUtils.createElement(doc, doc, 0, "alvisnlp-doc");
}
ensureAttribute(alvisnlpDocElt, "author", "");
ensureAttribute(alvisnlpDocElt, "date", "");
String klass = getModuleClass();
ensureAttribute(alvisnlpDocElt, "target", klass);
ensureAttribute(alvisnlpDocElt, "short-target", klass.substring(klass.lastIndexOf('.') + 1));
alvisnlpDocElt.setAttribute("beta", Boolean.toString(beta));
if (useInstead.length > 0) {
alvisnlpDocElt.setAttribute("use-instead", useInstead[0].getCanonicalName());
}
supplementSynopsisElement(alvisnlpDocElt);
supplementModuleDocElement(alvisnlpDocElt);
}
示例6: updateApplicationXml
import org.w3c.dom.Document; //导入依赖的package包/类
/**
* Add the web uri and context root elements to the Application xml
*/
@Override
protected void updateApplicationXml(Document doc) throws DeployException {
Element moduleElement = findElementWithModule(doc);
if (moduleElement != null) {
doc.getDocumentElement().removeChild(moduleElement);
}
//create new module
moduleElement = doc.createElement("module");
Element javaElement = doc.createElement("java");
javaElement.appendChild(doc.createTextNode(module));
moduleElement.appendChild(javaElement);
doc.getDocumentElement().appendChild(moduleElement);
}
示例7: saveUserDefinedProperties
import org.w3c.dom.Document; //导入依赖的package包/类
public static void saveUserDefinedProperties() throws XMLException {
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException var4) {
throw new XMLException("Failed to create document: " + var4, var4);
}
Element root = doc.createElement("drivers");
doc.appendChild(root);
Iterator var2 = getJDBCProperties().iterator();
while(var2.hasNext()) {
JDBCProperties props = (JDBCProperties)var2.next();
if(props.isUserDefined()) {
root.appendChild(props.getXML(doc));
}
}
XMLTools.stream(doc, getUserJDBCPropertiesFile(), StandardCharsets.UTF_8);
}
示例8: testBillingWithRolesForUserAssignment
import org.w3c.dom.Document; //导入依赖的package包/类
/**
* Billing test for price model with stepped price.
*
* @throws Exception
*/
private void testBillingWithRolesForUserAssignment(int numUser,
BigDecimal expectedPrice) throws Exception {
final int testMonth = Calendar.APRIL;
final int testDay = 1;
final int testYear = 2010;
final long billingTime = getTimeInMillisForBilling(testYear, testMonth,
testDay);
long subscriptionCreationTime = getTimeInMillisForBilling(testYear,
testMonth - 2, testDay);
long subscriptionActivationTime = getTimeInMillisForBilling(testYear,
testMonth - 2, testDay);
int userNumber = numUser;
initDataPriceModel(userNumber, subscriptionCreationTime,
subscriptionActivationTime);
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
billingService.startBillingRun(billingTime);
return null;
}
});
Document doc = getBillingDocument();
String costs = XMLConverter.getNodeTextContentByXPath(doc,
"/BillingDetails/OverallCosts/@grossAmount");
checkEquals(expectedPrice.toPlainString(), costs);
}
示例9: testWithMapOfLists
import org.w3c.dom.Document; //导入依赖的package包/类
public void testWithMapOfLists() throws Exception
{
List<ClassD> classDList = newListWith(new ClassD("classD-1"), new ClassD("classD-2"));
Map<String, List<ClassD>> map = new HashMap();
map.put("one", classDList);
this.convertToXmlWith(map);
File xmlLog = JrpipLogGenerator.findLogFileByExtension(JRPIP_LOG_BIN_DIR, ".xml");
Assert.assertTrue(xmlLog.exists());
Document doc = this.createXmlDocument(xmlLog);
NodeList nList1 = doc.getElementsByTagName("key");
Assert.assertEquals(1, nList1.getLength());
NodeList nList2 = doc.getElementsByTagName("ClassD");
Assert.assertEquals(2, nList2.getLength());
NodeList nList3 = doc.getElementsByTagName("String");
Assert.assertEquals(1, nList3.getLength());
}
示例10: merge
import org.w3c.dom.Document; //导入依赖的package包/类
/**
* Merges list of XML files presented by fileList into a single
* XML Document with a given root.
*
* @param fileList list of File objects
* @param rootElementName - name of a root element
*
* @return Document
*/
public static Document merge(final List fileList, final String rootElementName) throws ParserConfigurationException, SAXException, IOException {
final Document mergedDocument = createDomDocument();
final Element element = mergedDocument.createElement(rootElementName);
mergedDocument.appendChild(element);
for (final Iterator i = fileList.iterator(); i.hasNext();) {
final File file = (File)i.next();
if (file.isDirectory()) continue;
final Document documentToMerge = parseDom(file, false);
final NodeList list = documentToMerge.getElementsByTagName("*");
final Element rootElement = (Element)list.item(0);
final Node duplicate = mergedDocument.importNode(rootElement, true);
mergedDocument.getDocumentElement().appendChild(duplicate);
}
return mergedDocument;
}
示例11: readColumnValue
import org.w3c.dom.Document; //导入依赖的package包/类
private void readColumnValue(Document doc,
Map<String, String> xmlFieldXPaths, String columnName,
Object value, ReportResultData reportData, int index, Element node)
throws XPathExpressionException {
if ("RESULTXML".equalsIgnoreCase(columnName)
|| "PROCESSINGRESULT".equalsIgnoreCase(columnName)) {
Document columnValueAsDoc = parseXML((String) reportData
.getColumnValue().get(index));
if (xmlFieldXPaths.containsKey(columnName.toLowerCase())) {
String xpathEvaluationResult = XMLConverter
.getNodeTextContentByXPath(columnValueAsDoc,
xmlFieldXPaths.get(columnName));
// don't store null values but empty strings instead, to ensure
// proper display on client side
if (xpathEvaluationResult == null) {
xpathEvaluationResult = "";
}
node.appendChild(doc.createTextNode(xpathEvaluationResult));
} else {
appendXMLStructureToNode(node, columnValueAsDoc);
}
} else {
node.appendChild(doc.createTextNode(value.toString()));
}
}
示例12: KeyValue
import org.w3c.dom.Document; //导入依赖的package包/类
/**
* Constructor KeyValue
*
* @param doc
* @param pk
*/
public KeyValue(Document doc, PublicKey pk) {
super(doc);
XMLUtils.addReturnToElement(this.constructionElement);
if (pk instanceof java.security.interfaces.DSAPublicKey) {
DSAKeyValue dsa = new DSAKeyValue(this.doc, pk);
this.constructionElement.appendChild(dsa.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
} else if (pk instanceof java.security.interfaces.RSAPublicKey) {
RSAKeyValue rsa = new RSAKeyValue(this.doc, pk);
this.constructionElement.appendChild(rsa.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
}
示例13: unitsFrom
import org.w3c.dom.Document; //导入依赖的package包/类
private Collection<PersistenceUnitInfoImpl> unitsFrom(
final JavaArchive archive,
final ClasspathResource xml
) {
try {
final Document doc = BUILDER.parse(new ByteArrayInputStream(xml.getBytes()));
final Element root = doc.getDocumentElement();
final NodeList unitNodes = (NodeList) xpath().evaluate(
"//persistence/persistence-unit",
root,
NODESET
);
final Collection<PersistenceUnitInfoImpl> ret = new HashSet<>();
for (int i = 0; i < unitNodes.getLength(); i++) {
ret.add(createUnitInfo(archive, (Element) unitNodes.item(i)));
}
return ret;
} catch (final XPathExpressionException | SAXException | IOException e) {
throw new TestEEfiException("Failed to read persistence.xml", e);
}
}
示例14: loadSwingDocument
import org.w3c.dom.Document; //导入依赖的package包/类
@Override
public javax.swing.text.Document loadSwingDocument(InputStream in)
throws IOException, BadLocationException {
javax.swing.text.Document sd = new PlainDocument();
BufferedReader br = new BufferedReader(new InputStreamReader(in));
try {
String line = null;
while ((line = br.readLine()) != null) {
sd.insertString(sd.getLength(), line+System.getProperty("line.separator"), null); // NOI18N
}
} finally {
br.close();
}
return sd;
}
示例15: validateProcess
import org.w3c.dom.Document; //导入依赖的package包/类
private void validateProcess(InputStream inputStream) {
StringBuffer errorInfo=new StringBuffer();
try {
Document document = documentBuilderFactory.newDocumentBuilder().parse(inputStream);
List<String> errors=new ArrayList<String>();
List<String> nodeNames=new ArrayList<String>();
Element element=document.getDocumentElement();
if(processValidator.support(element)){
processValidator.validate(element, errors, nodeNames);
if(errors.size()>0){
for(int i=0;i<errors.size();i++){
errorInfo.append((i+1)+"."+errors.get(i)+"\r\r");
}
}
}else{
errorInfo.append("当前XML文件不是一个合法的UFLO流程模版文件");
}
} catch (Exception e) {
throw new RuntimeException(e);
}
String msg=errorInfo.toString();
if(StringUtils.isNotEmpty(msg)){
throw new ProcessValidateException(msg);
}
}