• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DTD Validation problem via Sax

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody,

I wrote a http servlet. My servlet getting xml requests over HTTP ,processing xml and sending back to client successfully. But there is a problem about validation via DTD.
I want to validate incoming xmls via DTD.
MY sample DTD : ADD_CLIENT.dtd :
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT ADD_SERVICE (MESSAGE_ID, XXX_SUBSCRIBER_ID,TEL_NUMBER)>
<!ELEMENT MESSAGE_ID (#PCDATA)>
<!ELEMENT XXX_SUBSCRIBER_ID (#PCDATA)>
<!ELEMENT TEL_NUMBER (#PCDATA)>


Sample Incoming xml :
<?xml version="1.0" encoding="UTF-8"?><ADD_SERVICE><MESSAGE_ID>309832903820923803282 308</MESSAGE_ID><XXX_SUBSCRIBER_ID>134523278</XXX_SUBSCRIBER_ID><TEL_NUMBER>03123445566</TEL_NUMBER></ADD_SERVICE>

But i am getting this exception constantly:

Error:
..
Line: 1
Error: Document root element "ADD_SERVICE", must match DOCTYPE root "null".|#]

..
Line: 1
Error: Document is invalid: no grammar found.|#]


I am changing my dtd and xml. But still i am getting same error. After getting this exception servlet continues its work properly.

Sample Code :


 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The system isn't finding your DTD. That's because you are providing only a relative path for it and making an incorrect assumption about what the current working directory is when you run that code.
 
alp carsikarsi
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing the path before using it. The path seems to be correct. ADD_CLIENT.dtd file is there !

System.out.println("path =" + new File(XML_DTD_PATH).getAbsolutePath());
inputSource.setSystemId(XML_DTD_PATH);


Result in server.log:

path =C:\sailfin\domains\fcsdomain\config\resources\ADD_CLIENT.dtd

Thanks.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The error messages pretty clearly indicate that your DTD isn't being seen. So now consider the fact that the InputSource.setSystemId method asks for a URL. You aren't passing it a URL. And also, you're supposed to be passing it the system ID of the XML document, not the location of the DTD. I think that would be the file:// URL for the directory containing the DTD.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a similar problem moving a stable app from Java 5 to Java 6. The DTD used to be resolved relative to the file system location from which the referencing document was opened. Now it is resolved relative to the location from which the application was started.

Edit: April 4. What I ended up doing was creating a EntityResolver and adding it to the DocumentBuilder.
 
reply
    Bookmark Topic Watch Topic
  • New Topic