Solved

Restrictions on attribute values

Posted on 2007-03-27
3
366 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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