Validating XML files against XSD in FireMonkey

本秂侑毒 提交于 2019-12-19 19:52:20

问题


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;

回答1:


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/



来源:https://stackoverflow.com/questions/17361799/validating-xml-files-against-xsd-in-firemonkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!