[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)
            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

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

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
    at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
    at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown
    at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown
    at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
    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
    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