[jdom-interest] RE: How to validate and convert a org.w3c.dom.Document

Eric Hartmann ehartmann at rhinfo.com
Tue Jun 19 09:32:31 PDT 2001


Hi,

I've browsed the archives to find a solution for this problem : I need to
validate  a org.w3c.dom.Document (against DTD or Schema which is in a jar
file) and convert this to org.jdom.Document.
I've found that I have to use EntityResolver (the schema is in a jar file)
and so a SAXBuilder. So I need to create a InputStream with a
org.w3c.dom.Document. In order to complete this I convert the document to
string with this :
public String DOMToString(org.w3c.dom.Document doc) {
            OutputFormat    format  = new OutputFormat( doc );   //Serialize
DOM
            StringWriter  stringOut = new StringWriter();        //Writer
will be a String
            XMLSerializer    serial = new XMLSerializer( stringOut,
format );
            serial.asDOMSerializer();                            // As a DOM
Serializer
            serial.serialize( doc.getDocumentElement() );
            return stringOut.toString() ;
}
And then use a StringReader. It seems to be a little bit complicated (but
DOM & SAX are complicated ;-) ), so is it the right way to complete this
task ?

Thanks in advance.

-Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20010619/9cbb5d2b/attachment.htm


More information about the jdom-interest mailing list