Project

Profile

Help

StAX transformation

Added by Anonymous over 19 years ago

Legacy ID: #3187212 Legacy Poster: hitman2005 (hitman2005)

Where can I find an example of a StAX transformation in Java? Is it different from a SAX transformation?


Replies (7)

Please register to reply

RE: StAX transformation - Added by Anonymous over 19 years ago

Legacy ID: #3187253 Legacy Poster: Michael Kay (mhkay)

StAX is only supported to a limited extent in Saxon 8.4, the reason being that until the recent Sun parser release, all StAX parsers I tested on were very buggy. Also, performance testing shows no particular benefits yet, though this may change in the future. There are examples showing how to use a StAX parser with XSLT and XQuery in PullExamples.java in the samples/java directory. Michael Kay

RE: StAX transformation - Added by Anonymous over 19 years ago

Legacy ID: #3187424 Legacy Poster: hitman2005 (hitman2005)

Thank you for your advice, I appreciated it very much. Could I make two questions about it? First: if someone has created a tree structure using StAX may I use SAX transformation for that tree? I mean may I use the following transformation without problem? File xml = new File(xmlti); File xsl = new File(xslt); File fine = new File(xmltf); // System.setProperty("javax.xml.transform.TransformerFactory","net.sf.saxon.TransformerFactoryImpl"); TransformerFactory tfactory = TransformerFactory.newInstance(); StreamSource xslSource = new StreamSource(xsl.toURI().toString()); // Create a transformer for the stylesheet. Transformer transformer = tfactory.newTransformer(xslSource); StreamSource xmlSource = new StreamSource(xml.toURI().toString()); StreamResult result = new StreamResult(fine); // Transform the source XML to System.out. transformer.transform(xmlSource, result); Second: the program I made, throws the following exceptions when I launch the former transformation: what it is expected me to do? java.lang.NoSuchMethodError: javax.xml.parsers.SAXParserFactory.getSchema()Ljavax/xml/validation/Schema; at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.<init>(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl.newSAXParser(Unknown Source) at net.sf.saxon.Configuration.getStyleParser(Configuration.java:739) at net.sf.saxon.PreparedStylesheet.loadStylesheetModule(PreparedStylesheet.java:175) at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:114) at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:124) at batch.Log.FileXslMergiati(Log.java:604) at batch.Log.Merge(Log.java:212) at batch.Log.PreparaFileLog(Log.java:722) at batch.Log.run(Log.java:64)

RE: StAX transformation - Added by Anonymous over 19 years ago

Legacy ID: #3187503 Legacy Poster: Michael Kay (mhkay)

Your first question: a Saxon tree (NodeInfo) created using a StAX parser looks just like a tree created any other way, and can be used interchangeably. But in your Java code, I don't see where the StAX-created tree comes into it. Your second question: the class javax.xml.validation/Schema is part of the JAXP 1.3 API, so this must be on your classpath. This will automatically be the case with JDK 1.5, but with 1.4 you need to install it as an add-on. You don't seem to be using schema-aware Saxon (for that you would need to set the TransformerFactory property to "com.saxonica.SchemaAwareTransformerFactory") so it seems to be Xerces that is asking for this class, not Saxon.

RE: StAX transformation - Added by Anonymous over 19 years ago

Legacy ID: #3187668 Legacy Poster: hitman2005 (hitman2005)

I use a file xml that is created with a StAX Parser so I thought that using it with a normal SAX Transformation doesn't work. A question: is there a condition implemented in Saxon to translat the conditions -mx512M -DentityExpansionLimit=128000 in the following instruction? I use jdk1.4 and saxon.jar java -mx512M -DentityExpansionLimit=128000 -jar lib/saxon.jar access-sorted.xml results/$QUERY_NAME/query.xsl > results/$QUERY_NAME/$day-sessions.xml~ Thank you very much Marco

RE: StAX transformation - Added by Anonymous over 19 years ago

Legacy ID: #3187682 Legacy Poster: Michael Kay (mhkay)

Your messages are very confusing. Parsers don't create XML files, they read and analyze them. Why should Saxon care how you created your XML file anyway? So long as it's XML, it's fine. I think that by -mx512M you mean -Xmx512m. This is an instruction to the Java interpreter to allocate 512Mb of memory. Saxon doesn't need to know about this, it just uses the memory that Java has allocated. The -DentityExpansionLimit=128000 sets a Java system property. Any class in the Java VM can read these properties. Saxon isn't interested in this property, but it's used by the XML parser (by some XML parsers, anyway). Saxon invokes the XML parser to parse the XML, it doesn't do this job itself.

RE: StAX transformation - Added by Anonymous over 19 years ago

Legacy ID: #3187689 Legacy Poster: hitman2005 (hitman2005)

I forgot : I didn't know that I wasn't used Saxon so I set the property System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); and since I use Jbuilder 8 I added a new requested library sax with the path where I stored saxon.jar. Why does it look for using xerces and not saxon?

RE: StAX transformation - Added by Anonymous over 19 years ago

Legacy ID: #3187733 Legacy Poster: Michael Kay (mhkay)

Saxon is an XSLT processor, Xerces is an XML Parser. Saxon does not parse XML itself, it uses an XML parser to do the job. By default under JDK 1.5 it loads Xerces.

    (1-7/7)

    Please register to reply