eclipse:使用 xsd 验证 xml
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4194129/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
eclipse: validate xml with xsd
提问by clamp
does anyone know if it is possible to validate an xml with an xsd while i am editing the xml in eclipse?
有谁知道我在 Eclipse 中编辑 xml 时是否可以使用 xsd 验证 xml?
this is how my xml begins:
这就是我的 xml 开始的方式:
<root
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../definitions.xsd">


采纳答案by Gábor Lipták
Right click and Validate. If it is not validated, then Eclipse cannot reach the XSD file. Is definitions.xsd in the parent directory of the XML? You can also define XML catalogentries for your xsds. Anyway, if everything is fine, during saving it should validate XML. Validation usually come together with code completion of elements and attributes. They usually both work or neither.
右键单击并验证。如果未验证,则 Eclipse 无法访问 XSD 文件。definition.xsd 是否在 XML 的父目录中?您还可以为xsd定义XML 目录条目。无论如何,如果一切正常,在保存期间它应该验证 XML。验证通常与元素和属性的代码完成一起进行。他们通常都工作或都不工作。
UPDATE:
更新:
Picture to make validate action more clear:

图片使验证动作更清晰:

回答by lukcio
I found out why the validate option doesn't show up. It happens when you browse files in your local filesystem. You should promote folder to a project, or just add xml and xsd files to some temporary project. Then validate as well as many other options should appear in contex menu.
我发现了验证选项不显示的原因。当您浏览本地文件系统中的文件时会发生这种情况。您应该将文件夹提升到一个项目,或者只是将 xml 和 xsd 文件添加到某个临时项目中。然后验证以及许多其他选项应出现在上下文菜单中。
I'm using eclipse 3.5.2 on Ubuntu.
我在 Ubuntu 上使用 Eclipse 3.5.2。
回答by Doron
It should be automatically-"on the fly" if you have the XSD file declared at the top.
如果您在顶部声明了 XSD 文件,它应该是自动“即时”的。

