[jdom-interest] MalformedURLException

Huma tahir.huma at gmail.com
Fri Jan 5 00:19:56 PST 2007


I have a model.xml file which I have placed in a directory /home/huma/abäßö.
But when I parse this file I get a MalformedURLException. Strangely, if the
same file is moved to the location /home/huma, I don't get any exception. To
summarize, if the xml file is in some directory that contains non-english
characters, I am getting a MalformedURL exception. Is there some
work-around? Can someone help me with this?

Here is the code snippet:

        final String DEF_ENC = "UTF-8";
        String str = new String("ab\u00e4\u00df\u00f6");
        String newStr = null;
        try {
        newStr = new String(str.getBytes(DEF_ENC), DEF_ENC);
        str = "/home/huma/" + newStr + "/model.xml";
        String fileName = null;
        fileName = new String(str.getBytes(DEF_ENC), DEF_ENC);
        File file = new File(fileName);
        File parent = file.getParentFile();
        InputStream iStream = null;


            iStream = new FileInputStream(file);
            InputSource is = new InputSource(iStream);
            if(parent != null)
            {
                is.setSystemId(parent.toURL().toString());
            }
            SAXBuilder saxbuilder = new SAXBuilder(true);
            Document doc = saxbuilder.build(is);
            Element root = doc.getRootElement();
            String version = root.getAttributeValue("schemaVersion");
            System.out.println("version: " + version);
        }
        catch (FileNotFoundException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JDOMException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }


This is the exception I am getting:

java.net.MalformedURLException: no protocol: model.dtd
    at java.net.URL.<init>(URL.java:537)
    at java.net.URL.<init>(URL.java:434)
    at java.net.URL.<init>(URL.java:383)
    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown
Source)
    at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown
Source)
    at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown
Source)
    at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown
Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)
    at ModelTest.main(ModelTest.java:47)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20070105/57f10189/attachment.htm


More information about the jdom-interest mailing list