【问题标题】:XSD Validation in Eclipse: "No grammar constraints" warning?Eclipse 中的 XSD 验证:“无语法约束”警告?
【发布时间】:2011-11-12 06:38:15
【问题描述】:

我在 Eclipse 中创建了一个新项目,只是为了验证一个 xml,这要归功于相应的 xsd。我写了 xsds 和 xml 文件。

主要的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 在同一个目录下,就像:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns="http://www.myurl.com/schemas" 
  targetNamespace="http://www.myurl.com/schemas">

主要包含主xsd中使用的complexTypes

xml 示例文件也在同一目录中,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<myTag xmlns="http://www.myurl.com/schemas" myAttributes="2011-09-07">

所有这三个文件都已加载到我的 Eclipse 项目的同一目录中。然而我一直有这个警告:

未检测到文档的语法约束(DTD 或 XML 模式)。 example.xml XMLValidation/Test line 1 XML Problem

我的 xml 或 xsd 中缺少什么以便我可以验证我的 xml 文件?

【问题讨论】:

    标签: xml eclipse xsd xsd-validation


    【解决方案1】:

    在 Preferences -> XML -> XML Catalog 下,添加用户指定的条目。将架构路径/文件名放在位置字段中(如果需要,使用工作区或文件系统按钮)。此时,应使用您的命名空间填充 Key 字段。单击确定几次退出,然后右键单击您的 xml 文件并单击验证。 Eclipse 应该将您的“xmlns”属性与“Key”匹配,并使用适当的模式。

    【讨论】:

      【解决方案2】:

      您需要告诉 eclipse xml 处理器在哪里可以找到架构。编辑 Preferences->XML->XML Catalog 以便将命名空间映射到模式资源,或者只在实例文档中包含 schemaLocation。假设您的主要架构是 main.xsd:

      <myTag xmlns="http://www.myurl.com/schemas" 
             myAttributes="2011-09-07"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.myurl.com/schemas main.xsd" >
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-06
        • 2010-09-24
        • 2011-06-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多