在 Visual Studio IDE 中使用 XSD 进行 XML 验证 [英] XML Validation with XSD in Visual Studio IDE

查看:25
本文介绍了在 Visual Studio IDE 中使用 XSD 进行 XML 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我以前做过这个,但是今天不起作用,我也找不到任何解释如何做的地方.可能是我睡眠不足,但我怀疑是小精灵.

I know I have done this before, but it isn't working today, nor can I find anywhere that explains how to do it. It could be my lack of sleep, but I suspect gremlins.

我有一个 XML 文档和一个包含定义它的 XSD 的目录.如何设置 Visual IDE 以通知我验证失败,然后在给定上下文中提供有效标签和属性的智能感知列表?

I have an XML document and a directory full of XSD's that define it. How do I set the Visual IDE up to notify me of validation failures, and then provide an intellisense list of valid tags and attributes in a given context?

我尝试过的:

  • 我已将 XSD 添加到带有 XML 文档的项目中.
  • 我已将 XSD 添加到 XML Schema 列表中(在 XML/Schemas... 菜单项下.)
  • 我什至在 XML 文档中包含了 schemaLocation 和 noNamespaceSchemaLocation 属性.

Visual Studio 仍然没有放弃任何有用的调试或编辑信息.我在 2010 年和 2008 年都尝试过(我之前在 2008 年之前做过)

Visual Studio still isn't giving up any useful debugging or editing information. I tried both 2010 and 2008 (I've done it before in 2008 I thought)

更新:我让另一位开发人员尝试了这个,但他也失败了.他知道他已经使用其他 XML 文档完成了这项工作,并且成功了.然后我下载了 Oxygen XML 编辑器,它在相同的 XML 和 XSD 文件上运行良好,所以文件似乎很好(或者 Oxygen 更宽容/更灵活......)

Update: I had another developer try this and it failed for him too. He knows he has done it with other XML documents and had it work. I then downloaded Oxygen XML editor and it worked fine on the same XML and XSD files, so the files seem to be fine (or Oxygen is more forgiving / flexible . . . )

推荐答案

您需要将 Visual Studio 中的 XML 文档与您拥有的 XSD 文件相关联.

You'll need to associate the XML document in Visual Studio with the XSD file you have.

  1. 您应该在 XML 文档的属性"窗口中看到如下内容:

  1. You should see something like this in your Properties window of the XML document:

在 XML 模式集编辑器中(当您单击属性"窗口中模式"文本框中的 (...) 省略号时打开),您需要确保您的模式存在.此外,请确保启用了该架构的 Use 列 - 如果没有,请单击它 - 您将获得一个选项下拉列表,选择 Use 一个带有绿色复选标记:

In the XML schema set editor (opens when you click on the (...) ellipsis in the "Schemas" textbox in your Properties window) you need to make sure you have your schema present. Also, make sure the Use column for that schema is enabled - if not, click on it - you'll get a drop-down list of options, pick the Use one with the green checkmark:

确保 Visual Studio 的错误列表窗口可见(菜单视图 > 错误列表).这将显示 XML 和 XSD 架构定义之间的所有不一致.

Make sure Visual Studio's Error List windows is visible (menu View > Error List). This will show all inconsistencies between XML and XSD schema definitions.

一切就绪后,Visual Studio XML 编辑器应该在编辑器中使用蓝色波浪线突出显示 XML 的问题:

Once all of that is in place, the Visual Studio XML editor should highlight problems with your XML in the editor using blue squigglies:

这篇关于在 Visual Studio IDE 中使用 XSD 进行 XML 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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