Validate document starting at xpath
Hi guys,
I have an issue where I am trying to validate an xml document, but there is header information that I don't want it to validate. So I want to be able to tell it to start validating at a certain xpath location.
xpathExpression contains the xpath link, but it seems to ignore it.
Code:
try {
DOMSource domSource = new DOMSource(doc, xpathExpression);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
String docString = writer.toString();
SAXBuilder builder =
new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setValidation(true);
builder.setFeature(
"http: //apache.org/xml/features/validation/schema",
true);
builder.setFeature("http: //apache.org/xml/features/validation/schema-full-checking", true);
builder.setProperty(
"http: //apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
new File(validationPath).toURI().toString());
org.jdom.Document docx = builder.build(new StringReader(docString));
this.wrong(rowCount,1, docString);
}
catch (Exception ex){
this.wrong(rowCount, 2, ex.getMessage());
error = true;
}
I also am having a hard way figuring out how to make sure the document is validated properly.