本文整理汇总了Java中javax.xml.transform.sax.SAXSource.setInputSource方法的典型用法代码示例。如果您正苦于以下问题:Java SAXSource.setInputSource方法的具体用法?Java SAXSource.setInputSource怎么用?Java SAXSource.setInputSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.transform.sax.SAXSource
的用法示例。
在下文中一共展示了SAXSource.setInputSource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testcase02
import javax.xml.transform.sax.SAXSource; //导入方法依赖的package包/类
/**
* SAXTFactory.newTransformerhandler() method which takes SAXSource as
* argument can be set to XMLReader. SAXSource has input XML file as its
* input source. XMLReader has a content handler which write out the result
* to output file. Test verifies output file is same as golden file.
*
* @throws Exception If any errors occur.
*/
@Test
public void testcase02() throws Exception {
String outputFile = USER_DIR + "saxtf002.out";
String goldFile = GOLDEN_DIR + "saxtf002GF.out";
try (FileOutputStream fos = new FileOutputStream(outputFile);
FileInputStream fis = new FileInputStream(XSLT_FILE)) {
XMLReader reader = XMLReaderFactory.createXMLReader();
SAXTransformerFactory saxTFactory
= (SAXTransformerFactory) TransformerFactory.newInstance();
SAXSource ss = new SAXSource();
ss.setInputSource(new InputSource(fis));
TransformerHandler handler = saxTFactory.newTransformerHandler(ss);
Result result = new StreamResult(fos);
handler.setResult(result);
reader.setContentHandler(handler);
reader.parse(XML_FILE);
}
assertTrue(compareWithGold(goldFile, outputFile));
}
示例2: testcase12
import javax.xml.transform.sax.SAXSource; //导入方法依赖的package包/类
/**
* Unit test for contentHandler setter/getter.
*
* @throws Exception If any errors occur.
*/
@Test
public void testcase12() throws Exception {
String outputFile = USER_DIR + "saxtf012.out";
String goldFile = GOLDEN_DIR + "saxtf012GF.out";
// The transformer will use a SAX parser as it's reader.
XMLReader reader = XMLReaderFactory.createXMLReader();
InputSource is = new InputSource(new FileInputStream(XSLT_FILE));
SAXSource saxSource = new SAXSource();
saxSource.setInputSource(is);
SAXTransformerFactory saxTFactory = (SAXTransformerFactory)TransformerFactory.newInstance();
XMLFilter filter = saxTFactory.newXMLFilter(saxSource);
filter.setParent(reader);
filter.setContentHandler(new MyContentHandler(outputFile));
// Now, when you call transformer.parse, it will set itself as
// the content handler for the parser object (it's "parent"), and
// will then call the parse method on the parser.
filter.parse(new InputSource(XML_FILE));
assertTrue(compareWithGold(goldFile, outputFile));
}
示例3: clear07
import javax.xml.transform.sax.SAXSource; //导入方法依赖的package包/类
/**
* Obtains transformer's parameter whose initiated with a sax source with
* the a name that set before. Value should be same as set one.
* @throws Exception If any errors occur.
*/
@Test
public void clear07() throws Exception {
try (FileInputStream fis = new FileInputStream(XSL_FILE)) {
SAXSource saxSource = new SAXSource();
saxSource.setInputSource(new InputSource(fis));
Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource);
transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);
}
}
示例4: clear08
import javax.xml.transform.sax.SAXSource; //导入方法依赖的package包/类
/**
* Obtains transformer's parameter whose initiated with a sax source with
* the a name that wasn't set before. Null is expected.
* @throws Exception If any errors occur.
*/
@Test
public void clear08() throws Exception {
try (FileInputStream fis = new FileInputStream(XSL_FILE)) {
SAXSource saxSource = new SAXSource();
saxSource.setInputSource(new InputSource(fis));
Transformer transformer = TransformerFactory.newInstance().newTransformer(saxSource);
transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
transformer.clearParameters();
assertNull(transformer.getParameter(LONG_PARAM_NAME));
}
}