ClassMethod ValidateFile(file As %String = "C:\0work\XMLdemo\inputfile2.xml",schema as %String="")
{
write !!,"Validating "_file_"..."
if (schema="") {
//in this case, use the schema that the file refers to
Set status=##class(%XML.TextReader).ParseFile(file,.tReader,,flags)
} else {
//use an override schema
Set status=##class(%XML.TextReader).ParseFile(file,.tReader,,flags,,schema)
}
if $$$ISERR(status) {
do $system.OBJ.DisplayError(status)
}
if '$ISOBJECT(tReader) {
write !, ">>> Cannot read this file, because it is not valid..."
quit
}
set errcount=0
set warningcount=0
while (tReader.Read()) {
if (tReader.NodeType="error") {
set errcount=errcount+1
Write !, ">>> *ERROR* ",tReader.Value
} elseif (tReader.NodeType="warning") {
set warningcount=warningcount+1
Write !, ">>> *WARNING* ",tReader.Value
}
}
if (errcount=0) && (warningcount=0) {
write !, ">>> No warnings or errors"
}
}
ClassMethod ValidateFilesInDir(dirtoprocess As %String = "C:\0work\XMLdemo",schema as %String="")
{
set stmt = ##class(%SQL.Statement).%New()
set status = stmt.%PrepareClassQuery("%File","FileSet")
if $$$ISERR(status) {
do $system.OBJ.DisplayError(status)
quit
}
set rset = stmt.%Execute(dirtoprocess,"*.xml",,1)
while rset.%Next() {
set filetoprocess=rset.%Get("Name")
set type=rset.%Get("Type")
if (type="F") {
do ..ValidateFile(filetoprocess,schema)
} elseif (type="D") {
set dirname=rset.%Get("Name")
do ..ValidateFilesInDir(dirname)
}
}
}