2012-05-16 55 views
1

我有这个现有的XSD,它试图限制一个值到一个URL,但它不工作。该ID为空白,文档仍然有效。它还验证我何时输入任何文本。限制元素到URL

<xsd:schema xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2005/Atom" elementFormDefault="qualified" attributeFormDefault="unqualified"> 
... 

<xsd:complexType name="feedType"> 
<xsd:choice minOccurs="3" maxOccurs="unbounded"> 
    <xsd:element name="id" type="atom:idType" minOccurs="1" maxOccurs="1"/> 
... 

<xsd:complexType name="idType"> 
    <xsd:annotation> 
     <xsd:documentation> 
      The Atom id construct is defined in section 4.2.6 of the format spec. 
     </xsd:documentation> 
    </xsd:annotation> 
    <xsd:simpleContent> 
     <xsd:extension base="xsd:anyURI"> 
      <xsd:attributeGroup ref="atom:commonAttributes"/> 
     </xsd:extension> 
    </xsd:simpleContent> 
</xsd:complexType> 

............

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.w3.org/2005/Atom ../XMLschemas/atom/2005/v/0.2/atom.xsd"> 
    <id>https://mydomain.com</id> 
+0

请不要在“XSD:”等前加上标题。这就是标签的用途。 –

+0

你在做什么验证工作? –

+0

@John,是的,我不知道这是为什么这样设置的,但无论如何,其他元素的限制都在起作用,它只是有问题的ID。 Petru,我正在使用Altova XMLSpy和Eclipse验证器。两者都有相同的结果。 – user994165

回答

1

anyURI还允许相对URI,和AFAIK一个空字符串是一个有效的相对URI。您可能会添加pattern方面以要求“://”更接近您想要的。

随着spec说,

...在实践中[任何URI]定义的规定只在最低限度符合标准的处理器很谦虚 义务。