Subject: RE: Validating XML file externally
From: "Kaila Kaarle" <Kaarle.Kaila@xxxxxxx>
Date: Thu, 28 Jul 2005 09:44:09 +0300
|
hi,
I wrote a small swing app a while ago that does this.
The validation itself is specified like thi8s:
-------- some definitions
static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
static final String W3C_XML_SCHEMA =
"http://www.w3.org/2001/XMLSchema";
static String schemaSource = "/kk/artf/files/raport.xsd";
static final String JAXP_SCHEMA_SOURCE =
"http://java.sun.com/xml/jaxp/properties/schemaSource";
---------- the validating method
private void validateFile() throws ParserConfigurationException, SAXException,
IOException {
String filePath;
filePath = jPath.getText();
f = new File(filePath);
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
factory.setAttribute(JAXP_SCHEMA_SOURCE,new File(schemaSource));
DocumentBuilder bld=null;
bld = factory.newDocumentBuilder();
bld.setErrorHandler(this);
doc = bld.parse(f);
}
---------------
I'll send you privately the whole class just in case you want to try it out
regards
Kaarle
Hi Team,
I wrote XSD for an XML file. Is it possible to validate this XML file by
using the XSD
without modifying the XML file. I mean to say, is there any way to
validate the XML file externally
using XSD (without specifying in XML file).
Thanks,
Sundeep.
|