on 11-25-2008 5:34 AM
Dear all,
I am trying develop a java program by following the SAP NetWaver Library.
http://help.sap.com/saphelp_nw04s/helpdata/en/c4/e1343e8c7f6329e10000000a114084/frameset.htm
But it always catches the IllegalArgumentException.Please advise me how to solve this problem.
The developing code:
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
docBuilderFactory.setValidating(true);
docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",mySchemaInputStream);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(myFileInputStream);
} catch(DOMException domException) {
domException.printStackTrace();
} catch(IllegalArgumentException illegalArgumentException){
illegalArgumentException.printStackTrace();
}
Thanks & Regards,
Red
Hi Grace,
Could you check your exception trace and identify where exactly is the exception generated in your code ?
If it occurs at Document doc = docBuilder.parse(myFileInputStream); line, then the argument myFileInputStream should be one of the following class type File, InputSource, InputSteam or String. If you are using FileInputStrea, then convert it to appropriate class for use.
Please refer to the following [documentation|http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html] for futher help.
Regards,
Alka.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Alka,
The IllegalArgumentException was throw by the method "docBuilderFactory.setAttribute".
When I set the comment marks before the two lines in this code as the following code,
it can paser the XML to DOM successfully without any exception.
//docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
//docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",mySchemaInputStream);
For the propose of the schema validation I have to assign the schema to implement the validation.
But it fails. Please advise me.
Thanks & Regards,
Red
Edited by: Grace Chien on Nov 25, 2008 10:25 AM
Hi Grace,
The value for the http://java.sun.com/xml/jaxp/properties/schemaSource property of the SAX Parser can be of File ot InputSource Class type. From your code snippet it appears to be FileInputStream type.
Try assigning the value as shown [here|http://www.xml.com/pub/a/2005/07/06/jaxp.html].
Regards,
Alka.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Alka,
Thank you for help.
I try to implement the schema vaildation by DOM parsing but not SAX parsing.
I have tried many ways to set the correct attribute to DocumentBuilderFactory.
But it still can't work. It always catches the IllegalArgumentException.
Please provide me more information about the schema vaildation by DOM parsing.
Thanks & Regards,
Red
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
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.