Hi. Clarification on what I am trying to do is this:

I have a Document, but I need to validate it against a DTD.
So, I convert it into a String and feed the String into a StringReader.
The StringReader is passed in as the parameter for creating a SaxReader.

       // convert dom4j Document to String
        StringReader docIn = null;
        docIn = new StringReader(exportDocumentToString(doc));

       // read stringified document with validation turned on for SaxReader
instance
        boolean validateXML = true;
        SAXReader saxReader = new SAXReader(validateXML);
        try{
            saxReader.read(docIn);
        }
        catch(DocumentException ex){
            ex.printStackTrace();
        }

The Document's looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE doc PUBLIC "-//MiniEmily//DTD Standing XML Article V1.0//EN"
"StandingXML.dtd"><doc><processinfo><timestamp>Wed Feb 19 14:09:00 GMT
2003</timestamp>
-
-

org.dom4j.DocumentException: null Nested exception: null
      at org.dom4j.io.SAXReader.read(SAXReader.java:342)
Nested exception:
java.net.MalformedURLException
      at java.net.URL.<init>(URL.java:613)
      at java.net.URL.<init>(URL.java:476)

I've put the StandingXML.dtd where the calling class gets compiled to, but
to no avail. Any ideas?

Thanks,
Portia





|---------+---------------------------->
|         |           "James Strachan" |
|         |           <james_strachan@y|
|         |           ahoo.co.uk>      |
|         |                            |
|         |           19/02/2003 07:56 |
|         |                            |
|---------+---------------------------->
  
>---------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                           |
  |       To:       "Dom4j-User" <[EMAIL PROTECTED]>, 
<[EMAIL PROTECTED]>                         |
  |       cc:                                                                          
                           |
  |       Subject:  Re: [dom4j-user] Validating XML with DTD                           
                           |
  
>---------------------------------------------------------------------------------------------------------------|




From: <[EMAIL PROTECTED]>
> (BTW, I've already looked at the following mail:
> http://www.mail-archive.com/dom4j-dev@lists.sourceforge.net/msg00493.html
> and it didn't provide sufficient information for what I need.)
>
> Hi. I am currently doing the following:
>
>         Document standingXML =
> transformer.parseToStandingXML(generator.getDocument());
>         standingXML.addDocType("doc", "", "StandingXML.dtd");
>
> and then:

BTW if you look at your document via

        standingXML.asXML()

does it look right?


>         boolean validateXML = true;
>         SAXReader saxReader = new SAXReader(validateXML);
>         saxReader.setIncludeInternalDTDDeclarations(true);
>         saxReader.read(docIn);


> where "docIn" is "standingXML".

So is there a file called "standingXML" on your file system somewhere? Is
it
in the current directory, along with the DTD?


> However, I get the following exception:
>
> org.dom4j.DocumentException: null Nested exception: null
>       at org.dom4j.io.SAXReader.read(SAXReader.java:342)
>       at org.dom4j.io.SAXReader.read(SAXReader.java:256)
> Nested exception:
> java.net.MalformedURLException
>       at java.net.URL.<init>(URL.java:613)
>       at java.net.URL.<init>(URL.java:476)
>       at java.net.URL.<init>(URL.java:425)
>
> I've already put "StandingXML.dtd" into the location where I am compiling
> my class "X" so that it will be picked up, but this does not work.
> Any ideas? I am don't think I need to use the EntityResolver interface.

XML doesn't use the classpath by default to load XML files. If you want to
use the classpath or class loader mechanism then you need to pass in a URL
yourself.

e.g.

URL url = getClass().getClassLoader().getResource("standingXML.xml");
SAXReader reader = new SAXReader();
Document doc = reader.read( url );



James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com






**********************************************************************************
This email may contain confidential material. If you were not an
intended recipient, please notify the sender and delete all copies.
We may monitor email to and from our network.



-------------------------------------------------------
This SF.net email is sponsored by: SlickEdit Inc. Develop an edge.
The most comprehensive and flexible code editor you can use.
Code faster. C/C++, C#, Java, HTML, XML, many more. FREE 30-Day Trial.
www.slickedit.com/sourceforge
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to