I am developing a cross-platform application (for Windows, Mac etc.) and for 32-bit and 64-bit machines. I have lots of XML files which I need to validate against their XSD.
Is there any way of doing this in Delphi XE3?
I have tried DTD validation but I'm always getting a "DTD prohibited" error. I have also tried solutions mentioned on lots of websites to resolve this error, but I've had no success.
Thanks in advance.
Below is the code I've used...
function TForm2.ValidateXML(const xmlFile : TFileName) : boolean;
var
xmlDoc: TXMLDocument;
begin
result := false;
xmlDoc := TXMLDocument.Create(nil) ;
try
xmlDoc.ParseOptions := [poResolveExternals, poValidateOnParse];
try
xmlDoc.LoadFromFile(xmlFile) ;
xmlDoc.Active := true; //this will validate
result := true;
except
on EX : EDOMParseError do
begin
ShowMessage('Invalid XML: ' + Ex.Message) ;
end;
end;
finally
xmlDoc := nil;
end;
end;