Xml XSD中忽略了目标命名空间
我有一些供应商提供的XML模式。这是: OCISchemaBASE.xsdXml XSD中忽略了目标命名空间,xml,xsd,xml-namespaces,xmllint,Xml,Xsd,Xml Namespaces,Xmllint,我有一些供应商提供的XML模式。这是: OCISchemaBASE.xsd <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="C" targetNamespace="C"> <xs:element name="BroadsoftDocument" type="OCIMessage"/> <xs:complexType name="OCIMessage"> <xs
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="C" targetNamespace="C">
<xs:element name="BroadsoftDocument" type="OCIMessage"/>
<xs:complexType name="OCIMessage">
<xs:sequence>
<xs:choice>
<xs:element name="sessionId" type="xs:normalizedString"/>
<xs:element name="userId" type="xs:token"/>
<xs:element name="phoneNumber" type="xs:token"/>
</xs:choice>
<xs:element name="command" type="OCICommand" minOccurs="1" maxOccurs="15"/>
</xs:sequence>
<xs:attribute name="protocol" use="required">
<xs:simpleType>
<xs:restriction base="xs:NMTOKEN">
<xs:enumeration value="OCI"/>
<xs:enumeration value="NSOCI"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:complexType name="OCICommand" abstract="true">
<xs:sequence>
</xs:sequence>
<xs:attribute name="echo" type="xs:string" use="optional"/>
</xs:complexType>
<xs:complexType name="OCIRequest" abstract="true">
<xs:complexContent>
<xs:extension base="OCICommand">
<xs:sequence>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
为什么BroadsoftDocument
元素不在C
命名空间中,尽管OCISchemaBASE.xsd中有目标命名空间声明
同样的问题是关于消息类型中的
sessionId
元素。您必须让XML处理程序知道在哪里可以找到XML的XSD
一种方法是将schemaLocation
添加到根BroadsoftDocument元素:
<BroadsoftDocument
xsi:schemaLocation="C OCISchemaBASE.xsd"
[...]
是因为您过于简化的命名空间C
,被解释为一个相对URI,它是:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:core="C" attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:simpleType name="UserId">
<xs:restriction base="xs:token">
<xs:minLength value="1"/>
<xs:maxLength value="161"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
<?xml version="1.0" encoding="ISO-8859-1"?>
<BroadsoftDocument
protocol="OCI" xmlns="C"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<sessionId xmlns="">1405499871130</sessionId>
<command xsi:type="AuthenticationRequest" xmlns="">
<userId>user@xdp.broadsoft.com</userId>
</command>
</BroadsoftDocument>
$ xmllint --noout --schema OCISchemaLogin.xsd --schema OCISchemaBASE.xsd --schema OCISchemaDataTypes.xsd ./AuthenticationRequest.xml
./AuthenticationRequest.xml:3: namespace warning : xmlns: URI C is not absolute
protocol="OCI" xmlns="C"
^
Element '{C}BroadsoftDocument': No matching global declaration available for the validation root.
./AuthenticationRequest.xml fails to validate
<BroadsoftDocument
xsi:schemaLocation="C OCISchemaBASE.xsd"
[...]
./AuthenticationRequest.xml:3: namespace warning : xmlns: URI C is not absolute
protocol="OCI" xmlns="C"
The use of relative URI references, including same-document references,
in namespace declarations is deprecated.