likeasomeboody
Technical User
Hello all. I have a problem with my xml schema. I want to make that the schema will only allow a certain value. For examlpe. The thing i have problems with is that the code i wrote is wrong in validating prices: In my schema file it's:
$14,95
or even:
$9.95. So my code is this.
<xs:schema xmlns:xs=" <xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element ref="book" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="author"/>
<xs:element ref="genre"/>
<xs:element ref="format"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="genre" type="xs:string"/>
<xs:element name="format" type="xs:string"/>
<xs:element name="price" type="priceType"/>
<xs:simpleType name="priceType">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="9"/>
<xsattern value="$\d{2}.\d{2} | $\d{1}.\d{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
As you can se here: <xsattern value="$\d{2}.\d{2} | $\d{1}.\d{2}"/> I try to validate the prices (american dollars, 1 or 2 digits, a dot and another 2 digits.). Why dose this not work? What am i doing wrong and how do i fix it? All help is apreciated. Thank you all!
$14,95
or even:
$9.95. So my code is this.
<xs:schema xmlns:xs=" <xs:element name="books">
<xs:complexType>
<xs:sequence>
<xs:element ref="book" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="book">
<xs:complexType>
<xs:sequence>
<xs:element ref="title"/>
<xs:element ref="author"/>
<xs:element ref="genre"/>
<xs:element ref="format"/>
<xs:element ref="price"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="title" type="xs:string"/>
<xs:element name="author" type="xs:string"/>
<xs:element name="genre" type="xs:string"/>
<xs:element name="format" type="xs:string"/>
<xs:element name="price" type="priceType"/>
<xs:simpleType name="priceType">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="9"/>
<xsattern value="$\d{2}.\d{2} | $\d{1}.\d{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
As you can se here: <xsattern value="$\d{2}.\d{2} | $\d{1}.\d{2}"/> I try to validate the prices (american dollars, 1 or 2 digits, a dot and another 2 digits.). Why dose this not work? What am i doing wrong and how do i fix it? All help is apreciated. Thank you all!