K
Kenneth P. Turvey
I'm new to using XML in Java, so please forgive me if this is an easy
question.
I'm using NetBeans and I've written a unit test that just reads in an XML
document using the DocumentBuilder class. This is a document I've written
myself and I've written a DTD for it as well. So I would like it to be
validated while being read. So, I've called the setValidating(true)
method on the DocumentBuilderFactory before getting the DocumentBuilder
itself.
The problem is that I don't know what to do with the DTD file so that it
will be found when the document is being parsed. The DocumentBuilder
doesn't know where the xml file came from so the current directory doesn't
seem right. There doesn't seem to be anywhere to load the dtd file so
that the builder will be able to find it.
I'm getting the following error which says to me that this is the
problem, but maybe I'm misreading it.
org.xml.sax.SAXParseException:
Document root element "onlinequiz", must match DOCTYPE root "null".
I'm sure that many of you use this stuff all the time. How would you set
up a unit test to make sure a document is being parsed correctly? What do
you do with the DTD?
Thanks,
question.
I'm using NetBeans and I've written a unit test that just reads in an XML
document using the DocumentBuilder class. This is a document I've written
myself and I've written a DTD for it as well. So I would like it to be
validated while being read. So, I've called the setValidating(true)
method on the DocumentBuilderFactory before getting the DocumentBuilder
itself.
The problem is that I don't know what to do with the DTD file so that it
will be found when the document is being parsed. The DocumentBuilder
doesn't know where the xml file came from so the current directory doesn't
seem right. There doesn't seem to be anywhere to load the dtd file so
that the builder will be able to find it.
I'm getting the following error which says to me that this is the
problem, but maybe I'm misreading it.
org.xml.sax.SAXParseException:
Document root element "onlinequiz", must match DOCTYPE root "null".
I'm sure that many of you use this stuff all the time. How would you set
up a unit test to make sure a document is being parsed correctly? What do
you do with the DTD?
Thanks,