当前位置: 首页>>代码示例>>Java>>正文


Java Document.setXmlStandalone方法代码示例

本文整理汇总了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());
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:20,代码来源:XmlBuilderTest.java

示例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());
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:21,代码来源:XmlBuilderTest.java

示例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);
    }
 
开发者ID:phweda,项目名称:MFM,代码行数:41,代码来源:PersistUtils.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:AuctionItemRepository.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:AuctionItemRepository.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:AuctionItemRepository.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:AuctionItemRepository.java

示例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));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:AuctionItemRepository.java

示例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;
	}
}
 
开发者ID:spetitjean,项目名称:TuLiPA-frames,代码行数:35,代码来源:RCGDOMbuilder.java

示例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));
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:11,代码来源:DomXmlBuilderBenchmark.java

示例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);
	}
}
 
开发者ID:dvbern,项目名称:doctemplate,代码行数:44,代码来源:AbstractMergeEngine.java

示例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;
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:6,代码来源:XmlBuilderTest.java


注:本文中的org.w3c.dom.Document.setXmlStandalone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。