根据特定架构验证 XDocument
我有一个已加载的 XDocument 文件。 (确认工作)。我需要验证这份文件。为此,我有一个 XSD 文件,我将其作为嵌入式资源附加到项目中。我加载 带有以下代码行的 xsd:
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("Project.Models.Ci.def.xsd");
我现在如何根据此 XSD 验证 XML?我只需要知道该文件是否有效,所以没什么花哨的。
I have an XDocument file that I have loaded. (confirmed the working). I need to validate this document. To do so I have an XSD file that I attached to the project as a embedded resource. I load
the xsd with these line of code:
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("Project.Models.Ci.def.xsd");
How can I now validate the XML against this XSD? I only need to know if the document is valid or not, so nothing fancy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一个 Validate 扩展方法可能会满足您的需求。查看 MSDN 上的此文档 - 它还有示例代码:
Extensions.Validate方法(XDocument、XmlSchemaSet、ValidationEventHandler、布尔值)
There is a Validate extension method that might meet your needs. Take a look at this documentation on MSDN - it has sample code as well:
Extensions.Validate Method (XDocument, XmlSchemaSet, ValidationEventHandler, Boolean)