Hello everyone!
I am new to XML and I am working on XSDs at the moment. I am supposed to validate an xml document that is based on credit cards. I have worked through most of the assignment, but I am stuck on declaring an element that must be a positive floating point number, while also allowing that element to have a required attribute, which must have a 3 letter currency type associated with it.
Here is an example of the XML element I have to validate:
<total curId="USD">4003.46</total>
Here is what I have:
<xsd:element name="total" type="validAmount"/>
<xsd:complexType name="validAmount">
<xsd:simpleContent>
<xsd:extension base="xsd:decimal">
<xsd:attribute name= "curId" type = "currencyAttribute" use="required"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
For the curId attribute:
<xsd:simpleType name="currencyAttribute">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[A-Z]{3}"/>
</xsd:restriction>
</xsd:simpleType>
The problem I am having is trying to change the extension to a restriction, allowing the decimal to be a positive number (perhaps changing its type to a string and using a pattern facet to restrict it to a positive number). However the script I am using to validate the xml doc throws errors if I do so. I know I am probably missing something painfully obvious, but like I said, I am new to this so any help would be greatly appreciated.