问题描述
我在Eclipse中创建了一个新项目,只是为了验证一个xml,感谢对应的xsd。我写了xsds和xml文件。
I created a new project in Eclipse just to validate a xml thanks to the corresponding xsd. I wrote both the xsds and the xml files.
主XSD如下:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.myurl.com/schemas"
targetNamespace="http://www.myurl.com/schemas"
version="1.0">
<xs:include schemaLocation="other_xsd.xsd"/>
[...]
other_xsd.xsd
在同一目录中,如下所示:
The other_xsd.xsd
is in the same directory and is like:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.myurl.com/schemas"
targetNamespace="http://www.myurl.com/schemas">
它主要包含 complexType
main xsd
It mostly contains complexType
s used in the main xsd
xml示例文件也位于同一目录中,如下所示:
The xml example file also is in the same directory and is like:
<?xml version="1.0" encoding="UTF-8"?>
<myTag xmlns="http://www.myurl.com/schemas" myAttributes="2011-09-07">
所有这三个文件已加载到我的Eclipse项目中的同一目录中。然而,我不断发出警告:
All those three files have been loaded within the same directory in my Eclipse project. Yet I keep having this warning:
我的xml或xsd中缺少什么,以便我可以验证我的xml文件?
What is missing in my xml or in my xsd so that I can validate my xml file?
推荐答案
在首选项 - > XML - > XML目录下,添加用户指定的条目。将模式路径/文件名放在位置字段中(如果需要,使用工作区或文件系统按钮)。此时,密钥字段应填充您的命名空间。单击确定几次退出,然后右键单击您的xml文件,然后单击验证。 Eclipse应该将您的xmlns属性与Key匹配,并使用适当的模式。
Under Preferences -> XML -> XML Catalog, add a user specified entry. Put the schema path/filename in the Location field (using the Workspace or File System buttons if desired). At that point the Key field should be populated with your namespace. Click OK a couple times to exit out, then right-click your xml file and click Validate. Eclipse should match your "xmlns" attribute with the "Key", and use the appropriate schema.
这篇关于Eclipse中的XSD验证:“无语法约束”警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!