473,387 Members | 1,476 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,387 software developers and data experts.

Java Xml Validation

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:
Expand|Select|Wrap|Line Numbers
  1.              SchemaFactory factory =
  2.                     SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
I´m sure that code is ok. In fact, I´ve found that in several tutorials and guides such as:
http://www.ibm.com/developerworks/library/x-javaxmlvalidapi.html?ca=dgr-lnxw07Java-XML-Val
http://www-128.ibm.com/developerworks/java/library/x-javaxmlvalidapi.html?ca=drs
http://www.java-tips.org/java-se-tips/javax.xml.validation/how-to-create-xml-validator-from-xml-s.html

In Linux it doesn´t work and it has this exception:

[java] java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema
[java] at javax.xml.validation.SchemaFactory.newInstance(Sch emaFactory.java:186)
[java] at es.rbcdexia.risk.dbimport.xml.XMLManager.validarSA X(XMLManager.java:289)
[java] at es.rbcdexia.risk.dbimport.xml.XMLManager.main(XMLM anager.java:115)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(Exec uteJava.java:202)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute( ExecuteJava.java:134)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:7 10)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Jav a.java:178)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.ja va:84)
[java] at org.apache.tools.ant.UnknownElement.execute(Unknow nElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:34 1)
[java] at org.apache.tools.ant.Target.performTasks(Target.ja va:369)
[java] at org.apache.tools.ant.Project.executeSortedTargets( Project.java:1216)
[java] at org.apache.tools.ant.helper.SingleCheckExecutor.ex ecuteTargets(SingleCheckExecutor.java:37)
[java] at org.apache.tools.ant.Project.executeTargets(Projec t.java:1068)
[java] at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java :382)
[java] at org.apache.tools.ant.UnknownElement.execute(Unknow nElement.java:275)
[java] at org.apache.tools.ant.Task.perform(Task.java:364)
[java] at org.apache.tools.ant.Target.execute(Target.java:34 1)
[java] at org.apache.tools.ant.Target.performTasks(Target.ja va:369)
[java] at org.apache.tools.ant.Project.executeSortedTargets( Project.java:1216)
[java] at org.apache.tools.ant.Project.executeTarget(Project .java:1185)
[java] at org.apache.tools.ant.helper.DefaultExecutor.execut eTargets(DefaultExecutor.java:40)
[java] at org.apache.tools.ant.Project.executeTargets(Projec t.java:1068)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:668)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:187)
[java] at org.apache.tools.ant.Main.start(Main.java:150)
[java] at org.apache.tools.ant.Main.main(Main.java:240)



Both in Windows and Linux I´m using this java version:
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode)

My GNU/Linux platform is the following:
Red Hat Enterprise Linux ES release 4 (Nahant)

W3C_XML_SCHEMA_NS_URI constant is defined in http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/XMLConstants.html#W3C_XML_SCHEMA_NS_URI

In the API from SchemaFactory
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/SchemaFactory.html#newInstance(java.lang.String)
it says:

To find a SchemaFactory object for a given schema language, this method looks the following places in the following order where "the class loader" refers to the context class loader:

1. If the system property "javax.xml.validation.SchemaFactory:schemaLanguage " is present (where schemaLanguage is the parameter to this method), then its value is read as a class name. The method will try to create a new instance of this class by using the class loader, and returns it if it is successfully created.
2. $java.home/lib/jaxp.properties is read and the value associated with the key being the system property above is looked for. If present, the value is processed just like above.
3.

The class loader is asked for service provider provider-configuration files matching javax.xml.validation.SchemaFactory in the resource directory META-INF/services. See the JAR File Specification for file format and parsing rules. Each potential service provider is required to implement the method:

isSchemaLanguageSupported(String schemaLanguage)


The first service provider found in class loader order that supports the specified schema language is returned.
4. Platform default SchemaFactory is located in a implementation specific way. There must be a platform default SchemaFactory for W3C XML Schema.

If everything fails, IllegalArgumentException will be thrown.


I haven.t done anything of that in the windows platform and it works. do you know what is the best way to make it work in Linux?
thanks in advance,
Jaime
May 28 '07 #1
12 3376
JosAH
11,448 Expert 8TB
I don't know why it doesn't work either; one little thing: did you import the correct
XMLConstants class? There are two of them and you need the one in javax.xml.
Sorry I can't help you any further.

kind regards,

Jos
May 28 '07 #2
JosAH
11,448 Expert 8TB
Please don't double post; I removed your other identical thread. Thanks.

kind regards,

Jos
May 28 '07 #3
JosAH
11,448 Expert 8TB
I checked Sun's bugbase and found this:

http://bugs.sun.com/bugdatabase/view...bug_id=5026581

As a matter of fact I read all the bugs related to the search term "SchemaFactory",
a frightening number of bugs were shown; my guess is that the best action to
take is to upgrade to Java 1.6

kind regards,

Jos
May 28 '07 #4
dorinbogdan
839 Expert 512MB
Please don't double post; I removed your other identical thread. Thanks.

kind regards,

Jos
Hi Jos,
It's my mistake for the duplicate threads. I copied the thread from XML to Java forum, without checking first.

Dorin.
May 28 '07 #5
JosAH
11,448 Expert 8TB
Hi Jos,
It's my mistake for the duplicate threads. I copied the thread from XML to Java forum, without checking first.

Dorin.
Ok, no harm done ;-)

