By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,058 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,058 IT Pros & Developers. It's quick & easy.

[java] how to create Schema object from DTD file?

P: n/a
Hi,

I can create a schema from xsd file:

Schema s =
SchemaFactory.newInstance(_XMLConstants.W3C_XML_SC HEMA_NS_URI_).newSchema(new
StreamSource(res.getInputStream()));

but when using XMLConstants.XML_DTD_NS_URI then an exception is thrown:

Schema s =
SchemaFactory.newInstance(_XMLConstants.XML_DTD_NS _URI_).newSchema(new
StreamSource(res.getInputStream()));

java.lang.IllegalArgumentException: http://www.w3.org/TR/REC-xml
at javax.xml.validation.SchemaFactory.newInstance(Unk nown Source)

I'm using xerces 2.7.1, do you know what's the matter?

Regards,
M

--
Marcin Cenkier [mailto_marcin.cenkier_at_cognifide_com]
Nov 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


Marcin Cenkier wrote:

but when using XMLConstants.XML_DTD_NS_URI then an exception is thrown:

Schema s =
SchemaFactory.newInstance(_XMLConstants.XML_DTD_NS _URI_).newSchema(new
StreamSource(res.getInputStream()));

java.lang.IllegalArgumentException: http://www.w3.org/TR/REC-xml
at javax.xml.validation.SchemaFactory.newInstance(Unk nown Source)


I don't think that is supported, see

<http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html>
whichs says:
"To be compliant with the spec, the implementation is only required
to support W3C XML Schema 1.0"
and
"Note that because the XML DTD is strongly tied to the parsing
process and has a significant effect on the parsing process, it is
impossible to define the DTD validation as a process independent from
parsing. For this reason, this specification does not define the
semantics for the XML DTD"
--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 23 '05 #2

P: n/a
Martin Honnen napisaƂ(a):
I don't think that is supported, see

<http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html>

whichs says:
"To be compliant with the spec, the implementation is only required to
support W3C XML Schema 1.0"
and
"Note that because the XML DTD is strongly tied to the parsing process
and has a significant effect on the parsing process, it is impossible to
define the DTD validation as a process independent from parsing. For
this reason, this specification does not define the semantics for the
XML DTD"


Yeah, I've seen it, but still I'm pretty sure that there must be a way
to validate xml using dtd?!? Maybe not by using Schema (which I thought
would be implemented in xerces).
I solved the problem by converting this dtd to xsd, but the question
remains...

Thanks,
M
--
Marcin Cenkier [mailto_marcin.cenkier_at_cognifide_com]
Nov 23 '05 #3

P: n/a
Marcin Cenkier wrote:
but still I'm pretty sure that there must be a way
to validate xml using dtd?!?


You can validate your XML code against a DTD while parsing.
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
Nov 23 '05 #4

P: n/a


Marcin Cenkier wrote:

Yeah, I've seen it, but still I'm pretty sure that there must be a way
to validate xml using dtd?!?


Yes, there is one but not with the API you are trying to use which was
added in Java 1.5 to allow schema validation.
If you want to validate against a DTD then you can do that by parsing an
XML document having a DOCTYPE declaration pointing to the DTD.
You simply need to set up the parser so that it does validation while
parsing, look into SAXParserFactory for instance where you can do
parserFactory.setValidating(true)
<http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/SAXParserFactory.html#setValidating(boolean)>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.