Jdeveloper and xsd

06 Apr 2012

Jdeveloper 10.1.3 has no ability to parse xsd if you use built in wizard. It just uses jaxb to generate class and code. For something generic use documentbuilderfactory in java 5

protected void validateXSD(String sFileName) throws Exception,SAXException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

URL sURL = Thread.currentThread().getContextClassLoader().getResource(XML_SCHEMA);
String sFile = sURL.getFile();
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "file:" + sFile);

DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler( new ErrorHandler() {
@Override
public void error(SAXParseException arg0) throws SAXException {
throw arg0;
}
@Override
public void fatalError(SAXParseException arg0) throws SAXException {
throw arg0;
}
@Override
public void warning(SAXParseException arg0) throws SAXException {
throw arg0;
}
});

org.w3c.dom.Document document = builder.parse(new File(sFileName));

}

validateXSD(sOutputPath + sCurrDate + sName);

SAXReader reader = new SAXReader(true);
reader.setValidation(false);
org.dom4j.Document doc = null;

doc = reader.read(new File(sOutputPath + sCurrDate + sName));

/* Iterate through the entries */
iterateElements(doc);

>

Published on 06 Apr 2012 Find me on Twitter!