XPathException: Failed to load document

Help
Dayana
2011-08-08
2012-10-08
  • Dayana

    Dayana - 2011-08-08

    Hi! Well, Im using JDOM, SAXON and XERCES to transform xml docs, using
    stylesheets.

    The problem is, that during this transformation, I receive this error message:

    et.sf.saxon.trans.XPathException: Failed to load document
    C:\UMLR\tmp\3639122.xml.mod

    My transforming code, is:

        private Document transformar(Document docMOD, String xslt, Map<String, String> parametros) throws TransformerException {
            //Generamos la guia
            //System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
            TransformerFactory guia = TransformerFactory.newInstance();
            Configuration config = ((TransformerFactoryImpl)guia).getConfiguration();
            DocumentWrapper wrapper = new DocumentWrapper(docMOD, docMOD.getBaseURI(), config);
    
            System.out.println(docMOD.getBaseURI());
    
            //Preparamos los traductores
            Templates plantilla = guia.newTemplates(new StreamSource(xslt));
            Transformer conversor = plantilla.newTransformer();
            for(String clave : parametros.keySet()){
                conversor.setParameter(clave, parametros.get(clave));
            }
    
            //Transformamos
            JDOMResult resultado = new JDOMResult();
            conversor.transform(wrapper, resultado);
    
            return resultado.getDocument();
        }
    

    The line where the error pops up, is: conversor.transform(wrapper, resultado);

    Sorry for the newbie question, but I don't know what more to try.

    Thanks, hope to read some answers.

     
  • Michael Kay

    Michael Kay - 2011-08-08

    It's not clear from the information you have supplied, but I would think a
    likely explanation is that you have used a Windows filesname (such as
    C:\UMLR\tmp\3639122.xml.mod) in a context where a URI is expected. Some APIs
    tolerate this; Saxon typically doesn't. It should be written
    file:///c:/UMLR/tmp/3639122.xml.mod.

    It's also possible, of course (from the information given) that the file
    really doesn't exist.

     
  • Dayana

    Dayana - 2011-08-08

    Hi!

    Thanks for your answer. The System.out.println() prints this URI:
    file:///C:/UMLR/tmp/9129250.xml.mod
    Also, the file does exists, because I create it before in the program, and
    already checked that it is there when called.

    The other method where I read the doc, it is:

    String nombreArchivo = directorio + nro + ".xml";
                SAXBuilder constructor = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
                constructor.setFeature("[url]http://apache.org/xml/features/validation/schema[/url]", true);
                Document docMOD = constructor.build(nombreArchivo + ".mod");
    
     
  • Michael Kay

    Michael Kay - 2011-08-08

    I suspect that there are further diagnostics being written to System.err which
    perhaps you are not displaying. If this is the case, please either redirect
    System.err to some log file, or configure Saxon to write to a location other
    than System.err, perhaps by supplying your own JAXP ErrorListener. (or you
    could supply an instance of the Saxon StandardErrorListener in which you have
    called setErrorOutput() to direct the error messages perhaps to a file.

     
  • Dayana

    Dayana - 2011-08-09

    Hi again!

    Ok, I got all the error message, and it told, in an upper part, that the
    problem was in a line in the xslt file (still don't get why It result in an
    XPathException). Anyways, I got to track the problem.

    Thank you so much, this libs are so usefull.

     
  • Dayana

    Dayana - 2011-08-16

    Ok, the full system error message, is:

    Recoverable error on line 77 of PrimerMapeo.xslt:
    FODC0002: Exception thrown by URIResolver: Invalid relative URI
    {C:\UMLR\tmp\1020457.xml.mod}: Illegal character in opaque part at index 2:
    C:\UMLR\tmp\1020457.xml.mod
    Error on line 77 of PrimerMapeo.xslt:
    FODC0002: Failed to load document C:\UMLR\tmp\1020457.xml.mod
    ; SystemID: file:///D:/Mis%20documentos/FRSF/Beca%20I+D/2011/workspace/umlrela
    cional/files/PrimerMapeo.xslt; Line#: 77; Column#: -1
    net.sf.saxon.trans.XPathException: Failed to load document
    C:\UMLR\tmp\1020457.xml.mod
    at net.sf.saxon.expr.Expression.dynamicError(Expression.java:995)
    at net.sf.saxon.functions.Doc.doc(Doc.java:158)
    at net.sf.saxon.functions.Doc.evaluateItem(Doc.java:129)
    at net.sf.saxon.expr.Expression.iterate(Expression.java:393)
    at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:619)
    at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:619)
    at net.sf.saxon.expr.LazyExpression.iterate(LazyExpression.java:106)
    at net.sf.saxon.value.MemoClosure.iterate(MemoClosure.java:98)
    at net.sf.saxon.value.Value.getIterator(Value.java:119)
    at net.sf.saxon.expr.VariableReference.iterate(VariableReference.java:407)
    at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:344)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.LetExpression.process(LetExpression.java:409)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:269)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:269)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:269)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:269)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.LetExpression.process(LetExpression.java:409)
    at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:387)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:269)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.LetExpression.process(LetExpression.java:409)
    at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:387)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ForEach.processLeavingTail(ForEach.java:387)
    at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:567)
    at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:569)
    at net.sf.saxon.expr.instruct.Instruction.process(Instruction.java:123)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:318)
    at net.sf.saxon.expr.instruct.ElementCreator.processLeavingTail(ElementCreator
    .java:269)
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:208)
    at net.sf.saxon.expr.instruct.ApplyTemplates.applyTemplates(ApplyTemplates.jav
    a:368)
    at net.sf.saxon.Controller.transformDocument(Controller.java:1887)
    at net.sf.saxon.Controller.transform(Controller.java:1737)

    I got this error message AGAIN, when I did resolve the NullPointer one.

    What I am missing?

     
  • Michael Kay

    Michael Kay - 2011-08-16

    Failed to load document C:\UMLR\tmp\1020457.xml.mod

    The doc() function expects a URI, not a Windows filename. The URI
    corresponding to this filename is

    file:///c:/UMLR/tmp/1020457.xml.mod

     
  • Dayana

    Dayana - 2011-08-16

    I see, I was looking for the issue in the other function.

    Tried, and solved.

    Kinds regards.

     

Log in to post a comment.