如何验证XML文档? [英] How to validate an XML document?

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

问题描述

我的C#/。NET应用程序读取手动由用户编辑的XML文件。允许的元素和标记应用程序的文档中描述。我使用LINQ到提取XML文件中的数据。

My C#/.NET application reads XML files that are manually edited by the users. The allowed elements and tags are described in the application's documentation. I'm using LINQ to extract data from the XML file.

从XML文件中提取数据之前,我想验证它,看它是否已预期结构体。如果不是,那将是不错的什么是错的,这样我可以给一些留言反馈给用户的信息。

Before extracting data from the XML file, I'd like to validate it to see if it has the expected structure. If not, it would be nice to have information about what is wrong so that I can give some feeback to the user.

什么是在C#中最简单的方法是什么?

What's the simplest way to do this in C#?

推荐答案

您可以验证XML文件对XSD。

You can validate xml files against XSD.

  • First you have to create Xml Schema Definition file. See example
  • use XML Schema Definition Tool to create XSD from XMLfile
  • Use this code to validate input XML using corresponding XSD

希望这将有助于...

Hope this will help...

这文章解释了所有可能的方式来验证XML,使用C#结果
如何在Visual C使用DTD,XDR,或XSD验证XML文档#.NET

This article explains all possible ways to validate xml, using C#
How To Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET

IMO最好的选择是使用XSD。

IMO best option is to use XSD.

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

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