Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with XML Schema

Status
Not open for further replies.

likeasomeboody

Technical User
Aug 4, 2010
1
SE
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"/>
<xs:pattern value="$\d{2}.\d{2} | $\d{1}.\d{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

As you can se here: <xs:pattern 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!
 
[0]
><xs:pattern value="$\d{2}.\d{2} | $\d{1}.\d{2}"/>
[tt]<xs:pattern value="$\d{2}[red]\[/red].\d{2[highlight]}|$[/highlight]\d{1}[red]\[/red].\d{2}"/>[/tt]

[1] The first two conditions are redundant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top