xsd Restriction base ID with Number ID

Viewed 66

I have a problem to define my data Type, this is my xsd file:

<xs:simpleType name="maso_Type">        
    <xs:restriction base="xs:ID">
        <xs:pattern value="[0-9]+"/>
    </xs:restriction>   
</xs:simpleType>

And this is my xml file:

<cuahang xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:noNamespaceSchemaLocation="dulieu.xsd">
   <sach soluong="1">
      <maso>1</maso>
      <tieude>Gotich</tieude>
      <nhaxuatban>KimDong</nhaxuatban>
      <tacgia>KimDong</tacgia>
      <hinhanh>hinhanhs/sachs/KientrucGotich.jpg</hinhanh>
      <giaca>7500</giaca>
      <tinhtrang>Con</tinhtrang>
      <theloai>nghethuat</theloai>
   </sach>
</cuahang>

I want my "maso" base on ID (is only for each), no duplicated. Its work if I define it is integer but it's not only. If I define base on ID, I got this when validate the xml:

cvc-datatype-valid.1.2.1: '1' is not a valid value for 'NCName'. [7] 
cvc-type.3.1.3: The value '1' of element 'maso' is not valid. [7] 
1 Answers

The answer is here: https://www.w3.org/TR/xmlschema-2/#ID

The ·value space· of ID is the set of all strings that ·match· the NCName production in Namespaces in XML

If you follow the link, it says:

[4] NCName     ::= (Letter | '_') (NCNameChar)* /*  An XML Name, minus the ":" */
[5] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender

So an NCName is not allowed to start with a digit. Therefore an ID is also not allowed to start with a digit.

Related