为什么“Namespace'http://www.w3.org/XML/1998/namespace'无法在此模式中引用。”?

时间:2010-12-10 02:48:13

标签: xml xsd

在Visual Studio 2010中查看来自http://xmpp.org/schemas/的stanzaerror.xsd时,我收到以下行的警告......

<xs:attribute ref='xml:lang' use='optional'/>

警告:

  

命名空间“http://www.w3.org/XML/1998/namespace”无法在此架构中引用。

这似乎是一个非常基本的XML警告 - 任何想法?

<?xml version='1.0' encoding='UTF-8'?>    
<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:ietf:params:xml:ns:xmpp-stanzas'
    xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'
    elementFormDefault='qualified'>

  <xs:element name='bad-request' type='empty'/>
  <xs:element name='conflict' type='empty'/>
  <xs:element name='feature-not-implemented' type='empty'/>
  <xs:element name='forbidden' type='empty'/>
  <xs:element name='gone' type='xs:string'/>
  <xs:element name='internal-server-error' type='empty'/>
  <xs:element name='item-not-found' type='empty'/>
  <xs:element name='jid-malformed' type='empty'/>
  <xs:element name='not-acceptable' type='empty'/>
  <xs:element name='not-allowed' type='empty'/>
  <xs:element name='not-authorized' type='empty'/>
  <xs:element name='payment-required' type='empty'/>
  <xs:element name='policy-violation' type='empty'/>
  <xs:element name='recipient-unavailable' type='empty'/>
  <xs:element name='redirect' type='xs:string'/>
  <xs:element name='registration-required' type='empty'/>
  <xs:element name='remote-server-not-found' type='empty'/>
  <xs:element name='remote-server-timeout' type='empty'/>
  <xs:element name='resource-constraint' type='empty'/>
  <xs:element name='service-unavailable' type='empty'/>
  <xs:element name='subscription-required' type='empty'/>
  <xs:element name='undefined-condition' type='empty'/>
  <xs:element name='unexpected-request' type='empty'/>

  <xs:group name='stanzaErrorGroup'>
    <xs:choice>
      <xs:element ref='bad-request'/>
      <xs:element ref='conflict'/>
      <xs:element ref='feature-not-implemented'/>
      <xs:element ref='forbidden'/>
      <xs:element ref='gone'/>
      <xs:element ref='internal-server-error'/>
      <xs:element ref='item-not-found'/>
      <xs:element ref='jid-malformed'/>
      <xs:element ref='not-acceptable'/>
      <xs:element ref='not-authorized'/>
      <xs:element ref='not-allowed'/>
      <xs:element ref='payment-required'/>
      <xs:element ref='policy-violation'/>
      <xs:element ref='recipient-unavailable'/>
      <xs:element ref='redirect'/>
      <xs:element ref='registration-required'/>
      <xs:element ref='remote-server-not-found'/>
      <xs:element ref='remote-server-timeout'/>
      <xs:element ref='resource-constraint'/>
      <xs:element ref='service-unavailable'/>
      <xs:element ref='subscription-required'/>
      <xs:element ref='undefined-condition'/>
      <xs:element ref='unexpected-request'/>
    </xs:choice>
  </xs:group>

  <xs:element name='text'>
    <xs:complexType>
      <xs:simpleContent>
        <xs:extension base='xs:string'>
          <xs:attribute ref='xml:lang' use='optional'/>
        </xs:extension>
      </xs:simpleContent>
    </xs:complexType>
  </xs:element>    

  <xs:simpleType name='empty'>
    <xs:restriction base='xs:string'>
      <xs:enumeration value=''/>
    </xs:restriction>
  </xs:simpleType>    
</xs:schema>

1 个答案:

答案 0 :(得分:12)

仅仅因为您不需要为实例文档声明xml命名空间,并不意味着模式也是如此。我知道这似乎有点奇怪,但它确实存在。您需要定义xml:lang属性,并且需要声明xml命名空间。通常,我使用一个简单的模式,我导入到我的模式。使用W3C has made available

导入,声明命名空间。一切都会好的

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    xmlns:xml="http://www.w3.org/XML/1998/namespace" 
    targetNamespace='urn:ietf:params:xml:ns:xmpp-stanzas'
    xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'
    elementFormDefault='qualified'>

    <xs:import schemaLocation="http://www.w3.org/2001/xml.xsd" namespace="http://www.w3.org/XML/1998/namespace"/>

    <xs:element name='bad-request' type='empty'/>
    <xs:element name='conflict' type='empty'/>
    <xs:element name='feature-not-implemented' type='empty'/>
    <xs:element name='forbidden' type='empty'/>
    <xs:element name='gone' type='xs:string'/>
    <xs:element name='internal-server-error' type='empty'/>
    <xs:element name='item-not-found' type='empty'/>
    <xs:element name='jid-malformed' type='empty'/>
    <xs:element name='not-acceptable' type='empty'/>
    <xs:element name='not-allowed' type='empty'/>
    <xs:element name='not-authorized' type='empty'/>
    <xs:element name='payment-required' type='empty'/>
    <xs:element name='policy-violation' type='empty'/>
    <xs:element name='recipient-unavailable' type='empty'/>
    <xs:element name='redirect' type='xs:string'/>
    <xs:element name='registration-required' type='empty'/>
    <xs:element name='remote-server-not-found' type='empty'/>
    <xs:element name='remote-server-timeout' type='empty'/>
    <xs:element name='resource-constraint' type='empty'/>
    <xs:element name='service-unavailable' type='empty'/>
    <xs:element name='subscription-required' type='empty'/>
    <xs:element name='undefined-condition' type='empty'/>
    <xs:element name='unexpected-request' type='empty'/>

    <xs:group name='stanzaErrorGroup'>
        <xs:choice>
            <xs:element ref='bad-request'/>
            <xs:element ref='conflict'/>
            <xs:element ref='feature-not-implemented'/>
            <xs:element ref='forbidden'/>
            <xs:element ref='gone'/>
            <xs:element ref='internal-server-error'/>
            <xs:element ref='item-not-found'/>
            <xs:element ref='jid-malformed'/>
            <xs:element ref='not-acceptable'/>
            <xs:element ref='not-authorized'/>
            <xs:element ref='not-allowed'/>
            <xs:element ref='payment-required'/>
            <xs:element ref='policy-violation'/>
            <xs:element ref='recipient-unavailable'/>
            <xs:element ref='redirect'/>
            <xs:element ref='registration-required'/>
            <xs:element ref='remote-server-not-found'/>
            <xs:element ref='remote-server-timeout'/>
            <xs:element ref='resource-constraint'/>
            <xs:element ref='service-unavailable'/>
            <xs:element ref='subscription-required'/>
            <xs:element ref='undefined-condition'/>
            <xs:element ref='unexpected-request'/>
        </xs:choice>
    </xs:group>

    <xs:element name='text'>
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base='xs:string'>
                    <xs:attribute ref='xml:lang' use='optional'/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

    <xs:simpleType name='empty'>
        <xs:restriction base='xs:string'>
            <xs:enumeration value=''/>
        </xs:restriction>
    </xs:simpleType>

</xs:schema>

我对XMPP并不熟悉,但我怀疑你的模式是要导入另一个已经声明了XML命名空间的模式。