Kavita Ashok Sukerkar wrote:
Hi everyone,[EMAIL PROTECTED] is the list for user related queries,
I am trying to use the Xerces parsers for xml schema validation within Java code. I use the parse function from the XMLParser class, that DOMParser inherits from. This function throws two kinds of exceptions: IOException and SAXException. But what if the xml file I am supplying is well formed and NOT valid? DOes it throw any kind of exception? My program just outputs an error message saying that the file was not valid. I want my function to be able to return a 0 if the parsing was unsuccessful,
One way is to write a small function that returns boolean value appropriately when errors/warnings .. are reported, register a error handler to identify them. Refer to sample programs provided by xerces for more help on error handlers.
Hope this helps.
Regards, venu
but I can't do that if there are just error messages being outputted. This is my code.....can someone help me please!
import org.apache.xerces.parsers.DOMParser; import org.apache.xerces.parsers.*; import org.w3c.dom.Document; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import java.io.IOException;
public class DOMParserDemo { private static void setFeature(DOMParser parser, String feature, boolean setting) { try { parser.setFeature(feature, setting); } catch (SAXNotRecognizedException e) { System.out.print("Unrecognized feature: "); System.out.println(feature); } catch (SAXNotSupportedException e) { System.out.print("Unrecognized feature: "); System.out.println(feature); } }
public static void main (String args[]) { DOMParser parser = null; parser = new DOMParser();
Document doc = null;
setFeature(parser, "http://xml.org/sax/features/validation", true); setFeature(parser, "http://apache.org/xml/features/validation/schema",true); setFeature(parser, "http://apache.org/xml/features/validation/schema-full-checking", true);
try { parser.parse("C:/Program Files/Xinox Software/JCreator LE/MyProjects/soaptest/XsuTest/SQRT.xml"); } catch (IOException ie) { System.out.println("Could not read file."); } catch (SAXException e) { System.out.print("Could not create Document: "); System.out.println(e.getMessage()); } catch (Exception e) { System.out.print("Error occurred\n"); }
System.out.println("done\n"); } }
Thanks, Kavita
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
