[jdom-interest] EntityNodes

Christian Bjørnbak bjornbak at iuas.dk
Thu Apr 5 05:18:26 PDT 2001


I considering changing fra Xerces DOM to JDOM..

Trying to reading one of our existing XML files with:

        try {
            SAXBuilder builder = new SAXBuilder();

            Document doc = builder.build(new File("C:/temp/adm.xml"));

            XMLOutputter fmt = new XMLOutputter();
            fmt.output(doc, System.out);
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

Returns 

Error in building: org.jdom.Entity
org.jdom.JDOMException: Error in building: org.jdom.Entity
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:411)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:464)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:445)
        at
to.util.templatecache.test.DOMCacheTest.<init>(DOMCacheTest.java:38)
        at
to.util.templatecache.test.DOMCacheTest.main(DOMCacheTest.java:122)
Root cause: java.lang.ClassCastException: org.jdom.Entity
        at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:969)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:395)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:464)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:445)
        at
to.util.templatecache.test.DOMCacheTest.<init>(DOMCacheTest.java:38)
        at
to.util.templatecache.test.DOMCacheTest.main(DOMCacheTest.java:122)

I have tracked down that the following DOCTYPE declaration is the cause of
the error:

<!DOCTYPE template SYSTEM "template.dtd" [
	<!ENTITY % templateDTD SYSTEM "template.dtd">
	%templateDTD;
	<!ENTITY defaultData SYSTEM "defaultData.xml">
	<!ENTITY defaultErrorPages SYSTEM "errorPages.xml">
]>

The DOCTYPE declaration work when I parse it to a DOM in Xerces.. Hence I
think it a bug the SAXBuilder of JDOM..

I've recreated the bug using the personal.xml sample data from the Xerces
distribution:

personal.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE personnel [
	<!ENTITY % personalDTD SYSTEM "personal.dtd">
	%personalDTD;
	<!ENTITY fourworker SYSTEM "fourworker.xml">
	<!ENTITY fiveworker SYSTEM "fiveworker.xml">
]>
<personnel>
	<person id="Big.Boss">
		<name>
			<family>Boss</family>
			<given>Big</given>
		</name>
		<email>chief at foo.com</email>
		<link subordinates="one.worker two.worker three.worker
four.worker five.worker"/>
	</person>
	<person id="one.worker">
		<name>
			<family>Worker</family>
			<given>One</given>
		</name>
		<email>one at foo.com</email>
		<link manager="Big.Boss"/>
	</person>
	<person id="two.worker">
		<name>
			<family>Worker</family>
			<given>Two</given>
		</name>
		<email>two at foo.com</email>
		<link manager="Big.Boss"/>
	</person>
	<person id="three.worker">
		<name>
			<family>Worker</family>
			<given>Three</given>
		</name>
		<email>three at foo.com</email>
		<link manager="Big.Boss"/>
	</person>
	&fourworker;
	&fiveworker;
</personnel>

fourworker.xml:
<?xml version="1.0" encoding="UTF-8"?>
	<person id="four.worker">
		<name>
			<family>Worker</family>
			<given>Four</given>
		</name>
		<email>four at foo.com</email>
		<link manager="Big.Boss"/>
	</person>

fiveworker.xml
<?xml version="1.0" encoding="UTF-8"?>
<person id="five.worker">
	<name>
		<family>Worker</family>
		<given>Five</given>
	</name>
	<email>five at foo.com</email>
	<link manager="Big.Boss"/>
</person>

Can anyone help me? I would really like to make the shift for JDom!

/Christian Bjørnbak



More information about the jdom-interest mailing list