Hello there
I tried for several days to get a simple validation with xml schema &
xerces working. Goal for me is tuse JAXP and not specific Xerces
classes. I don't get the point what I am doing wrong. Could somebody
help me? I didn't find any full example working on the net. Thank you
for any hints!
If I run the examples below, the parsers parses the file well, no
vlaidation is occuring although the schema and xml file does not
match.
I tried with the JAXP standard procedure, it does not work, why ?
File f = new File("dvd.xml") ;
SAXParserFactor y saxFactory = SAXParserFactor y.newInstance() ;
saxFactory.setN amespaceAware(t rue);
saxFactory.setV alidating(true) ;
SAXParser saxParser = saxFactory.newS AXParser();
saxParser.parse (f, new DefaultHandler( ));
I tried with activating additional SAX Features, does also not work,
why ?
File f = new File("dvd.xml") ;
SAXParserFactor y saxFactory = SAXParserFactor y.newInstance() ;
saxFactory.setN amespaceAware(t rue);
saxFactory.setV alidating(true) ;
saxFactory.setF eature("http://xml.org/sax/features/validation",tru e);
saxFactory.setF eature("http://apache.org/xml/features/validation/schema",true);
saxFactory.setF eature("http://apache.org/xml/features/validation/schema-full-checking",true) ;
SAXParser saxParser = saxFactory.newS AXParser();
saxParser.parse (f, new DefaultHandler( ));
Here is my xml:
<?xml version="1.0" encoding="utf-8" ?>
<dvd xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespace SchemaLocation= "dvd.xsd" id="33" available="3">M atrix
Revolutions</dvd>
Here is my xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="dvdi" type="xs:string "/>
<xs:attribute name="id" type="xs:string "/>
<xs:attribute name="available " type="xs:boolea n"/>
</xs:schema> 4 5609 jo**@bluewin.ch (joes) writes: Hello there
I tried for several days to get a simple validation with xml schema & xerces working. Goal for me is tuse JAXP and not specific Xerces classes. I don't get the point what I am doing wrong. Could somebody help me? I didn't find any full example working on the net. Thank you for any hints!
Before you call SAXParserFactor y.newInstance() you need to configure
the implementation lookup mechanism to use Xerces (the current JDK
1.4.x default is to use the Crimson parser).
One method (see the javadoc for the SAXParserFactor y.newInstance()
method) would be to set a system property, from the command line using
-D, or in the code:
System.setPrope rty("javax.xml. parsers.SAXPars erFactory",
"org.apache.xer ces.jaxp.SAXPar serFactoryImpl" );
You need to do this in addition to having the xerces jar files in your classpath.
Nigel
Thank you Nigel
But this is not the case. I do have already the xerces activated for
my application. By the way you have not to configure this by using
system properties. You can use the Jar service Provider Service
mechanism. Means you have just to include xerces in the class path
that's all.
I still not have a solution for my issue above, so has someone a
solution how to activate xml schema validation in xerces by using only
JAXP and not xerces specific classes ?
thank you
regards
mark
Nigel Whitaker <ni************ @deltaxml.com> wrote in message news:<m2******* *****@Nigel-Whitakers-Computer.local> ... jo**@bluewin.ch (joes) writes:
Hello there
I tried for several days to get a simple validation with xml schema & xerces working. Goal for me is tuse JAXP and not specific Xerces classes. I don't get the point what I am doing wrong. Could somebody help me? I didn't find any full example working on the net. Thank you for any hints!
Before you call SAXParserFactor y.newInstance() you need to configure the implementation lookup mechanism to use Xerces (the current JDK 1.4.x default is to use the Crimson parser).
One method (see the javadoc for the SAXParserFactor y.newInstance() method) would be to set a system property, from the command line using -D, or in the code:
System.setPrope rty("javax.xml. parsers.SAXPars erFactory", "org.apache.xer ces.jaxp.SAXPar serFactoryImpl" );
You need to do this in addition to having the xerces jar files in your classpath.
Nigel
Ok I found the solution by myself...
Please refer to: http://xml.apache.org/~edwingo/jaxp-...es.html#Schema
After that I simple tried the following JAXP, SAX & DOM solutions
which work.
While this is not documented at the Xerces Homepage in detail, I don't
expect that this is working in any further releases, so be careful.
For SAX, you have to use especially the underlying xmlReader with the
saxparser interface from sun it is not working.
File f = new File("dvd.xml") ;
SAXParserFactor y saxFactory = SAXParserFactor y.newInstance() ;
saxFactory.setN amespaceAware(t rue);
saxFactory.setV alidating(true) ;
saxFactory.setF eature("http://apache.org/xml/features/validation/schema",
true );
SAXParser saxParser = saxFactory.newS AXParser();
XMLReader xmlReader = saxParser.getXM LReader();
xmlReader.parse (f.getAbsoluteP ath());
A DOM solution would look and work like this:
DocumentBuilder Factory dbf = DocumentBuilder Factory.newInst ance();
dbf.setAttribut e("http://apache.org/xml/features/validation/schema",
Boolean.TRUE);
dbf.setNamespac eAware(true);
dbf.setValidati ng(true);
DocumentBuilder db = dbf.newDocument Builder();
db.parse(f);
don't give up...we are just at the beginning
regards
Mark Egloff jo**@bluewin.ch (joes) wrote in message news:<26******* *************** ****@posting.go ogle.com>... Hello there
I tried for several days to get a simple validation with xml schema & xerces working. Goal for me is tuse JAXP and not specific Xerces classes. I don't get the point what I am doing wrong. Could somebody help me? I didn't find any full example working on the net. Thank you for any hints!
If I run the examples below, the parsers parses the file well, no vlaidation is occuring although the schema and xml file does not match.
I tried with the JAXP standard procedure, it does not work, why ?
File f = new File("dvd.xml") ; SAXParserFactor y saxFactory = SAXParserFactor y.newInstance() ; saxFactory.setN amespaceAware(t rue); saxFactory.setV alidating(true) ; SAXParser saxParser = saxFactory.newS AXParser(); saxParser.parse (f, new DefaultHandler( ));
I tried with activating additional SAX Features, does also not work, why ?
File f = new File("dvd.xml") ; SAXParserFactor y saxFactory = SAXParserFactor y.newInstance() ; saxFactory.setN amespaceAware(t rue); saxFactory.setV alidating(true) ; saxFactory.setF eature("http://xml.org/sax/features/validation",tru e); saxFactory.setF eature("http://apache.org/xml/features/validation/schema",true); saxFactory.setF eature("http://apache.org/xml/features/validation/schema-full-checking",true) ; SAXParser saxParser = saxFactory.newS AXParser(); saxParser.parse (f, new DefaultHandler( ));
Here is my xml:
<?xml version="1.0" encoding="utf-8" ?> <dvd xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" xsi:noNamespace SchemaLocation= "dvd.xsd" id="33" available="3">M atrix Revolutions</dvd>
Here is my xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="dvdi" type="xs:string "/> <xs:attribute name="id" type="xs:string "/> <xs:attribute name="available " type="xs:boolea n"/> </xs:schema>
"joes" <jo**@bluewin.c h> wrote in message
news:26******** *************** **@posting.goog le.com... A DOM solution would look and work like this:
DocumentBuilder Factory dbf = DocumentBuilder Factory.newInst ance(); dbf.setAttribut e("http://apache.org/xml/features/validation/schema", Boolean.TRUE); dbf.setNamespac eAware(true); dbf.setValidati ng(true); DocumentBuilder db = dbf.newDocument Builder(); db.parse(f);
Sun's JAXP tutorial includes a more complete example along these lines. The
section "Reading XML Data into a DOM" illustrates necessary imports and
error handling. See URL: http://java.sun.com/j2ee/1.4/docs/tu.../JAXPDOM3.html
Section "Validating with XML Schema" is at URL: http://java.sun.com/j2ee/1.4/docs/tu...8.html#wp76446
/kmc This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bugbear |
last post by:
Subject pretty much says it all. I'd like to
parse XML (duh!) using Xerces (because its fast,
and reliable, and comprehensive, and supports lots
of features).
I'd like to conform to standards as much as possible,
so I'd like to call Xerces under the JAXP API.
I'd like to validate the XML against a DTD, so that
errors are flagged up to the user, and I can transcribe
|
by: Thomas Scheffler |
last post by:
Hi,
I use the Xerces SAXParser to read my documents in Java. For that I
wrote an EntityResolver so that the parse can use a schema to validate
them. Now that is the problem. The parser does never call my
EntityResolver and so gives out an error message
INFO SystemID: ./xyz-01.xml
INFO PublicID: null
|
by: Olaf Meyer |
last post by:
Apprentently xerces 2.6.0 (Java) does not validate against contraints
specified in the schema (e.g. constraints specified via unique element).
The validation works with the XML editor I'm using (XMLSpy4) but not
with Xerces 2.6.0.
I've included a really short and simple example to illustrate it. I
would like to get some comments on the validation capabilities of Xerces
2.6.0. I though it *fully* supported W3C Schema!
|
by: benoit |
last post by:
Hi,
When it's written in WebLogic Server 8.1 documentation that this
software is based on JDK 1.4.1, and is JAXP 1.1 compliant,
(http://edocs.bea.com/wls/docs81/xml/xml_intro.html#189256),
does it mean that only JAXP 1.1 can be used (and therefore the latest
Xerces and Xalan releases are forbidden, because JAXP 1.2 compliant),
or with the famous "Endorsed Standards Override Mechanism"...
|
by: Nuno |
last post by:
Hello,
I'm looking for a way of validating/parsing the xsd file (schema), i
only been able of validating the xml file with the corresponding
schema, but what i want is only validate the xsd file, to check if the
schema is valid.
I'm using Xerces-C++ and the only thing that i found is a way of
parsing the xml file with the xml schema like this:
| |
by: erik_midtskogen |
last post by:
Hi Folks,
I'm writing a general-purpose HTML screen-scraping framework in Java
(scrape new web sites without writing new code, yada yada...), and I
want to use the JAXP DOM api along with XPath and XSLT for most of my
business logic. I actually hope to make this an open-source project if
I can ever get it to some reasonable level of usability.
My problem is that, since the slurry pumped out by most web sites bears
only the faintest...
|
by: Undeclared |
last post by:
Hello!
My goal is to use JAXP for creating SAX parser with my own XMLParserConfiguration. For example, in package org.apache.xerces.parsers there is a constructor:
public SAXParser(XMLParserConfiguration config);
But I don't want to use Xerces classes, only JAXP.
Thank you.
|
by: mstilli |
last post by:
Hi,
I am trying to use schema for server side validation using xerces to
catch the validation errors.
validating this XML:
<Content4>
<textarea13></textarea13>
<binaryobject3></binaryobject3>
|
by: Boris Kolpackov |
last post by:
Hi,
I am pleased to announce the availability of Apache Xerces-C++ 3.0.0.
Xerces-C++ is an open-source validating XML parser written in a
portable subset of C++. It provides DOM (level 1, 2, and 3), SAX,
and SAX2 APIs and supports validation of XML documents against DTD
and XML Schema.
This release includes a large number of new features, bug fixes, and
clean-ups, including:
|
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...
|
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,...
| |
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...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |