on 02-06-2007 5:46 PM
Hi all,
I need to validate an XML in a java mapping.
To this end, I'm trying to instantiate a SchemaFactory supporting W3C XML Schema 1.0. using this piece of code in my java class:
/* ... stuff here ... */
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
/* ... stuff again ... */
but I get an IllegalArgumentException:
<b>java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema at
javax.xml.validation.SchemaFactory.newInstance(Unknown Source)...</b>
The point is that when I test that class with eclipse it works. Should I add some other archive (I've added xercesImpl.jar, xml-apis.jar, xercesSample.jar and resolver.jar)?
thanks a lot for any help,
Daniele
I managed to force the XMLSchemaFactory replacing the piece of code i wrote with this:
XMLSchemaFactory sf = new XMLSchemaFactory();
Now the mapping understands the class to use (quite obviously) and does not produce errors (well, not too many 😜 ).
So now <b>this</b> problem is solved, but I feel like many others will rise...
Thank you for your help.
Daniele
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you guys for your answers, but I'm still in troubles.
I gave a look to your code Iván but it seems to use DOM parser which does not match my needs as I believe it uses much more memory than a SAX parser. In addition to this I need also a content handler to check where did the error occur. Can I apply the same method to a SAX parser mantaining a content handler?
I've also imported every jar I used on Eclipse but the error is still there. It seems it cannot find a suitable SchemaFactory (which should be XMLSchemaFactory by default, a class that is present in the jars I've imported). I've added this line to suggest this class at runtime
System.setProperty("javax.xml.validation.SchemaFactory:http://www.w3.org/2001/XMLSchema","XMLSchemaFactory");
but nothing changed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Have you included all the jars while creating the "jar" for Java Mapping? If not you can even seperately import them in the imported archives section.
Search whether the XMLConstants class exists in the jar files you specified. If its working in eclipse then it should also work in XI as Java Mapping. Add all jars in XI imported archives and try executing.
Regards,
P.Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Danielle,
Try with this java code :
import org.apache.xerces.parsers.DOMParser;
import java.io.File;
import org.w3c.dom.Document;
public class SchemaTest
{
public static void main (String args[])
{
File docFile = new File("document.xml");
try
{
DOMParser parser = new DOMParser();
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
"memory.xsd");
ErrorChecker errors = new ErrorChecker();
parser.setErrorHandler(errors);
parser.parse("document.xml");
}
catch (Exception e)
{
System.out.print("Problem parsing the file.");
}
}
}
Best Regards
Iván Prieto
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.