【问题标题】:XML validation against XSD: schemaLocation value must have even number of URI's针对 XSD 的 XML 验证:schemaLocation 值必须具有偶数个 URI
【发布时间】:2013-01-29 15:16:23
【问题描述】:

我有一个 blog.xml 和一个 Blog.xsd 来验证 XML 文件。我正在使用http://www.xmlvalidation.com/?L=0 来验证这两个文件,但出现错误。

你能告诉我有什么问题吗?

错误:

blog.xml:

http://pastebin.com/He3xCxxC(不好意思发到pastebin(由于字数限制)

博客.xsd:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="blog">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="post" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="ptitle"/>
              <xs:element type="xs:string" name="psubtitle"/>
              <xs:element type="xs:anyURI" name="image"/>
              <xs:element type="xs:string" name="author"/>
              <xs:element type="xs:string" name="date"/>
              <xs:element type="xs:string" name="par"/>
              <xs:element type="xs:anyURI" name="source"/>
              <xs:element type="xs:string" name="comments"/>
            </xs:sequence>
            <xs:attribute type="xs:byte" name="id" use="optional"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

【问题讨论】:

  • 您的 xml 在 pastebin 中不再可用。至少提供具有代表性的 xml 片段,以便您的帖子对其他人有用。
  • 不要粘贴解析输出的截图。这不会在搜索机器中编入索引(即使在这种情况下,我们也无法在页面中搜索该测试)。

标签: xml validation xsd xsd-validation


【解决方案1】:

您还没有设置架构的targetNamespace(即“http://www.w3schools.com”)。

<xs:schema attributeFormDefault="unqualified" targetNamespace="http://www.w3schools.com" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

schemalocation 必须指定命名空间和架构。这就是为什么schemaLocation 中必须有偶数个元素。

<a:blog xmlns:a="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com ./Blog.xsd">

【讨论】:

  • 我把它放在哪里?以及如何?
  • 我仍然收到错误:7:129 SchemaLocation:schemaLocation value = '/Blog.xsd' 必须有偶数个 URI。 7: 129 cvc-elt.1: 找不到元素“a:blog”的声明。文件 xml-schema 中的错误:1:165 TargetNamespace.2:不期望命名空间,但架构文档的目标命名空间为“w3schools.com”。
  • @Brian 您所做的工作可能只是一个学习练习,但作为一般规则,您不应该将其他人的命名空间用于您自己的 XML 格式。
猜你喜欢
  • 2014-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-15
  • 2012-06-11
  • 2012-09-20
  • 2021-04-11
  • 1970-01-01
相关资源
最近更新 更多