• 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

Processing xml inputsources from servlets

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using a jaxp SaxParer to parse an inbound XML document. My servlet works properly when I don't actually use a validating parser- but validation against a DTD is a requirement. The DTD on the inbound document has the following syntax:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE FOO_BAR SYSTEM "FOO_BAR.dtd">
<FOO_BAR>
ect ect
So the DTD is expected to be at the server's location(somewhere)- when I run it using the SAXParser I get a Saxparser exception saying that it cannot resolve the document without a proper URI reference.
So my question is- how do I get the DTD registered with my servlet so that the parser knows where the physical file is residing. I've tried adding it to the classpath, but it doesn't work.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should probably give an absolute path "file:\\c:\MyDocs\DTDs\employee.dtd" or just "c:\MyDocs\DTDs\employee.dtd" in the DOCTYPE declaration. Be careful about the path separator character which is OS-specific.
Alternatively, you can put it on a location visible from your intranet and use standard http way ( http:\\Yoursite\files\employee.dtd ) to reference it in the DOCTYPE declaration.
I'm 100% sure the second approach works, but I haven't tried the first one.
Just give it a try!!
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
IBM Certified Developer - XML and Related Technologies, V1.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just realized, you can try hosting the DTD file in the home directory of your Servlet.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help.
Unfortunately, I have no control over the DTD reference on the inbound document. People sending these documents will not code the reference for our server-it is based on an XML standard, and accordingly, we are expected to validate it against the most recent copy of the DTD on our server. These people will be sending these XML documents to people that are implementing the same standard. I tried adding it to my servlets home directory(I'm running apache/tomcat)- but it didn't work. Is there a way to programmatically link the dtd file to a reference in the java program?
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not have a lot of experience but I think I can answer this question.
What worked for me was to put the dtds in the 'bin' directory of tomcat.
Hope it works for you.
Sanjay
pleased at being able to actually *offer* a suggestion
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way to do this is to tweak the incoming XML and add a DOCTYPE declaration referencing your local(latest) DTD..
Not a very elegant way, but it works
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ajith
All your URI slashes are wrong. No matter which platform, only forward slashes are used.
I'm struggling with the problems, and find either http:// url and file:// url will work, file URL must be absolute; the path in tomcat relative to webapps will not work. My difficulties are opposite to the above, since I don't know the client site URL or absolute path in advance.
I'll try entity resolver to solve the problems or tweak the xml before parsing. I don't like either one of them, but it seems no other choices.
If any of you have a better solution, please let me know ASAP. Huge thanks in advance!
Roseanne
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved my own problem now. Thanks!
 
reply
    Bookmark Topic Watch Topic
  • New Topic