Sorry for the late reply; been on vacation. This may have been answered but
this is what worked for me (if I understood your question correctly):
public String validateXml(String aClassName, String aXml)
{
outputXml = null;
try
{
Class xClass = Class.forName(aClassName);
ArrayList validationErrors = new ArrayList();
XmlOptions typeOptions = new XmlOptions();
XmlOptions validationOptions = new XmlOptions();
XmlObject xmlDocument;
SchemaType schemaType = XmlBeans.typeForClass(xClass);
validationOptions.setErrorListener(validationErrors);
typeOptions.setDocumentType(schemaType);
xmlDocument = XmlObject.Factory.parse(aXml, typeOptions);
if (!xmlDocument.validate(validationOptions))
{
String exMsg = "Validation failed";
Iterator iter = validationErrors.iterator();
while (iter.hasNext())
{
XmlValidationError valErr = (XmlValidationError)iter.next();
exMsg += "\n\t" + valErr.getMessage();
}
return exMsg;
}
outputXml = xmlDocument.toString();
return "XML document is valid";
}
catch (Exception e)
{
if (e instanceof java.lang.ClassNotFoundException)
{
return "Validation failed\n\tSupport library not installed for
this XML document type";
}
return "Validation failed\n\tDocument could not be validated
(typically invalid XML)";
}
}