我正在尝试使用XSD验证示例Auth XML,该示例由aadhar开发人员门户网站提供,但收到错误:
Type 'http://www.uidai.gov.in/authentication/common/types/1.0:uid' is not declared, or is not a simple type)
但在auth XML中我指定了uid
元素。
Auth XML:
<Auth xmlns="http://www.uidai.gov.in/authentication/uid-ath-request/1.0" ac="public" lk="MBFWjkJHNF-fLidl8oOHtUwgL5p1ZjDbWrqsMEVEJLVEDpnlNj_CZTg" sa="public" tid="public" uid="999991260711" ver="1.6" txn="AuthDemoClient:public:20160701120821">
<Uses pi="y" pa="n" pfa="n" bio="n" pin="n" otp="n" />
<Meta udc="UIDAI:SampleClient" fdc="NA" idc="NA" pip="127.0.0.1" lot="P" lov="110002" />
<Skey ci="20200916"></Skey>
<Data type="X"></Data>
<Hmac></Hmac>
</Auth>
auth XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.uidai.gov.in/authentication/uid-auth-request/1.0"
xmlns:tns="http://www.uidai.gov.in/authentication/uid-auth-request/1.0"
elementFormDefault="qualified"
xmlns:ar="http://www.uidai.gov.in/authentication/uid-auth-request-data/1.0"
xmlns:common="http://www.uidai.gov.in/authentication/common/types/1.0">
<xs:import namespace="http://www.uidai.gov.in/authentication/common/types/1.0"
schemaLocation="common-types.xsd" />
<xs:simpleType name="TknType">
<xs:restriction base="xs:string">
<xs:enumeration value="001">
<xs:annotation>
<xs:documentation>Mobile number</xs:documentation>
</xs:annotation>
</xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="TknValue">
<xs:restriction base="xs:string">
<xs:maxLength value="100"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Tkn">
<xs:attribute name="type" type="tns:TknType"></xs:attribute>
<xs:attribute name="value" type="tns:TknValue"></xs:attribute>
</xs:complexType>
<xs:simpleType name="UsesFlag">
<xs:restriction base="xs:string">
<xs:enumeration value="y"></xs:enumeration>
<xs:enumeration value="n"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Uses">
<xs:attribute name="pi" use="required" type="tns:UsesFlag" />
<xs:attribute name="pa" use="required" type="tns:UsesFlag" />
<xs:attribute name="pfa" use="required" type="tns:UsesFlag" />
<xs:attribute name="bio" use="required" type="tns:UsesFlag" />
<xs:attribute name="bt" type="xs:string" />
<xs:attribute name="pin" use="required" type="tns:UsesFlag" />
<xs:attribute name="otp" use="required" type="tns:UsesFlag" />
</xs:complexType>
<xs:complexType name="Skey">
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="ci" type="xs:string">
<xs:annotation>
<xs:documentation>
Certificate identifier - should be expiry date of certificate in YYYYMMDD format
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ki" type="xs:string" use="optional">
<xs:annotation>
<xs:documentation>
Unique key identifier
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="DataType">
<xs:restriction base="xs:string">
<xs:enumeration value="X"></xs:enumeration>
<xs:enumeration value="P"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Auth">
<xs:sequence>
<xs:element name="Tkn" type="tns:Tkn" minOccurs="0" />
<xs:element name="Uses" type="tns:Uses" />
<xs:element name="Meta" type="common:Meta" />
<xs:element name="Skey" type="tns:Skey" />
<xs:element name="Data" >
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="type" type="tns:DataType" default="X" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Hmac" type="xs:base64Binary" />
</xs:sequence>
<xs:attribute name="uid" type="common:uid" use="required" />
<xs:attribute name="ac" type="common:AuaCode" use="required" />
<xs:attribute name="tid" type="common:Tid" use="required" />
<xs:attribute name="ver" type="common:Ver" />
<xs:attribute name="txn" type="common:Txn" use="required" />
<xs:attribute name="lk" type="common:LicenseKey" use="required" />
<xs:attribute name="sa" type="common:AuaCode" use="required" />
</xs:complexType>
<xs:element name="Auth" type="tns:Auth"></xs:element>
</xs:schema>
共types.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.uidai.gov.in/authentication/common/types/1.0"
xmlns:tns="http://www.uidai.gov.in/authentication/common/types/1.0"
elementFormDefault="qualified">
<xs:simpleType name="uid">
<xs:restriction base="xs:string">
<xs:pattern value="\d{12}"></xs:pattern>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="pin">
<xs:restriction base="xs:string">
<xs:pattern value="\d{6}"></xs:pattern>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="otp">
<xs:restriction base="xs:string">
<xs:pattern value="\d{6}"></xs:pattern>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="LicenseKey">
<xs:restriction base="xs:string">
<xs:maxLength value="200"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Tid">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9\.,-\\/():]*"></xs:pattern>
<xs:maxLength value="50"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Ver">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9\.,-\\/():]*"></xs:pattern>
<xs:maxLength value="10"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Txn">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9\.,-\\/():]*"></xs:pattern>
<xs:maxLength value="50"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="AuaCode">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9]*"></xs:pattern>
<xs:maxLength value="10"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Geocode">
<xs:restriction base="xs:string">
<xs:maxLength value="100"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Latitude">
<xs:restriction base="xs:string">
<xs:maxLength value="100"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Longitude">
<xs:restriction base="xs:string">
<xs:maxLength value="100"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="LocationType">
<xs:restriction base="xs:string">
<xs:enumeration value="G"></xs:enumeration>
<xs:enumeration value="P"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="Meta">
<xs:attribute name="udc" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="20"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="pip" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="60"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="fdc" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="idc" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="10"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="lot" type="tns:LocationType" use="required">
<xs:annotation>
<xs:documentation>Location Type</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="lov" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"></xs:maxLength>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:simpleType name="FingerPosition">
<xs:restriction base="xs:string">
<xs:annotation>
<xs:documentation>
Finger positions
</xs:documentation>
</xs:annotation>
<xs:enumeration value="LEFT_INDEX"></xs:enumeration>
<xs:enumeration value="LEFT_LITTLE"></xs:enumeration>
<xs:enumeration value="LEFT_MIDDLE"></xs:enumeration>
<xs:enumeration value="LEFT_RING"></xs:enumeration>
<xs:enumeration value="LEFT_THUMB"></xs:enumeration>
<xs:enumeration value="RIGHT_INDEX"></xs:enumeration>
<xs:enumeration value="RIGHT_LITTLE"></xs:enumeration>
<xs:enumeration value="RIGHT_MIDDLE"></xs:enumeration>
<xs:enumeration value="RIGHT_RING"></xs:enumeration>
<xs:enumeration value="RIGHT_THUMB"></xs:enumeration>
<xs:enumeration value="UNKNOWN"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>
答案 0 :(得分:3)
在您的XML文件中,名称空间声明中只有一个字符拼写错误,很难注意到。
要解决此问题,请更改
<Auth xmlns="http://www.uidai.gov.in/authentication/uid-ath-request/1.0"
到
<Auth xmlns="http://www.uidai.gov.in/authentication/uid-auth-request/1.0"
然后您的XML将按预期验证。