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


Java DOMSource.setSystemId方法代码示例

本文整理汇总了Java中javax.xml.transform.dom.DOMSource.setSystemId方法的典型用法代码示例。如果您正苦于以下问题:Java DOMSource.setSystemId方法的具体用法?Java DOMSource.setSystemId怎么用?Java DOMSource.setSystemId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.transform.dom.DOMSource的用法示例。


在下文中一共展示了DOMSource.setSystemId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tfactory01

import javax.xml.transform.dom.DOMSource; //导入方法依赖的package包/类
/**
 * This test case checks for the getAssociatedStylesheet method
 * of TransformerFactory.
 * The style sheet returned is then copied to an tfactory01.out
 * It will then be verified to see if it matches the golden files.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void tfactory01() throws Exception {
    String outputFile = USER_DIR + "tfactory01.out";
    String goldFile = GOLDEN_DIR + "tfactory01GF.out";
    String xmlFile = XML_DIR + "TransformerFactoryTest.xml";
    String xmlURI = "file:///" + XML_DIR;

    try (FileInputStream fis = new FileInputStream(xmlFile);
            FileOutputStream fos = new FileOutputStream(outputFile);) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.parse(fis, xmlURI);
        DOMSource domSource = new DOMSource(doc);
        domSource.setSystemId(xmlURI);
        StreamResult streamResult = new StreamResult(fos);
        TransformerFactory tFactory = TransformerFactory.newInstance();

        Source s = tFactory.getAssociatedStylesheet(domSource, "screen",
                                       "Modern", null);
        Transformer t = tFactory.newTransformer();
        t.transform(s, streamResult);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:TransformerFactoryTest.java

示例2: testcase05

import javax.xml.transform.dom.DOMSource; //导入方法依赖的package包/类
/**
 * Unit test for XMLReader parsing when relative URI is used in xsl file and
 * SystemId was set.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testcase05() throws Exception {
    String outputFile = USER_DIR + "saxtf005.out";
    String goldFile = GOLDEN_DIR + "saxtf005GF.out";

    try (FileOutputStream fos = new FileOutputStream(outputFile)) {
        XMLReader reader = XMLReaderFactory.createXMLReader();
        SAXTransformerFactory saxTFactory
                = (SAXTransformerFactory)TransformerFactory.newInstance();
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Document document = docBuilder.parse(new File(XSLT_INCL_FILE));
        Node node = (Node)document;
        DOMSource domSource= new DOMSource(node);

        domSource.setSystemId("file:///" + XML_DIR);

        TransformerHandler handler =
                    saxTFactory.newTransformerHandler(domSource);
        Result result = new StreamResult(fos);

        handler.setResult(result);
        reader.setContentHandler(handler);
        reader.parse(XML_FILE);
    }
    assertTrue(compareWithGold(goldFile, outputFile));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:SAXTFactoryTest.java


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