Question

In XMLSpy, there is a validation error, "Value '18' is not allowed for attribute 'name'. Hint: A valid value would be 'NCName'. Error location: xs:schema / xs:element / xs:complexType / xs:choice / xs:element / xs:complexType / xs:choice / xs:element / @name" here:

<xs:element name="Age">
                <xs:complexType>
                    <xs:choice>
                        <xs:element name="18" type="xs:int"/>

If I enter letters it validates, but I need numbers in that field.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.urent.com/Elmhurst" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.urent.com/Elmhurst" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="URent">
        <xs:annotation>

        </xs:annotation>
        <xs:complexType>
            <xs:choice>
                <xs:element name="RentalPeriod">
                    <xs:complexType>
                        <xs:all>
                            <xs:element name="StartDate" type="xs:date"/>
                            <xs:element name="EndDate" type="xs:date"/>
                        </xs:all>
                    </xs:complexType>
                </xs:element>
                <xs:element name="Age">
                <xs:complexType>
                    <xs:choice>
                        <xs:element name="18" type="xs:int"/>
                        <xs:element name="19" type="xs:int"/>
                        <xs:element name="20" type="xs:int"/>
                        <xs:element name="21" type="xs:int"/>
                        <xs:element name="22" type="xs:int"/>
                        <xs:element name="23" type="xs:int"/>
                        <xs:element name="24" type="xs:int"/>
                        <xs:element name="25+" type="xs:int"/>
                    </xs:choice>
                </xs:complexType>
            </xs:element>
            <xs:element name="RateCode">
                <xs:complexType>
                    <xs:choice>
                        <xs:element name="Corporate" type="xs:string"/>
                        <xs:element name="Leisure" type="xs:string"/>
                    </xs:choice>
                </xs:complexType>
            </xs:element>
            <xs:element name="TypeOfVehicle">
                <xs:complexType>
                    <xs:all>
                        <xs:element name="Subcompact" type="xs:string"/>
                        <xs:element name="Compact" type="xs:string"/>
                        <xs:element name="Intermediate" type="xs:string"/>
                        <xs:element name="Standard" type="xs:string"/>
                        <xs:element name="Full Size" type="xs:string"/>
                        <xs:element name="Premium" type="xs:string"/>
                        <xs:element name="Luxury" type="xs:string"/>
                        <xs:element name="Standard Elite SUV" type="xs:string"/>
                        <xs:element name="Intermediate SUV" type="xs:string"/>
                        <xs:element name="Minivan" type="xs:string"/>
                        <xs:element name="Full Size SUV" type="xs:string"/>
                        <xs:element name="Standard SUV" type="xs:string"/>
                        <xs:element name="Premium SUV" type="xs:string"/>
                    </xs:all>
                </xs:complexType>
            </xs:element>
            <xs:element name="Residence">
                <xs:complexType>
                    <xs:choice>
                        <xs:element name="US" type="xs:string"/>
                        <xs:element name="OutsideUS" type="xs:string"/>
                    </xs:choice>
                </xs:complexType>
            </xs:element>
            <xs:element name="SpecialEquipment">
                <xs:complexType>
                    <xs:choice>
                        <xs:element name="GPS Navigation" type="xs:string"/>
                        <xs:element name="XM Radio" type="xs:string"/>
                        <xs:element name="Fuel Service" type="xs:string"/>
                        <xs:element name="Child Safety Seats" type="xs:string"/>
                    </xs:choice>
                </xs:complexType>
            </xs:element>
            <xs:element name="Customer Info">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="FirstName" type="xs:string"/>
                        <xs:element name="LastName" type="xs:string"/>
                        <xs:element name="EmailAddress" type="xs:string"/>
                        <xs:element name="PhoneNumber" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:choice>
    </xs:complexType>
</xs:element>

Was it helpful?

Solution

Taken literally, your declaration says the set of valid Age elements includes <Age><18>45</18></Age> and <Age><25+>33</25+></Age>, though not <Age><45>18</45></Age>.

But '18' and '25+' are not allowed by XML as names of element types; like names of variables in most programming languages, names of element types in XML must begin with a letter. (They are also not allowed to contain blanks, so the element names "Full Size" and "Standard Elite SUV" will also raise errors.) So the examples given in the preceding paragraph are not XML, and you cannot define an XSD schema against which they would be valid.

It's not clear whether you need to review the basics of XML or the basics of XSD, but your work developing a schema will be more pleasant and productive if you have a better grasp of the technologies you are trying to use; that helps you work with the grain of the technology and not against it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top