Michael Glavassevich wrote:
Dominic Brügger <[EMAIL PROTECTED]> wrote on 08/16/2006 07:56:19 AM:
How can I set up sax to resolve the include relative to the initial xml
file?
Relative URIs require a context for resolution. If you're passing the
parser an InputSource you need to set the system ID on this object. If you
don't
do this the parser will fallback to using the current working directory
(the value of the system property user.dir) as the base URI for resolution
since it has no idea where your document is located.
Thanks for your response Michael. I'm using the SAXParser to get an
XMLReader for a XSL transformation. In fact I'm using a filter chain to
process a series of stylesheets (see code below). Where can I set the
system ID for the XML file used as input for the transformation?
public void processXSLT(String inFile, String[] xslFiles, String outFile) {
try {
// Set up the input stream.
InputStream inputStream = new BufferedInputStream(new
FileInputStream(inFile));
InputSource input = new InputSource(inputStream);
// Set up the output stream.
OutputStream out = new BufferedOutputStream(new
FileOutputStream(outFile));
StreamResult result = new StreamResult(out);
// Set up a reader.
SAXParser parser = saxParserFactory.newSAXParser();
XMLReader reader = parser.getXMLReader();
// Set up the filter chain.
XMLFilter[] filters = new XMLFilter[xslFiles.length];
for (int i = 0; i < xslFiles.length; i++) {
Source source = new StreamSource(xslFiles[i]);
filters[i] = saxTransformerFactory.newXMLFilter(source);
if (i == 0) {
filters[i].setParent(reader);
} else {
filters[i].setParent(filters[i - 1]);
}
}
// Take the last filter as input of the transformation.
SAXSource transformSource = new
SAXSource(filters[filters.length - 1], input);
// Start XSLT transformation.
Transformer transformer =
saxTransformerFactory.newTransformer();
transformer.transform(transformSource, result);
// Clean up.
out.close();
catch (IOException ex) {
log.info("Error on processing chained XSL transformation: "
+ ex.getMessage());
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]