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!

Validate XML with XSD as String (not from file)

843834Sep 21 2006 — edited Sep 22 2006
Hi people,

i wonder if anybody can help me!! I have been look for a solution through internet for one day and i didn�t find anything.

Well i have an XML as String and a XSD as String as well (the XSD and XML are taken from the database as clob and converted into String).

I want to validate the XML with the XSD, but everywehere i find that you have to give the SchemaURL always you want to validate, but in this case i don�t have the file. I am using this code:

public void parsearXML(String fileStringXSD, String fileStringXML) throws Exception
{

StringReader stringReader = null;
InputSource xsd = null;


try {
//stringReader = new StringReader(fileStringXML);
xsd = new InputSource(fileStringXSD);

SAXParser parser = new SAXParser();
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-checking", true);
//parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", xsd);


Validator handler = new Validator();
parser.setErrorHandler(handler);
parser.parse(new InputSource (fileStringXML));

}
catch (Throwable exception) {

Trazas.impExc("EXCEPTION: Archivo XML NO valido seg�n el XSD asociado: "+ exception.getMessage());
Trazas.imprimeErrorExtendido(exception);
throw new Exception(exception);
}

}


Validator is just a simple class for handler:

I don�t know how to tell the parser that the XSD i want to use is the one i have as String. I have lost one day looking for a solution and i have no idea about it (also it�s few time since i am working with XML).


Thanks

regards

Oscar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 20 2006
Added on Sep 21 2006
2 comments
233 views