473,804 Members | 3,174 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi,

I can create a schema from xsd file:

Schema s =
SchemaFactory.n ewInstance(_XML Constants.W3C_X ML_SCHEMA_NS_UR I_).newSchema(n ew
StreamSource(re s.getInputStrea m()));

but when using XMLConstants.XM L_DTD_NS_URI then an exception is thrown:

Schema s =
SchemaFactory.n ewInstance(_XML Constants.XML_D TD_NS_URI_).new Schema(new
StreamSource(re s.getInputStrea m()));

java.lang.Illeg alArgumentExcep tion: http://www.w3.org/TR/REC-xml
at javax.xml.valid ation.SchemaFac tory.newInstanc e(Unknown Source)

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

Regards,
M

--
Marcin Cenkier [mailto_marcin.c enkier_at_cogni fide_com]
Nov 23 '05 #1
4 4577


Marcin Cenkier wrote:

but when using XMLConstants.XM L_DTD_NS_URI then an exception is thrown:

Schema s =
SchemaFactory.n ewInstance(_XML Constants.XML_D TD_NS_URI_).new Schema(new
StreamSource(re s.getInputStrea m()));

java.lang.Illeg alArgumentExcep tion: http://www.w3.org/TR/REC-xml
at javax.xml.valid ation.SchemaFac tory.newInstanc e(Unknown Source)


I don't think that is supported, see

<http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.h tml>
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.h tml>

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.c enkier_at_cogni fide_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 SAXParserFactor y for instance where you can do
parserFactory.s etValidating(tr ue)
<http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/SAXParserFactor y.html#setValid ating(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
5750
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 8.1.7.3.0 with JServer 8.1.7.3.0. The reason it seams strange is that the problem only occurs with the UNIX version of SQL*PLUS, not the PC client version running on Windows 2000 but connected to the same database and schema. Can anyone shed any light...
3
2738
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 object like
11
9281
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 C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
6
2595
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 schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
7
3097
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 works fine. So I deploy the webservice on a remote machine (Linux box) and I get an error when calling the service. BUT: I can retrieve the WSDL and make a webreference in my VS.NET project, so obviously I (or more correct: My VS.NET project) am...
3
2203
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 the steps i followed to create a .net client I created a web reference("NetClient") for a webservice running in Axis thru "Add Web Reference", it created succesfully. The next step I should do in order to invoke the service is to
2
6971
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 attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
1
4310
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 Linux there is an error. The code that fails is the following: SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); I´m sure that code is ok. In fact, I´ve found that in several...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10320
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.