0
这是我的模式。我将它作为XML Doc中的一个属性。电话号码的XSD限制出错
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xml.netbeans.org/schema/ThueBao"
xmlns:tns="http://xml.netbeans.org/schema/ThueBao"
elementFormDefault="qualified">
<xsd:simpleType name="tTen">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:simpleType name="tSDT">
<xsd:restriction base="xsd:ID">
<xsd:pattern value="[0]{1}[0-9]{9}[0-9]*"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="tSDTGoiDi">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0]{1}[0-9]{9}[0-9]*"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:simpleType name="tDiaBan">
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
<xsd:simpleType name="tThoiGianGoi">
<xsd:restriction base="xsd:duration"/>
</xsd:simpleType>
<xsd:complexType name="tThueBao">
<xsd:sequence>
<xsd:element name="HoTen" type="tns:tTen"></xsd:element>
<xsd:element name="DiaBan" type="tns:tDiaBan"></xsd:element>
<xsd:element name="SoDienThoaiGoiDi" type="tns:tSDTGoiDi"></xsd:element>
<xsd:element name="ThoiGianGoi" type="tns:tThoiGianGoi"></xsd:element>
</xsd:sequence>
<xsd:attribute name="SDT" type="tns:tSDT"/>
</xsd:complexType>
<xsd:element name="DSThueBao">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ThueBao" type="tns:tThueBao"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
这是我的XML。
<ns0:ThueBao SDT="0984224932">
<ns0:HoTen>Pham Tuan Manh</ns0:HoTen>
<ns0:DiaBan>Ha Noi</ns0:DiaBan>
<ns0:SoDienThoaiGoiDi>01635981989</ns0:SoDienThoaiGoiDi>
<ns0:ThoiGianGoi>PT2M</ns0:ThoiGianGoi>
</ns0:ThueBao>
在验证上,NetBeans总是显示此错误:
cvc-datatype-valid.1.2.1: '0984224932' is not a valid value for 'NCName'. [15]
cvc-attribute.3: The value '0984224932' of attribute 'SDT' on element 'ns0:ThueBao' is not valid with respect to its type, 'tSDT'. [15]
我有两个电话号码在我的XML。第二个被接受,但是第一个。我不知道这是如何发生的。 我该如何解决这个问题? 在此先感谢!
非常感谢您的明确的解释,Mr.Kay。 我编辑了我的代码,它与和完美配合。 再一次,非常感谢! –
Manhhailua
2013-05-08 11:45:21