<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:Arial;
        color:black;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
pre
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;
        font-weight:normal;
        font-style:normal;
        text-decoration:none none;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>I had a problem trying to use the SAXBuilder to
process an XML file that uses namespaces, and has XML Schema validation and
uses an EntityResolver to locate the schema files. The XML file also has a
DOCTYPE <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>declaration for an entity. (I mention all of
these in case one is known to cause problems.)<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>I’ve solved the problem (perhaps not in the best
way) but wanted to bring it to your attention in case it is a known or unknown
bug.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>I tried using the build( File), build( InputStream)
and build( InputSource), and all fail similarly. I have tested the
correct solution on the File and InputStream versions and they both work the
same.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>This is on the root element of my XML file.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>The XML file looks like:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><?xml version="1.0"
encoding="UTF-8"?><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><!DOCTYPE dmodule [<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><!NOTATION cgm SYSTEM "explorer.exe"><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><!ENTITY ICN-AE-A-000000-0-U8025-00536-A-01-1 <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> SYSTEM <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> "file:///c:/longfilename.cgm" NDATA
cgm><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>]><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><dmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
xsi:noNamespaceSchemaLocation="descriptSchema.xsd"<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
id="DMC-BICYCLEXXXAAA-AAA-D00-00-00-0000-041A-A_000-03.xml"><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><idstatus><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>…<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'></dmodule><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>My code is:<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> SAXBuilder saxb =
new SAXBuilder(<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
"org.apache.xerces.parsers.SAXParser", true); <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
DomEntityResolver der = new DomEntityResolver(<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
schemaDm, DomEntityResolver.VERBOSE ); <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> // the next
entry does not change the result <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> //
true fails in the same way as false<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
saxb.setExpandEntities( false ); <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
saxb.setFeature( "http://apache.org/xml/features/validation/schema",<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
true);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face=Arial><span style='font-size:
12.0pt'> </span></font><font size=2
color=black><span style='font-size:10.0pt;color:windowtext'>saxb.setProperty(
JAXPConstants.JAXP_SCHEMA_LANGUAGE, <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> JAXPConstants.W3C_XML_SCHEMA
);<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
saxb.setFeature( "http://xml.org/sax/features/namespaces", true );<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
saxb.setEntityResolver( der );<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> try<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> {<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>
doc = saxb.build( file ); <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> catch
(JDOMException e) { e.printStackTrace(); } <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'> catch
(IOException e) { e.printStackTrace(); }<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face=Arial><span style='font-size:
12.0pt'>Note: With the schema validation feature set to true and the
setProperty commented out, the EntityResolver is called at construction time,
and for each schema file, but each element is flagged as needing to be
declared. The text of the traceback is listed below. Note that it
includes references to an XMLDTDValidator</span></font><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red'> </span></font>object<font size=1 color=red face="Courier New"><span
style='font-size:8.0pt;font-family:"Courier New";color:red'>.</span></font><br>
<br>
With the schema validation feature commented out, and the setProperty in place,
the EntityResolver is not called, and there is no validation performed. (I
added invalid content to one of the files and there were no errors listed.)<br>
<br>
With both the setFeature and the setProperty in place, however, I get the calls
from the EntityResolver indicating that it is processing the schema files, and
for the good files, I get no errror, but for the bad file, I get an error
indicating a bad validation. <br>
<br>
<br>
<font size=2 color=black><span style='font-size:10.0pt;color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>In my DomEntityResolver, I’m getting a message
from the constructor, but no messages from the calls to resolveEntity().<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>In the traceback for the exception I’m troubled
by seeing the dtd.XMLDTDValidator.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'>Caused by: org.xml.sax.SAXParseException: Element
type "dmodule" must be declared.</span></font><font size=1
color=black face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)</span></font><font size=1 color=black face="Courier New"><span
style='font-size:8.0pt;font-family:"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
Source)</span></font><font size=1 color=black face="Courier New"><span
style='font-size:8.0pt;font-family:"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'>
scanRootElementHook(Unknown Source)</span></font><font size=1 color=black
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.<o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'>
dispatch(Unknown Source)</span></font><font size=1 color=black
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)</span></font><font size=1 color=black face="Courier New"><span
style='font-size:8.0pt;font-family:"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.parsers.XMLParser.parse(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at
org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal style='text-autospace:none'><font size=1 color=red
face="Courier New"><span style='font-size:8.0pt;font-family:"Courier New";
color:red;background:white'> at org.jdom.input.SAXBuilder.build(SAXBuilder.java:453)</span></font><font
size=1 color=black face="Courier New"><span style='font-size:8.0pt;font-family:
"Courier New";color:windowtext'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'>My first bypass was to create an org.w3c.dom.Document
and then use a DOMBuilder to convert the org.w3c.dom.Document into an
org.jdom.Document. <o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;color:windowtext'><o:p> </o:p></span></font></p>
<div>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt'>David R. Patterson</span></font><o:p></o:p></p>
<p class=MsoNormal><em><i><font size=2 color=black face=Arial><span
style='font-size:10.0pt;font-family:Arial'>Senior Software Engineer</span></font></i></em><o:p></o:p></p>
<p class=MsoNormal><font size=3 color=black face=Arial><span style='font-size:
12.0pt'><a href="mailto:dpatterson@i-a-i.com"><font size=2><span
style='font-size:10.0pt'>dpatterson@i-a-i.com</span></font></a><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt'>Intelligent Automation, Inc.</span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt'>(301) 294-4632</span></font><o:p></o:p></p>
</div>
<p class=MsoNormal><font size=3 color=black face=Arial><span style='font-size:
12.0pt'><o:p> </o:p></span></font></p>
</div>
</body>
</html>