Hi I've created a class that is accepting an xml string and needs to validate it against an XML schema. The problem is that it's not validating. Here is the code I have so far.
import org.apache.xerces.parsers.DOMParser;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class XMLOrder{
public String createorder(String xmlstring) throws Exception { byte buf = xmlstring.getBytes; InputStream is = new ByteArrayInputStream(buf); BufferedInputStream bufis = new BufferedInputStream(is); InputSource source = new InputSource(bufis);
try{
DOMParser parser = new DOMParser;
try{
parser.setFeature("http://xml.org/sax/features/validation",true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-che cking", true);
}
catch (SAXNotRecognizedException se){
return se.toString;
}
try{
parser.setProperty("http://apache.org/xml/properties/schema/external-noNames paceSchemaLocation","xmlorder.xsd"); } catch (SAXNotRecognizedException se){ return se.toString; }
try{
parser.parse(source);
Document doc = parser.getDocument;
Node root = doc.getDocumentElement;
return root.getNodeName;
}
catch (SAXParseException se){
return se.getMessage;
}
}
catch (Exception e) {
return e.toString;
}//create the parser
}
}
import org.apache.xerces.parsers.DOMParser;
import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
public class XMLOrder{
public String createorder(String xmlstring) throws Exception { byte buf = xmlstring.getBytes; InputStream is = new ByteArrayInputStream(buf); BufferedInputStream bufis = new BufferedInputStream(is); InputSource source = new InputSource(bufis);
try{
DOMParser parser = new DOMParser;
try{
parser.setFeature("http://xml.org/sax/features/validation",true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-che cking", true);
}
catch (SAXNotRecognizedException se){
return se.toString;
}
try{
parser.setProperty("http://apache.org/xml/properties/schema/external-noNames paceSchemaLocation","xmlorder.xsd"); } catch (SAXNotRecognizedException se){ return se.toString; }
try{
parser.parse(source);
Document doc = parser.getDocument;
Node root = doc.getDocumentElement;
return root.getNodeName;
}
catch (SAXParseException se){
return se.getMessage;
}
}
catch (Exception e) {
return e.toString;
}//create the parser
}
}