本文整理汇总了Java中org.w3c.dom.Document.setXmlStandalone方法的典型用法代码示例。如果您正苦于以下问题:Java Document.setXmlStandalone方法的具体用法?Java Document.setXmlStandalone怎么用?Java Document.setXmlStandalone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.setXmlStandalone方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldBuildDocumentFromSetOfXPaths
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void shouldBuildDocumentFromSetOfXPaths()
throws XPathExpressionException, TransformerException, IOException {
Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
Document document = documentBuilder.newDocument();
document.setXmlStandalone(true);
Document builtDocument = new XmlBuilder(namespaceContext)
.putAll(xmlProperties.keySet())
.build(document);
for (Entry<String, Object> xpathToValuePair : xmlProperties.entrySet()) {
XPath xpath = xpathFactory.newXPath();
if (null != namespaceContext) {
xpath.setNamespaceContext(namespaceContext);
}
assertThat(xpath.evaluate(xpathToValuePair.getKey(), builtDocument)).isNotNull();
}
assertThat(xmlToString(builtDocument)).isEqualTo(fixtureAccessor.getPutXml());
}
示例2: shouldBuildDocumentFromSetOfXPathsAndSetValues
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void shouldBuildDocumentFromSetOfXPathsAndSetValues()
throws XPathExpressionException, TransformerException, IOException {
Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
Document document = documentBuilder.newDocument();
document.setXmlStandalone(true);
Document builtDocument = new XmlBuilder(namespaceContext)
.putAll(xmlProperties)
.build(document);
for (Entry<String, Object> xpathToValuePair : xmlProperties.entrySet()) {
XPath xpath = xpathFactory.newXPath();
if (null != namespaceContext) {
xpath.setNamespaceContext(namespaceContext);
}
assertThat(xpath.evaluate(xpathToValuePair.getKey(), builtDocument, XPathConstants.STRING))
.isEqualTo(xpathToValuePair.getValue());
}
assertThat(xmlToString(builtDocument)).isEqualTo(fixtureAccessor.getPutValueXml());
}
示例3: saveDATtoFile
import org.w3c.dom.Document; //导入方法依赖的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);
}
示例4: testXIncludeDOMPos
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Test the simple case of including a document using xi:include using a
* DocumentBuilder.
*
* @throws Exception If any errors occur.
*/
@Test(groups = {"readWriteLocalFiles"})
public void testXIncludeDOMPos() throws Exception {
String resultFile = USER_DIR + "doc_xincludeDOM.out";
String goldFile = GOLDEN_DIR + "doc_xincludeGold.xml";
String xmlFile = XML_DIR + "doc_xinclude.xml";
try (FileOutputStream fos = new FileOutputStream(resultFile)) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
doc.setXmlStandalone(true);
TransformerFactory.newInstance().newTransformer().
transform(new DOMSource(doc), new StreamResult(fos));
}
assertTrue(compareDocumentWithGold(goldFile, resultFile));
}
示例5: testXIncludeFallbackDOMPos
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Test the simple case of including a document using xi:include within a
* xi:fallback using a DocumentBuilder.
*
* @throws Exception If any errors occur.
*/
@Test(groups = {"readWriteLocalFiles"})
public void testXIncludeFallbackDOMPos() throws Exception {
String resultFile = USER_DIR + "doc_fallbackDOM.out";
String goldFile = GOLDEN_DIR + "doc_fallbackGold.xml";
String xmlFile = XML_DIR + "doc_fallback.xml";
try (FileOutputStream fos = new FileOutputStream(resultFile)) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
doc.setXmlStandalone(true);
TransformerFactory.newInstance().newTransformer()
.transform(new DOMSource(doc), new StreamResult(fos));
}
assertTrue(compareDocumentWithGold(goldFile, resultFile));
}
示例6: testXIncludeFallbackTextPos
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Test for xi:fallback where the fall back text is parsed as text. This
* test uses a nested xi:include for the fallback test.
*
* @throws Exception If any errors occur.
*/
@Test(groups = {"readWriteLocalFiles"})
public void testXIncludeFallbackTextPos() throws Exception {
String resultFile = USER_DIR + "doc_fallback_text.out";
String goldFile = GOLDEN_DIR + "doc_fallback_textGold.xml";
String xmlFile = XML_DIR + "doc_fallback_text.xml";
try (FileOutputStream fos = new FileOutputStream(resultFile)) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
doc.setXmlStandalone(true);
TransformerFactory.newInstance().newTransformer()
.transform(new DOMSource(doc), new StreamResult(fos));
}
assertTrue(compareDocumentWithGold(goldFile, resultFile));
}
示例7: testXIncludeLoopPos
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Test if xi:include may reference the doc containing the include if the
* parse type is text.
*
* @throws Exception If any errors occur.
*/
@Test(groups = {"readWriteLocalFiles"})
public void testXIncludeLoopPos() throws Exception {
String resultFile = USER_DIR + "doc_xinc_loops.out";
String goldFile = GOLDEN_DIR + "doc_xinc_loopGold.xml";
String xmlFile = XML_DIR + "doc_xinc_loops.xml";
try (FileOutputStream fos = new FileOutputStream(resultFile)) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new File(xmlFile));
doc.normalizeDocument();
doc.setXmlStandalone(true);
TransformerFactory.newInstance().newTransformer()
.transform(new DOMSource(doc), new StreamResult(fos));
}
assertTrue(compareDocumentWithGold(goldFile, resultFile));
}
示例8: testXIncludeNestedPos
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Test if two non nested xi:include elements can include the same document
* with an xi:include statement.
*
* @throws Exception If any errors occur.
*/
@Test(groups = {"readWriteLocalFiles"})
public void testXIncludeNestedPos() throws Exception {
String resultFile = USER_DIR + "schedule.out";
String goldFile = GOLDEN_DIR + "scheduleGold.xml";
String xmlFile = XML_DIR + "schedule.xml";
try (FileOutputStream fos = new FileOutputStream(resultFile)) {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setXIncludeAware(true);
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile));
doc.setXmlStandalone(true);
TransformerFactory.newInstance().newTransformer()
.transform(new DOMSource(doc), new StreamResult(fos));
}
assertTrue(compareDocumentWithGold(goldFile, resultFile));
}
示例9: exportGrammar
import org.w3c.dom.Document; //导入方法依赖的package包/类
public static Document exportGrammar(RCG g, Map<String, TagTree> dict){
dictionary = dict;
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder constructor = factory.newDocumentBuilder();
Document rcggrammar = constructor.newDocument();
rcggrammar.setXmlVersion("1.0");
rcggrammar.setXmlStandalone(true);
Element root = rcggrammar.createElement("rcg");
String label = "";
PredLabel p = g.getStartPredicateLabel();
if (p instanceof PredStringLabel) {
label = p.toString();
} else if (p instanceof PredComplexLabel) {
label = ((PredComplexLabel) p).getComplexLabel();
}
root.setAttribute("start", label);
List<Clause> clauses = g.getClauses();
for(int i = 0 ; i < clauses.size() ; i++) {
RCGDOMbuilder.exportClause(root, clauses.get(i), null, rcggrammar);
}
// finally we do not forget the root
rcggrammar.appendChild(root);
return rcggrammar;
} catch (ParserConfigurationException e) {
System.err.println(e);
//System.err.println(e.getStackTrace());
return null;
}
}
示例10: shouldBuildDocumentFromSetOfXPaths
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Benchmark
public void shouldBuildDocumentFromSetOfXPaths(Blackhole blackhole)
throws XPathExpressionException, IOException {
Map<String, Object> xmlProperties = fixtureAccessor.getXmlProperties();
Document document = documentBuilder.newDocument();
document.setXmlStandalone(true);
blackhole.consume(new XmlBuilder(namespaceContext)
.putAll(xmlProperties.keySet())
.build(document));
}
示例11: mergeContent
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* @param mergeSource
* @param input
* @param output
* @throws DocTemplateException
*/
protected void mergeContent(MergeSource mergeSource, InputStream input,
OutputStream output) throws DocTemplateException {
try (InputStreamRemainingOpen is = new InputStreamRemainingOpen(input)) {
// XML Verarbeitung
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(is);
Document result = builder.newDocument();
result.setXmlStandalone(true);
preProcess(result, doc, result);
StringWriter writer = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(result), new StreamResult(writer));
// Struktur parsen
BasicMergeElement bme = parseInit();
parseTemplate(new StringBuffer(writer.toString()));
if (this.parseStack.size() > 1) {
// Debug-Info about the failing element
BasicMergeElement lastFailing = this.parseStack.peek();
String errorMessage = "last failing tag is " + lastFailing.toString();
LOG.error("There is an unmatched tag on the stack. The template has an invalid structure: " + errorMessage);
throw new DocTemplateException("error.template.invalid.structure", errorMessage);
}
// Ergebnis erstellen
bme.getContent(new MergeContext(mergeSource), mergeSource, output);
}
catch (DocTemplateException sfe) {
throw sfe;
}
catch (IOException | SAXException | ParserConfigurationException
| TransformerException | TransformerFactoryConfigurationError e) {
throw new DocTemplateException(e);
}
}
示例12: stringToXml
import org.w3c.dom.Document; //导入方法依赖的package包/类
private Document stringToXml(String xml) throws IOException, SAXException {
Document document = documentBuilder.parse(new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8"))));
document.setXmlStandalone(true);
return document;
}