Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to validate with DomParser

843834Feb 17 2003 — edited Feb 17 2003
Hi,

I have this problem. how can i validate this xml file:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<!DOCTYPE REQ>
<REQ ver="1.00">
<CLIENT>
<ID>itsalive</ID>
<PWD>itsalive</PWD>
</CLIENT>
<LIR>
<MSIDS>
<MSID>1234512345</MSID>6
</MSIDS>
</LIR>
</REQ>

has you can the there is the 6 number that make this xml file not valide i'm using this code:

public boolean validateXMLDoc(String xmlDoc) {
System.out.println("** in xmlLayer.validateXMLDoc method! **");
InputSource isXmlDoc = new InputSource(new java.io.StringReader(xmlDoc));
// Create a Xerces DOM Parser
DOMParser parser = new DOMParser();
// Turn Validation on
try {
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature ( "http://xml.org/sax/features/namespaces", true);
} catch (SAXNotRecognizedException e) {
System.err.println("xmlLayer.validateXMLDoc error: " + e.toString());
return false;
} catch (SAXNotSupportedException e) {
System.err.println("xmlLayer.validateXMLDoc error: " + e.toString());
return false;
}
try {
parser.parse(isXmlDoc);
Document document = parser.getDocument();
} catch (SAXException e) {
System.err.println("xmlLayer.validateXMLDoc error: " + e.toString());
return false;
} catch (IOException e) {
System.err.println("xmlLayer.validateXMLDoc error: " + e.toString());
return false;
}
return true;
}

but i don't get any exception error.
can any one help me????

thanks zik.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 17 2003
Added on Feb 17 2003
7 comments
165 views