简体   繁体   English

针对XSD模式验证xml-没有匹配的全局声明

[英]Validating xml against xsd schema - no matching global declaration

I'm running into trouble while validating my XML file. 验证XML文件时遇到麻烦。 Error message is "Element '{some_namespace}contact': No matching global declaration available for the validation root." 错误消息是“元素'{some_namespace}联系人':没有匹配的全局声明可用于验证根”。

I do realize there must be something wrong with namespaces but after hours of fighting I cannot make it work (validate). 我确实意识到名称空间一定存在问题,但经过数小时的奋战,我无法使其正常工作(验证)。

I hope you can help me with this; 我希望你能帮我这个忙; maybe there's a stupid thing I'm missing all the time (I'm quite new to XML/XSD topic). 也许我一直都想念一个愚蠢的东西(我对XML / XSD话题很陌生)。

My XML 我的XML

   <?xml version="1.0" encoding="utf-8" ?>
   <abc:contact xmlns:abc="some_namespace">
     <session>d22737b4aad7b641eea7c85e7294426b84b73713</session>
     <id>23372455488</id>
   </abc:contact>

XSD XSD

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:targetNamespace="some_namespace">
  <xsd:element name="contact">
    <xsd:complexType>
      <xsd:all>
        <xsd:element name="session" type="xsd:string"/>
        <xsd:element name="id" type="xsd:integer"/>
      </xsd:all>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

To validate I use xmllint (console), NPP+XML Tools and PHP (DOMDocument::schemaValidate) - all with the same result. 为了进行验证,我使用xmllint(控制台),NPP + XML工具和PHP(DOMDocument :: schemaValidate)-都具有相同的结果。

In your schema document, replace 在架构文档中,替换

xmlns:targetNamespace="some_namespace"

with

targetNamespace="some_namespace"

(The target namespace of the schema document is identified using the targetNamespace attribute on the schema element, not by binding a magic namespace prefix to the target namespace.) (使用schema元素上的targetNamespace属性标识架构文档的目标名称空间,而不是通过将魔术名称空间前缀绑定到目标名称空间来进行标识。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM