By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,496 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,496 IT Pros & Developers. It's quick & easy.

Java Xml Validation

P: 9
hello,
I want to validate an xml by means of a schema (xsd). To do that first of all Im 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);
Im sure that code is ok. In fact, Ive 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 doesnt 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 Im 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
Share this Question
Share on Google+
1 Reply


dorinbogdan
Expert 100+
P: 839
Welcome to TheScripts TSDN.
I copied the thread to Java and Linux forums too.
I saw that you already posted on Java forum, so please delete one copy there.

Thanks,
Dorin.
May 28 '07 #2

Post your reply

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