我正在尝试使用xsd验证一个非常简单的xml,但由于某种原因我得到了这个错误.如果有人能解释我为什么,我真的很感激.
XML文件
<?xml version="1.0" encoding="utf-8"?>
<MyElement>A</MyElement>
Run Code Online (Sandbox Code Playgroud)
XSD文件
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Test"
xmlns:tns="http://www.example.org/Test"
elementFormDefault="qualified">
<simpleType name="MyType">
<restriction base="string"></restriction>
</simpleType>
<element name="MyElement" type="tns:MyType"></element>
</schema>
Run Code Online (Sandbox Code Playgroud) 我对XML Schema等仍然有点新,并且一直致力于开发一些XML,Schema和样式表(XSLT).我已经取得了合理的进展,但随后意识到我的架构已停止工作,所以我把它带回了一个更简单的非描述性示例.
这是我的XML:
<?xml version="1.0" encoding="UTF-8"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="Test.Namespace"
schemaLocation="http://myNameSpace.com Test1.xsd">
<element1 id="001">
<element2 id="001.1">
<element3 id="001.1" />
</element2>
</element1>
</Root>
Run Code Online (Sandbox Code Playgroud)
我写了一个Schema,它在这里:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="Test.Namespace"
elementFormDefault="qualified">
<xsd:element name="Root">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="element1" maxOccurs="unbounded" type="element1Type"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="element1Type">
<xsd:sequence>
<xsd:element name="element2" maxOccurs="unbounded" type="element2Type"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="element2Type">
<xsd:sequence>
<xsd:element name="item" type="element3Type"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
<xsd:complexType name="element3Type">
<xsd:attribute name="id" type="xsd:string"/>
</xsd:complexType>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
Schema代表了我真正的XML结构.
现在,当我尝试验证我的XML时,我收到此错误:
cvc-elt.1: Cannot find the declaration of element 'Root'. [7] …
我收到了这个WSDL,我遇到了XSD的问题.
我似乎无法在我的XSD文件中找到问题.
什么没约束?我怎么解决这个问题?
error: The prefix "xsd" for element "xsd:schema" is not bound.
Run Code Online (Sandbox Code Playgroud)
这是XSD文件的一部分:
<xsd:schema targetNamespace="http://www.informatica.com/wsdl/"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns="http://www.informatica.com/wsdl/"
xmlns:infatype="http://www.informatica.com/types/">
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/http/"/>
<xsd:element name="SHA003Bis_GetArticleDataResponse"
type="SHA003Bis_GetArticleDataResponseType"/>
<xsd:element name="SHA003Bis_GetArticleDataRequest"
type="SHA003Bis_GetArticleDataRequestType"/>
<xsd:complexType name="SHA003Bis_GetArticleDataRequestType">
<xsd:sequence>
<xsd:element name="SHA003Bis_GetArticleDataRequestElement">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Company" minOccurs="0" maxOccurs="1">
<xsd:simpleType>
<xsd:restriction base="xsd:integer"/>
</xsd:simpleType>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)
这是WSDL的一部分:
<wsdl:definitions targetNamespace="http://www.informatica.com/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:n="http://www.informatica.com/wsdl/"
xmlns:infa="http://www.informatica.com/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<xsd:schema targetNamespace="http://www.informatica.com/wsdl/"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns="http://www.informatica.com/wsdl/"
xmlns:infatype="http://www.informatica.com/types/">
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/http/"/>
<xsd:element name="SHA003Bis_GetArticleDataResponse"
type="SHA003Bis_GetArticleDataResponseType"/>
<xsd:element name="SHA003Bis_GetArticleDataRequest"
type="SHA003Bis_GetArticleDataRequestType"/>
<xsd:complexType name="SHA003Bis_GetArticleDataRequestType">
<xsd:sequence>
<xsd:element name="SHA003Bis_GetArticleDataRequestElement">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Company" …Run Code Online (Sandbox Code Playgroud)