small XML schema problem

Discussion in 'OT Technology' started by spahndirge, Jan 28, 2009.

  1. spahndirge

    spahndirge Scumbag Member

    Joined:
    Jul 15, 2005
    Messages:
    421
    Likes Received:
    0
    Just learning XML and trying to create the schema for this file:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <breakfast_menu>
        <food>
            <name>Belgian Waffles</name>
            <price>$5.95</price>
            <description>two of our famous Belgian Waffles with plenty of real maple syrup</description>
            <calories>650</calories>
        </food>
        <food>
            <name>Strawberry Belgian Waffles</name>
            <price>$7.95</price>
            <description>light Belgian waffles covered with strawberries and whipped cream</description>
            <calories>900</calories>
        </food>
        <food>
            <name>Berry-Berry Belgian Waffles</name>
            <price>$8.95</price>
            <description>light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
            <calories>900</calories>
        </food>
    </breakfast_menu>
    
    Here's what I have so far

    Code:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="breakfast_menu">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="food" maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="name" type="xs:string"/>
    <xs:element name="price">
    <xs:simpleType>
    <xs:restriction base="xs:decimal">
    <xs:pattern value="[$]"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element name="description" type="xs:string"/>
    <xs:element name="calories" type="xs:integer"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    
    However, when I try and validate them at here:

    http://www.xmlme.com/Validator.aspx?mid=83

    It says the price is the wrong data type, I know it's because of the $. But I'm really confused about defining it with regulkar expressions. I've checked out w3c and still no luck. Anyone care to help?
     
  2. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    you could just remove the $ and say it's a float type
     
  3. spahndirge

    spahndirge Scumbag Member

    Joined:
    Jul 15, 2005
    Messages:
    421
    Likes Received:
    0
    Tried that out and didn't work, worked it out in the end. The pattern value should have been:

    Code:
    <xs:pattern value="[$].*"/>
    
     

Share This Page