Try looking in the API docs for SAXReader:

public Document <http://dom4j.org/apidocs/org/dom4j/Document.html> *read*(InputStream <http://java.sun.com/products/jdk/1.3/docs/api/java/io/InputStream.html> in, String <http://java.sun.com/products/jdk/1.3/docs/api/java/lang/String.html> systemId) throws DocumentException <http://dom4j.org/apidocs/org/dom4j/DocumentException.html>

|@param systemId| is the base URI for the input

I think dom4j uses whichever parser it finds in your classpath. If you have Crimson AND Xerces, I'm not sure how you specify,
but I know it is possible. Seems like dom4j.org has info on it.






Samuel Cheung wrote:

Thanks Brain,

But could you please tell me how can I set the base URL for the SAX reader?
And how can I switch to use Xerces parser instead of crimson?


The file.getContents() gives me an input stream of the xml file. I have to use this call since I am work on a plugin for an IDE and I get the object 'file' from the IDE framework.

Thanks for your help again.


-----Original Message----- From: Brian W. Young [mailto:[EMAIL PROTECTED] Sent: Thursday, February 27, 2003 7:52 AM To: Samuel Cheung Cc: [EMAIL PROTECTED] Subject: Re: [dom4j-user] SAX Parse Exception


The error message is pretty accurate- since you're not loading your doc from a URL, there is no base URL to derive the relative URL of your DTD. What does file.getContents() do? If it is just loading the contents of the file from disk into a string or something, you'd be better off just passing a URL to the sax reader. Otherwise I believe you are able to set a base URL on the sax reader for entity resolution, you might give that a shot.

Samuel Cheung wrote:

> Hi,
>
> I have the follow code to parse a file, and my file reference an
> external DTD ../style/modulesynopsis.dtd like this:
>
> <?xml version="1.0"?>
> <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
> ....
>
> but I got an Nested exception: org.xml.sax.SAXParseException: Relative
> URI "../style/modulesynopsis.dtd"; can not be resolved without a base URI.
>
> Could some one please tell me what did I miss?
> And How can I switch to use xerces instead of crimson parser?
>
> Thanks for any help
>
>
> <<<<<<< My code >>>>>>>>>>>>
>
> SAXReader reader = new SAXReader( DOMDocumentFactory.getInstance() );
> try {
> Document document = reader.read(
> file.getContents() );
> } catch (Exception e) {
> }
>
> << complete Exception >>>
> Nested exception: org.xml.sax.SAXParseException: Relative URI
> "../style/modulesynopsis.dtd"; can not be resolved without a base URI.
>
> at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
> at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3176)
> at
> org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2758)
> at
> org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2730)
> at
> org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1129)
> at
> org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
> at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
> at
> org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
> at org.dom4j.io.SAXReader.read(SAXReader.java:323)
> at org.dom4j.io.SAXReader.read(SAXReader.java:24
>






-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to