private boolean validate ( DefinitionsDocument defdoc ) { List < XmlError > errorList = new ArrayList <> ( ) ; XmlOptions options = new XmlOptions ( ) . setSavePrettyPrint ( ) . setSavePrettyPrintIndent ( 2 ) . setSaveAggressiveNamespaces ( ) ; options . setErrorListener ( errorList ) ; System . out . println ( "!--toString---" ) ; System . out . println ( defdoc . toString ( ) ) ; boolean valid = defdoc . validate ( options ) ; System . out . println ( "Document is " + ( valid ? "valid" : "invalid" ) ) ; if ( ! valid ) { for ( int i = 0 ; i < errorList . size ( ) ; i ++ ) { XmlError error = errorList . get ( i ) ; System . out . println ( "\n" ) ; System . out . println ( "Message: " + error . getMessage ( ) + "\n" ) ; System . out . println ( "Location of invalid XML: " + error . getCursorLocation ( ) . xmlText ( ) + "\n" ) ; } } return valid ; }
Validates the xml after creation