[jdom-interest] Jdom DTD validation error state

Weiss, Arthur arthur.weiss at gs.com
Thu Feb 28 16:51:15 PST 2002


I am using Jdom Beta 7 and am validating an XML file against a DTD. If I
process an invalid file and Jdom reports an exception due to non-conformance
with the DTD, then I can't process a valid file afterwards without
restarting my process. It seems that Jdom remembers the error state and does
not clear it even though I am instantiating a new SaxBuilder with a
different valid XML file. For the valid file, Jdom reports some spurious
exception that an "Attribute value must be unique within a document". Has
anybody encountered this problem before? I get the same behavior even if I
substitute a later version of the Xerces parser than the one shipped with
Jdom. Following is a short program exhibiting this behavior. I can post the
valid and invalid XML files (together with the DTD) if needed. 
========================================================================
import java.io.*;

import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;

/**
 * <b><code>XMLparse</code></b> will parse an XML document for
 *  configuration information
 *
 */
public class XMLparse {
    private Document doc = null;
    private SAXBuilder builder1 = null;
    private SAXBuilder builder2 = null;

    public XMLparse ()
    {
        for (int i=0; i < 2; ++i)
            try {
                // Create the document (with validation)
                if (i == 1)
                {
	        // Jdom complains about the document even though it is valid
                    builder1 = new SAXBuilder(true);
                    doc = builder1.build(new File("XMLvalid.xml"));
                }
                else
                {
                    builder2 = new SAXBuilder(true);
                    doc = builder2.build(new File("XMLinvalid.xml"));
                }

                // Output the document, use standard formatter
                XMLOutputter fmt = new XMLOutputter();
                fmt.output(doc, System.out);
                System.out.println("\n\n");

            } catch (Exception e) {
                e.printStackTrace();
                if (e instanceof JDOMException )
                {
 
System.out.println(((JDOMException)e).getCause().getMessage());
                }
                else
                    System.out.println(e.getMessage());

            }
    }

    public static void main(String[] args)
    {
        new XMLparse();
    }
}



More information about the jdom-interest mailing list