• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

validating xml against a DTD

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I validate XML against a DTD? I don't see how I am supposed to reference the DTD in my java code.
Thanks!
-carl
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Generally, you don't point to the DTD in the Java code, the XML document must refer to it, AND you must specify a validating parser in your Java code.
Sounds like you need a basic XML reference book - O'Reilly publishes a nice compact one.
Bill
------------------
author of:
 
carl jensen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your quick response.
Maybe I should clarify. My xml document (textXML in the code below) does specify the DTD, but I get an exception because the DTD cannot be found. Here is my code:
SAXBuilder builder = new SAXBuilder();
builder.setValidation(true);

// Create the document
StringReader xmlreader = new StringReader(testXML);
Document doc = builder.build(xmlreader);

When I run this code, I get the following exception:
org.jdom.JDOMException: Error on line 0: File "TXLife2.4.99.01.dtd" not found.
So, I guess the question is: How do I make my Java program aware of the location of my DTD?
I am using VAJ for my IDE.
Thanks!
 
carl jensen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have answered my own question. To specify the DTDs location on the hard drive, do the following:
<!DOCTYPE Xmlife SYSTEM "file:///c:/DTDs/TXLife2.4.99.01.dtd">
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic