<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.5730.11" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=800504609-05012007><FONT face=Arial
color=#0000ff size=2>URLs do not allow non-ASCII characters; they must be
escaped using the %xx convention. The Javadoc for java.net.URL is worth reading.
In particular:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=800504609-05012007><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=800504609-05012007>
<P>The URL class does not itself encode or decode any URL components according
to the escaping mechanism defined in RFC2396. It is the responsibility of the
caller to encode any fields, which need to be escaped prior to calling URL, and
also to decode any escaped fields, that are returned from URL. Furthermore,
because URL has no knowledge of URL escaping, it does not recognise equivalence
between the encoded or decoded form of the same URL. For example, the two
URLs:<BR></P><PRE> http://foo.com/hello world/ and http://foo.com/hello%20world</PRE>would
be considered not equal to each other.
<P>Note, the <A title="class in java.net"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html"><CODE>URI</CODE></A>
class does perform escaping of its component fields in certain circumstances.
The recommended way to manage the encoding and decoding of URLs is to use <A
title="class in java.net"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html"><CODE>URI</CODE></A>,
and to convert between these two classes using <A
href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URL.html#toURI%28%29"><CODE>toURI()</CODE></A>
and <A
href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html#toURL%28%29"><CODE>URI.toURL()</CODE></A>.
</P>
<P>The <A title="class in java.net"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLEncoder.html"><CODE>URLEncoder</CODE></A>
and <A title="class in java.net"
href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLDecoder.html"><CODE>URLDecoder</CODE></A>
classes can also be used, but only for HTML form encoding, which is not the same
as the encoding scheme defined in RFC2396. </P>
<P><SPAN class=800504609-05012007><FONT face=Arial color=#0000ff size=2>In your
case you seem to be using the URL class solely in order to set the SystemID
property on a source, starting from a File object. For that I would use the
File.toURI() method, assuming you don't need to run on anything earlier than JDK
1.4</FONT></SPAN></P>
<P><SPAN class=800504609-05012007><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </P>
<P><SPAN class=800504609-05012007></SPAN><SPAN class=800504609-05012007><FONT
face=Arial color=#0000ff size=2>Michael Kay</FONT></SPAN></P>
<P><SPAN class=800504609-05012007><FONT face=Arial color=#0000ff size=2><A
href="http://www.saxonica.com/">http://www.saxonica.com/</A></FONT></SPAN></P></SPAN></DIV><BR>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> jdom-interest-bounces@jdom.org
[mailto:jdom-interest-bounces@jdom.org] <B>On Behalf Of
</B>Huma<BR><B>Sent:</B> 05 January 2007 08:20<BR><B>To:</B>
jdom-interest@jdom.org<BR><B>Subject:</B> [jdom-interest]
MalformedURLException<BR></FONT><BR></DIV>
<DIV></DIV>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? <BR><BR>Here is the
code snippet:<BR><BR> final String
DEF_ENC = "UTF-8"; <BR>
String str = new
String("ab\u00e4\u00df\u00f6");<BR>
String newStr = null;<BR> try
{<BR> newStr = new String(
str.getBytes(DEF_ENC), DEF_ENC);<BR> str
= "/home/huma/" + newStr + "/model.xml"; <BR>
String fileName = null;<BR>
fileName = new String(str.getBytes(DEF_ENC),
DEF_ENC);<BR> File file = new
File(fileName); <BR> File parent =
file.getParentFile();<BR> InputStream
iStream = null;<BR>
<BR> <BR>
iStream = new
FileInputStream(file);<BR>
InputSource is = new
InputSource(iStream);<BR>
if(parent != null)<BR>
{ <BR>
is.setSystemId(parent.toURL().toString());<BR>
}<BR>
SAXBuilder saxbuilder = new
SAXBuilder(true);<BR>
Document doc = saxbuilder.build (is);<BR>
Element root = doc.getRootElement();<BR>
String version =
root.getAttributeValue("schemaVersion");<BR>
System.out.println("version: " +
version);<BR> } <BR>
catch (FileNotFoundException e1) {<BR>
// TODO Auto-generated catch
block<BR>
e1.printStackTrace();<BR>
}<BR> <BR>
catch (UnsupportedEncodingException e)
{<BR> // TODO
Auto-generated catch block <BR>
e.printStackTrace();<BR>
} catch (MalformedURLException e) {<BR>
// TODO Auto-generated catch
block<BR>
e.printStackTrace();<BR> } catch
(JDOMException e) {<BR>
// TODO Auto-generated catch block <BR>
e.printStackTrace();<BR> } catch
(IOException e) {<BR>
// TODO Auto-generated catch block<BR>
e.printStackTrace();<BR>
}<BR> }<BR><BR><BR>This is the exception
I am getting: <BR><BR>java.net.MalformedURLException: no protocol:
model.dtd<BR> at
java.net.URL.<init>(URL.java:537)<BR> at
java.net.URL.<init>(URL.java:434)<BR> at
java.net.URL.<init>(URL.java:383)<BR> at
org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown
Source)<BR> at
org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown
Source)<BR> at
org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
<BR> at
org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown
Source)<BR> at
org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown
Source)<BR> at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument (Unknown
Source)<BR> at
org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)<BR> at
org.apache.xerces.parsers.XML11Configuration.parse(Unknown
Source)<BR> at org.apache.xerces.parsers.XMLParser.parse
(Unknown Source)<BR> at
org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown
Source)<BR> at
org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown
Source)<BR> at
org.jdom.input.SAXBuilder.build(SAXBuilder.java :453)<BR> at
ModelTest.main(ModelTest.java:47)<BR><BR><BR></BLOCKQUOTE></BODY></HTML>