针对FireMonkey中的XSD验证XML文件 [英] Validating XML files against XSD in FireMonkey

查看:92
本文介绍了针对FireMonkey中的XSD验证XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发跨平台应用程序(适用于Windows,Mac等)以及32位和64位计算机。
我有很多XML文件,需要根据它们的 XSD 进行验证。

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.

在Delphi XE3中有什么办法吗?

Is there any way of doing this in Delphi XE3?

我尝试了DTD验证,但是我总是收到禁止DTD错误。我还尝试了许多网站上提到的解决方案来解决此错误,但没有成功。

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.

预先感谢。

下面是我使用的代码...

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.

也许 Libxml2 http://xmlsoft.org/ )是一个选项,因为它可以在许多平台上的许多编程语言中使用。

Maybe Libxml2 (http://xmlsoft.org/) is an option, as it can be used from many programming languages on many platforms.

用于Libxml2的开源Pascal包装器可在 http: //sourceforge.net/projects/libxml2-pas/

A open source Pascal wrapper for Libxml2 is avalaible on http://sourceforge.net/projects/libxml2-pas/

这篇关于针对FireMonkey中的XSD验证XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