Project

Profile

Help

Problems reading file with SAXON

Added by Anonymous over 13 years ago

Legacy ID: #10594661 Legacy Poster: Dayana (leyre)

Ok, I already changed to an actual lib, and now I can't even read the xslt file, that was properly readed before (even getting back to the older version, gave me this error). Code: [code]import java.io.File; import java.io.IOException; import java.util.HashMap; import javax.xml.transform.Templates; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.transform.JDOMResult; import com.saxonica.config.ProfessionalConfiguration; import net.sf.saxon.Configuration; import net.sf.saxon.TransformerFactoryImpl; import net.sf.saxon.option.jdom.DocumentWrapper; import exception.TransformacionException; ... public void obtenerXML() throws TransformacionException { try { //Releemos el archivo String nombreArchivo = directorio + nro + ".xml.mod"; SAXBuilder constructor = new SAXBuilder(); Document docMOD = constructor.build(new File(nombreArchivo)); //Preparamos los transformadores String xslt = "/files/PrimerMapeo.xslt"; String xsd = "/files/Model.xsd"; //Transformamos Document docTPO = transformar(docMOD, xslt); ... private Document transformar(Document docMOD, String xslt) throws TransformerException { // Create a transform factory instance. TransformerFactory tfactory = TransformerFactory.newInstance(); // Create a transformer for the stylesheet. Transformer transformer = tfactory.newTransformer(new StreamSource(xslt)); // Transform the source XML to System.out. transformer.transform(new StreamSource(docMOD.getBaseURI()), new StreamResult(new File(directorio + nro + ".xml.tpo"))); return null; }[/code] OK, and the stackTrace: [quote]Recoverable error on line 0 column 0 SXXP0003: Error reported by XML parser: File "file:///files/PrimerMapeo.xslt" not found. Error I/O error reported by XML parser processing /files/PrimerMapeo.xslt: \files\PrimerMapeo.xslt (El sistema no puede hallar la ruta especificada) javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected. at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:199) at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:132) at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:87) at logica.transformadores.MapeoTiposOR.transformar(MapeoTiposOR.java:107)[/quote] The error is in here: Transformer transformer = tfactory.newTransformer(new StreamSource(xslt)); Please, avoid answers of the type that "the file could really not exists" because it is there, and not empty. Thanks, and I hope for some usefull answer.


Replies (4)

Please register to reply

RE: Problems reading file with SAXON - Added by Anonymous over 13 years ago

Legacy ID: #10594671 Legacy Poster: Dayana (leyre)

Wrong stacktrace, and I cant edit my post. This is the correct one: [quote]Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at org.apache.xerces.parsers.SAXParser.setContentHandler(SAXParser.java:874) at net.sf.saxon.Configuration.reuseStyleParser(Configuration.java:2346) at net.sf.saxon.PreparedStylesheet.loadStylesheetModule(PreparedStylesheet.java:261) at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:185) at net.sf.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:132) at net.sf.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:87) at logica.transformadores.MapeoTiposOR.transformar(MapeoTiposOR.java:106)[/quote] Line of error: Transformer transformer = tfactory.newTransformer(new StreamSource(Path.getPath("files/PrimerMapeo.xslt"))); What printsthe Path.getPath(): C:/Documents and Settings/Mis Documentos/ ... /files/PrimerMapeo.xslt (the ... where I cant put the full path)

RE: Problems reading file with SAXON - Added by Anonymous over 13 years ago

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

You seem to be reporting two separate problems here. Let's ignore the first "file not found" one, and concentrate on the NullPointerException, which certainly seems curious. The first thing is to establish which version of Saxon you are using. I can tell from the line numbers on the stack trace that it's not any of the last three major versions (9.1, 9.2, 9.3) On the other hand, it could be a problem with the version of Xerces. Saxon does call XMLReader.setContentHandler(null) to release resources, and it could be you are using a version of Xerces that throws an exception when this is done. But I think that recent release of Saxon will catch this exception and recover from it.

RE: Problems reading file with SAXON - Added by Anonymous over 13 years ago

Legacy ID: #10595915 Legacy Poster: Dayana (leyre)

Hi again. Well, I'm using the Saxon9.3 EE that I did download from the official site. You say that this is a Xerces issue? The libs I'm using currently to deal with the XML, are: JDOM, Saxon9EE, Xerces. What should I do, then? Thanks

RE: Problems reading file with SAXON - Added by Anonymous over 13 years ago

Legacy ID: #10597314 Legacy Poster: Dayana (leyre)

I upgraded my xerces version, and the problem stop, but I popped up the older one (already post a stack trace on the pertinen topic). Thanks so much, mhkay. Kinds regards.

    (1-4/4)

    Please register to reply