验证XML语法只适用于C# [英] Validate XML Syntax Only in C#

查看:134
本文介绍了验证XML语法只适用于C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多,关于如何验证对XML架构教教程。但现在我只想验证XML语法,不违背架构。这意味着我只是想检查XML是否是良好的形式,即是否有关闭或打开未正确做标记。

There are a lot of tutorials that teach on how to validate XML against a schema. But now I want to validate XML syntax only, not against the schema. Meaning I just want to check whether the XML is well-form, that whether there are closing or opening tag that is not done properly.

有反正我能做到这一点在.net中?

Is there anyway I can do that in .Net?

推荐答案

或者,如果你在.NET 3.5中,你可以使用的 XElement.Load()

Or if you're on .NET 3.5, you can use XElement.Load().

的LINQ to XML的加载功能是对的 system.xml.xmlreader.aspx>的XmlReader 。因此,
可能赶上是
的的 XmlReader.Create
超载方法和的XmlReader
中的方法读取并解析
文档。

LINQ to XML's loading functionality is built upon XmlReader. Therefore, you might catch any exceptions that are thrown by the XmlReader.Create overload methods and the XmlReader methods that read and parse the document.

这篇关于验证XML语法只适用于C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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