{++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// validate_xml_memo
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
Function validate_xml_memo(
xml,xsd:
string):Boolean;
procedure AddParseError(E: IXMLDOMParseError);
begin
if E.errorCode <> 0
then
begin
Showmessage('
Validation Error: '+E.reason+#13#10+E.srcText)
end else result:=TRUE;
end;
var
Doc: IXMLDOMDocument2;
Schema: IXMLDOMDocument2;
SchemaCache: IXMLDOMSchemaCollection;
sNameSpace:
String;
begin
try
// Load XML document
Doc := CoDOMDocument60.Create;
Doc.async := False;
Doc.resolveExternals := True;
Doc.validateOnParse := True;
if not Doc.loadXML(
xml)
then
begin
AddParseError(Doc.parseError);
Exit;
end;
// Load schema
Schema := CoDOMDocument60.Create;
Schema.async := False;
Schema.resolveExternals := True;
Schema.validateOnParse := True;
if not Schema.loadXML(xsd)
then
begin
AddParseError(Schema.parseError);
Exit;
end;
// put in schema cache
SchemaCache := CoXMLSchemaCache60.Create;
sNameSpace := VarToStr(Schema.documentElement.getAttribute('
targetNamespace'));
SchemaCache.add(sNameSpace, Schema);
//load schema with the correct namespace
// assign schema cache to a document
Doc.schemas := SchemaCache;
// Validate
AddParseError(Doc.validate);
result:=TRUE;
except
on E:
Exception do
Showmessage(E.
message);
end;
end;