kind regards,

Jos
May 28 '07 #6
hello,
thanks for your answers.
I´ve read the bug 5026581 and I have tried with that testing class. Again it works fine in windows and results in an IllegalArgumentException if you run it in Linux. Bug doc says it was fixed ( 1.5(tiger-b46)). do you know what java version is 1.5(tiger-b46. I mean it is former or not to 1.5.0_11-b03?
thank you!
May 28 '07 #7
JosAH
11,448 Expert 8TB
hello,
thanks for your answers.
I´ve read the bug 5026581 and I have tried with that testing class. Again it works fine in windows and results in an IllegalArgumentException if you run it in Linux. Bug doc says it was fixed ( 1.5(tiger-b46)). do you know what java version is 1.5(tiger-b46. I mean it is former or not to 1.5.0_11-b03?
thank you!
b03 < b46; 'b' stands for 'build number' and I assume you haven't downloaded
anything earlier than 1.5.0_11. Try and download the latest Java 1.6 version;
all that xml stuff has been full of bugs all the time; it's a mess no matter
whether or not they stamp it the "reference implementation".

kind regards,

Jos
May 28 '07 #8
hello,
the problem is I must use java 1.5 ;-( I´ve downloaded JAXP from https://jaxp.dev.java.net/servlets/ProjectDocumentList?folderID=4585&expandFolder=458 5&folderID=0
Exactly I´ve downloaded JAXP_141.jar. I´ve unpacked it and there are 2 jars:
jaxp-ri.jar and jaxp-api.jar. I have tried to use them as endorsed but again the same exception.
I´ve moved that jars to an endorsed dir I´ve created in the /jre/lib, and the result is the same. any further idea?

b03 < b46; 'b' stands for 'build number' and I assume you haven't downloaded
anything earlier than 1.5.0_11. Try and download the latest Java 1.6 version;
all that xml stuff has been full of bugs all the time; it's a mess no matter
whether or not they stamp it the "reference implementation".

kind regards,

Jos
May 30 '07 #9
JosAH
11,448 Expert 8TB
hello,
the problem is I must use java 1.5 ;-( I´ve downloaded JAXP from https://jaxp.dev.java.net/servlets/ProjectDocumentList?folderID=4585&expandFolder=458 5&folderID=0
Exactly I´ve downloaded JAXP_141.jar. I´ve unpacked it and there are 2 jars:
jaxp-ri.jar and jaxp-api.jar. I have tried to use them as endorsed but again the same exception.
I´ve moved that jars to an endorsed dir I´ve created in the /jre/lib, and the result is the same. any further idea?
Why did you download that thing separately? It is included in J2SE starting at
version 1.5. btw version 1.6 is functionally identical to 1.5; if I were you I'd
upgrade to 1.6

kind regards,

Jos
May 30 '07 #10
I downloaded it and used it in the endorsed way to check if the last version has the bug fixed.
I´ll test it in Java 6 and I´ll try to be allowed to upgrade to java 6.
thank you!

Why did you download that thing separately? It is included in J2SE starting at
version 1.5. btw version 1.6 is functionally identical to 1.5; if I were you I'd
upgrade to 1.6

kind regards,

Jos
May 30 '07 #11
JosAH
11,448 Expert 8TB
I downloaded it and used it in the endorsed way to check if the last version has the bug fixed.
I´ll test it in Java 6 and I´ll try to be allowed to upgrade to java 6.
thank you!
If I'm not mistaken the separate download gives you JAXP 1.4.x, the bundled
version is 1.3.y. I never trust different versions when it comes to that darn xml
cra^H^H^Hcode. All the best; I hope you solve that nasty bug.

kind regards,

Jos
May 30 '07 #12
I upgraded to java 6 and the problem was the same.
The matter was not having set fork. I was running it in Linux from a shell. After setting fork=true it works perfectly in java 6 as well as in java 1.5_11.
I think the bug has nothing to do in this case, it was just a matter of the fork that prevented the classloader from working properly.
thank you anyway! regards!
May 31 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Dave W | last post by:
I wish to validate a string but i'm not quite sure how to go about doing it. I'd like to ensure that it is 9 characters long and in the following format. "LL 00 LLL" - Thats letter, letter,...
0
by: Brian | last post by:
I am having alot of trouble getting a XML document validated with a schema. I got a sample document and schema off of w3schools.com, which passed an online xml validator:...
1
by: Ulf Nordlund | last post by:
I am using an XML schema to check (validate) the structure of an XML document. But since I cannot check everything I need using a schema, I am thinking of using XSL for more detailed checks (value...
4
by: Marcin Cenkier | last post by:
Hi, I can create a schema from xsd file: Schema s = SchemaFactory.newInstance(_XMLConstants.W3C_XML_SCHEMA_NS_URI_).newSchema(new StreamSource(res.getInputStream())); but when using...
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...
4
by: Francois Stander | last post by:
Hi, hope someone can help me. It seems imposible to read data from a server, however, I can read the validation data from the server and hold it in dataviews . datasets or data tables in my asp...
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...
2
by: poornimanithya76 | last post by:
Hi, I am having grid view an my page which is having template fields(text box, check box and drop down).If user clicks on check box i need to consider text box and drop down as a required fields.i...
2
by: killy971 | last post by:
I am using java to validate an XML file with a DTD, without having the DVD declaration inside the original file, by setting the doctype dynamically to a transformer like this : ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.