Solved

Restrictions on attribute values

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to get the parent segment field value in an xml using XSLT 6 27
Merge XML into DOM 5 27
c# code 19 61
XML & .net 5 20
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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now