Solved

Restrictions on attribute values

Posted on 2007-03-27
3
373 Views
Last Modified: 2007-03-27
Hi,

XML and XSD newbie here.  Is it possible to restrict the values of an attribute?  Below is my try #1 but it doesn't work.

......
......
<xs:attribute name="intHour" type="xs:int" use="required" >
                <xs:simpleType>
                  <xs:restriction base="xs:integer">
                        <xs:minInclusive value="0"/>
                        <xs:maxInclusive value="23"/>
                  </xs:restriction>
            </xs:simpleType>
    </xs:attribute>
  </xs:complexType>

how can I make intHour only accept values from 0 to 23?

Many thanks...

0
Comment
Question by:brdrok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 18799808
you can't give the type twice
If you set the type of the attribute (type="xs:int")
you can't redefine it in the xs:attribute content
drop that and you will be OK

    <xs:element name="test">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="time" >
                        <xs:simpleType>
                            <xs:restriction base="xs:integer">
                                <xs:minInclusive value="0"/>
                                <xs:maxInclusive value="23"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

    cheers

Geert
0
 
LVL 7

Author Comment

by:brdrok
ID: 18800081
Awesome,

always great to have another pair of eyes looking at stuff =)

Thanks
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 18800374
welcome
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question