473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
4 4553


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
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
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


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Matt | last post by:
I'm new to Java but experienced with PL/SQL. I've found what appears to be strange behaviour (a bug?) when attempting to create java stored objects using the UNIX version of Oracle SQL*PLUS...
3
by: timothy ma and constance lee | last post by:
i have an xml file like <node type="Service" key="1"> <value>Title</value> </node> <node type="Service" key="2"> <value>CA</value> </node> Can java parse through the xml file to create an...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
7
by: Jorgen Haukland, Norway | last post by:
Hi, I have created a Java webservice which runs in IBM WebSphere appserver. I take the WSDL-file and create a VS.NET WinForm application and calls the service running on my PC and everything...
3
by: Dhananjayan | last post by:
Hi, I have a java webservice running on Axis, Iam able to create a java client to invoke the webservice and obtain the result. But iam not able to invoke the service from .Net client.. Here are...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
1
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.