當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。