本文整理汇总了Java中net.sf.saxon.s9api.Processor.newSerializer方法的典型用法代码示例。如果您正苦于以下问题:Java Processor.newSerializer方法的具体用法?Java Processor.newSerializer怎么用?Java Processor.newSerializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.saxon.s9api.Processor
的用法示例。
在下文中一共展示了Processor.newSerializer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
@Test
public void doTest() throws SaxonApiException, FileNotFoundException, IOException {
Configuration config = Configuration.newConfiguration();
Processor processor = new Processor(config);
XsltTransformer transformer = processor.newXsltCompiler().compile(new StreamSource("src/test/resources/identity.xsl")).load();
Serializer serializer = processor.newSerializer(new File("target/generated-test-files/output.xml"));
FileAppenderStep fas = new FileAppenderStep();
fas.setParameter(FileAppenderStep.FILE_NAME, new XdmAtomicValue("target/generated-test-files/appendee.txt"));
fas.setParameter(FileAppenderStep.VALUE, new XdmAtomicValue("blablabla"));
fas.setParameter(FileAppenderStep.LINE_SEPARATOR, new XdmAtomicValue("LF"));
fas.setDestination(serializer);
transformer.setDestination(fas);
transformer.setSource(new StreamSource("src/test/resources/source.xml"));
File expect = new File("target/generated-test-files/appendee.txt");
if(expect.exists()) expect.delete();
transformer.transform();
assertTrue(expect.isFile());
BufferedReader br = new BufferedReader(new FileReader(expect));
char[] buff = new char[30];
int ret = br.read(buff);
br.close();
assertEquals(10, ret);
char[] ex = new char[] { 'b', 'l', 'a', 'b', 'l', 'a', 'b', 'l', 'a', '\n'};
assertArrayEquals(ex, Arrays.copyOf(buff, ret));
fas.setDestination(processor.newSerializer(new File("target/generated-test-files/output2.xml")));
transformer.transform();
br = new BufferedReader(new FileReader(expect));
ret = br.read(buff);
br.close();
assertEquals(20, ret);
}
示例2: getSerializer
import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
/**
* Return indenting XML serializer
*
* @return Saxon serializer
*/
private static Serializer getSerializer() {
Configuration config = new Configuration();
Processor processor = new Processor(config);
Serializer s = processor.newSerializer();
s.setOutputProperty(Property.METHOD, "xml");
s.setOutputProperty(Property.ENCODING, "utf-8");
s.setOutputProperty(Property.INDENT, "yes");
return s;
}
示例3: init
import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
/**
* Initialization to improve performance for repetitive invocations of filter and evaluate expressions
*
* @throws XPathException
*/
private void init() throws XPathException {
try {
// Get the processor
proc = new Processor(false);
// Set any specified configuration properties for the processor
if (featureMappings != null) {
for (Entry<String, Object> entry : featureMappings.entrySet()) {
proc.setConfigurationProperty(entry.getKey(), entry.getValue());
}
}
//proc.setConfigurationProperty(FeatureKeys.ENTITY_RESOLVER_CLASS, "com.elsevier.spark_xml_utils.common.IgnoreDoctype");
// Get the XPath compiler
XPathCompiler xpathCompiler = proc.newXPathCompiler();
// Set the namespace to prefix mappings
this.setPrefixNamespaceMappings(xpathCompiler, namespaceMappings);
// Compile the XPath expression and get a document builder
xsel = xpathCompiler.compile(xPathExpression).load();
builder = proc.newDocumentBuilder();
// Create and initialize the serializer
baos = new ByteArrayOutputStream();
serializer = proc.newSerializer(baos);
serializer.setOutputStream(baos);
serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION,"yes");
serializer.setProcessor(proc);
} catch (SaxonApiException e) {
log.error("Problems creating an XPathProcessor. " + e.getMessage(),e);
throw new XPathException(e.getMessage());
}
}
示例4: init
import net.sf.saxon.s9api.Processor; //导入方法依赖的package包/类
/**
* Initialization to improve performance for repetitive invocations of evaluate expressions
*
* @throws XQueryException
*/
private void init() throws XQueryException {
try {
// Get the processor
proc = new Processor(false);
// Set any specified configuration properties for the processor
if (featureMappings != null) {
for (Entry<String, Object> entry : featureMappings.entrySet()) {
proc.setConfigurationProperty(entry.getKey(), entry.getValue());
}
}
// Get the XQuery compiler
XQueryCompiler xqueryCompiler = proc.newXQueryCompiler();
xqueryCompiler.setEncoding(CharEncoding.UTF_8);
// Set the namespace to prefix mappings
this.setPrefixNamespaceMappings(xqueryCompiler, namespaceMappings);
// Compile the XQuery expression and get an XQuery evaluator
exp = xqueryCompiler.compile(xQueryExpression);
eval = exp.load();
// Create and initialize the serializer
baos = new ByteArrayOutputStream();
serializer = proc.newSerializer(baos);
// Appears ok to always set output property to xml (even if we are just returning a text string)
serializer.setOutputProperty(Serializer.Property.METHOD, "xml");
serializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION,"yes");
serializer.setProcessor(proc);
} catch (SaxonApiException e) {
log.error("Problems creating an XQueryProcessor. " + e.getMessage(),e);
throw new XQueryException(e.getMessage());
}
}