XML Schema Validation using XERCES 1.4.4

Status
Not open for further replies.

Suresh

Usenet Archive
Joined
Aug 17, 2001
Messages
167
Reaction score
0
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

}
}
 

dan b

Usenet Archive
Joined
Dec 21, 2001
Messages
3
Reaction score
0
What JDK are you using? Schema validation with Xerces 1.4.4 works great for me when I use Sun's JDK 1.4, but when I try using Sun's JDK
1.3.1_01 I get the following error:

Exception in thread "main" java.lang.NoSuchMethodError
at org.apache.xerces.parsers.DOMParser.startElement(DOMParser.java:1131) at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:1284) at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1806) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:949) at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381) at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098) at org.apache.xerces.validators.common.XMLValidator.resolveSchemaGrammar(XMLValidator.java:2823) at org.apache.xerces.validators.common.XMLValidator.parseSchemas(XMLValidator.java:2747) at org.apache.xerces.validators.common.XMLValidator.bindNamespacesToElementAndAttributes(XMLValidator.java:2688)

at org.apache.xerces.validators.common.XMLValidator.callStartElement(XMLValidator.java:1218) at org.apache.xerces.framework.XMLDocumentScanner.scanElement(XMLDocumentScanner.java:1806) at org.apache.xerces.framework.XMLDocumentScanner$ContentDispatcher.dispatch(XMLDocumentScanner.java:949) at org.apache.xerces.framework.XMLDocumentScanner.parseSome(XMLDocumentScanner.java:381) at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1098) at org.apache.xerces.framework.XMLParser.parse(XMLParser.java:1139) at dom.wrappers.DOMParser.parse(DOMParser.java:111) at dom.DOMCount.count(DOMCount.java:138) at dom.DOMCount.main(DOMCount.java:340)

(Suresh) wrote:
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{
...
 
Status
Not open for further replies.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,243
Members
248,133
Latest member
DujonT

Latest Threads

Top