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;
Obviously you need a cross-platform validator.
Maybe Libxml2 (http://xmlsoft.org/) is an option, as it can be used from many programming languages on many platforms.
A open source Pascal wrapper for Libxml2 is avalaible on http://sourceforge.net/projects/libxml2-pas/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With