net.sf.saxon.trans.XPathException with saxon8

Help
jhodgski2
2012-01-11
2012-10-08
  • jhodgski2

    jhodgski2 - 2012-01-11

    Hiya,

    I'm having trouble with the following code. It runs fine on my local
    development machine (jdk1.6.0_23) but when I upload to the web (jdk1.6.0_26),
    I get this error:

    net.sf.saxon.trans.XPathException: java.net.MalformedURLException: no
    protocol: %
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:424)
    at net.sf.saxon.event.Sender.send(Sender.java:193)
    at net.sf.saxon.event.Sender.send(Sender.java:50)
    at net.sf.saxon.Configuration.buildDocument(Configuration.java:2973)
    at org.w3c.mwi.mobileok.basic.XhtmlContent10.parseDOM(XhtmlContent10.java:334)
    at org.w3c.mwi.mobileok.basic.XhtmlContent10.<init>(XhtmlContent10.java:226)
    at org.w3c.mwi.mobileok.basic.MobileOKDecodedContentFactory.decodeContent(Mobi
    leOKDecodedContentFactory.java:64)
    at org.w3c.mwi.mobileok.basic.Resource.decode(Resource.java:243)
    at
    org.w3c.mwi.mobileok.basic.Preprocessor.processResource(Preprocessor.java:484)
    at org.w3c.mwi.mobileok.basic.Preprocessor.access$000(Preprocessor.java:33)
    at org.w3c.mwi.mobileok.basic.Preprocessor$2.run(Preprocessor.java:529)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.j
    ava:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:
    908)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: java.net.MalformedURLException: no protocol: %
    at java.net.URL.<init>(URL.java:567)
    at java.net.URL.<init>(URL.java:464)
    at java.net.URL.<init>(URL.java:413)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity
    (XMLEntityManager.java:650)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEnt
    ityManager.java:1315)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDTDEntity(XML
    EntityManager.java:1282)
    at com.sun.org.apache.xerces.internal.impl.XMLDTDScannerImpl.setInputSource(XM
    LDTDScannerImpl.java:283)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.di
    spatch(XMLDocumentScannerImpl.java:1194)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.ne
    xt(XMLDocumentScannerImpl.java:1090)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver
    .next(XMLDocumentScannerImpl.java:1003)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocu
    mentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNS
    DocumentScannerImpl.java:140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scan
    Document(XMLDocumentFragmentScannerImpl.java:511)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Co
    nfiguration.java:808)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Co
    nfiguration.java:737)
    at
    com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Abstract
    SAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(S
    AXParserImpl.java:522)
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:404)
    ... 13 more

        /**
         * Parses the given string as XML and returns the corresponding DOM
         * <code>Document</code>.
         * 
         * <p>The function uses Saxon's extended DOM implementation to be
         * able to retrieve the line number where a given node appears in
         * the original string. In particular, the returned Document may
         * be casted to the <code>net.sf.saxon.om.DocumentOverNodeInfo</code>
         * class.</p> 
         * 
         * @param body XML string to parse.
         * @return     the DOM Document representation of the XML string,
         *             <code>null</code> when the string is not valid XML.
         * @throws TestException an unexpected error occurred.
         */
        private Document parseDOM(final String body) throws TestException {
            if (body == null) {
                return null;
            }
    
            try {
                // Use Saxon's ability to track line numbers
                // Note that we cannot use the DocumentBuilderImpl class provided
                // by Saxon because of an existing bug that prevents the use of
                // and entity resolver, see discussion and bug at:
                // [url]https://sourceforge.net/mailarchive/message.php?msg_name=209D7731E68043DC8F6695AF79CD6397@Sealion[/url]
                // [url]https://sourceforge.net/tracker/?func=detail&aid=2995298&group_id=29872&atid=397617[/url]
    
                // Activate line numbering
                final Configuration config = new Configuration();
                config.setLineNumbering(true);
                config.setStripsWhiteSpace(Whitespace.NONE);
    
                // Force local resolution of entities in the document
                final XMLReader xmlReader = config.getSourceParser();
                final EntityResolver resolver = new ExtendedCatalogResolver(new XHTMLCatalogResolver());
                xmlReader.setEntityResolver(resolver);
    
                // Create source
                final InputSource stringSource = new InputSource(new StringReader(body));
                final SAXSource saxSource = new SAXSource(xmlReader, stringSource);
    
                // Parse document and wrap it into a DOM document
                final DocumentInfo docInfo = config.buildDocument(saxSource); // ** This line throws the exception **
                final Document doc = (Document)DocumentOverNodeInfo.wrap(docInfo);
                return doc;
            } catch (XPathException e) {
                // A parse error occurred. The document cannot be parsed because
                // it's a not a valid XML file.
                if ((e.getCause() != null)
                        && (e.getCause() instanceof IOException)) {
                    throw new TestException(e.getCause());
                }
                return null;
            }
        }
    

    Does anyone have any ideas what the problem could be? The strack trace
    suggests maybe there's an issue with the DTD, but how to solve??

    Many thanks in advance,
    James

     
  • Michael Kay

    Michael Kay - 2012-01-11

    Firstly, "saxon8" refers to a sequence of 10 major releases (8.0, 8.1,,, 8.9)
    issued over a period of about four years between 2004 and 2008. The current
    release is 9.4.

    All I can really tell you from this information is that you have called
    Configuration.buildDocument() from your application supplying a Source object
    that wraps a URI which Java considers invalid. This URI is probably generated
    by your ExtendedCatalogResolver.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks