Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > [java] how to create Schema object from DTD file?

Reply
Thread Tools

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

 
 
Marcin Cenkier
Guest
Posts: n/a
 
      11-17-2005
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]
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-17-2005


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/
 
Reply With Quote
 
 
 
 
Marcin Cenkier
Guest
Posts: n/a
 
      11-17-2005
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]
 
Reply With Quote
 
Johannes Koch
Guest
Posts: n/a
 
      11-18-2005
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.)
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      11-18-2005


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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
New to xml schema - does the dtd/schema validation happens always ? pramodr XML 3 04-05-2009 12:10 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
How to specify DTD to DTD.getDTD for DocumentParser? Ronald Fischer Java 4 03-17-2005 09:37 AM
Removing the dtd name when using print(...) on the dtd generated class Joseph Tilian Java 0 12-21-2004 02:58 PM
Including a dtd into another dtd... possible? Asfand Yar Qazi XML 1 09-19-2003 12:10 PM



Advertisments