Solved

Drop-down Menu in XML

Posted on 2004-08-09
4
641 Views
Last Modified: 2013-11-19

Hi,

Is it possible to have a drop-down menu, or something similar to it in XML Schema? I have an element called paymentFrequency and there are basicly 7 different possible types. How can I get it so that a person creating an XML document using my schema will end up picking one of these values in the paymentFrequency element?

Thanks
0
Comment
Question by:fyness
  • 2
4 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 11755051
<form name="Form1">
<select name="paymentFrequency">
<option value="" selected="selected">Select one</option>
<xsl:for-each select="/....">
<option value="{PaymentFrequency}">
<xsl:value-of select="PaymentFrequency"/>
</option>
</xsl:for-each>
</select>
</form>
0
 
LVL 26

Accepted Solution

by:
rdcpro earned 125 total points
ID: 11758758
Use the Enumeration facet to restrict the string type:

<xsd:simpleType name="paymentFrequencyType">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="Here is one type"/>
    <xsd:enumeration value="Ok, this is good too."/>
    <xsd:enumeration value="Maybe you want this one?"/>
    <!-- and so on ... -->
  </xsd:restriction>
</xsd:simpleType>

Whether or not the application the person is using will provide a dropdown based on the schema is dependant on the editor itself.  Notepad, for example, doesn't care anything about schemas.  XML Spy, on the other hand, will examine the schema, and figure out what values are allowed in context.  When you create a new element of that type, XML Spy will show you a list of allowable values, for you to pick from.

Regards,
Mike Sharp
0
 

Author Comment

by:fyness
ID: 11760348

Thanks for your reply, just wanted clear something up.
So are you saying that I restrict the value using an attribute within the element of paymentFrequency?

Suzy
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 11763429
No, I'm saying the W3C XML Schema can restrict the value of paymentFrequency directly.  The Schema defines the content model for paymentFrequency.  There are a number of different ways to accomplish the same thing in Schema, and the above example showed one way, by defining a simpleType.  You then create your element declaration like:

<xs:element name = "paymentFrequency" type="user:paymentFrequencyType" />

I can only guess at the exact syntax, as it depends on how you've declared your namespace, and how you've constructed the schema.  So my example might not cut-and-paste into your schema, but it shows the approach.

Regards,
Mike Sharp
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

813 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

18 Experts available now in Live!

Get 1:1 Help Now