Solved

Drop-down Menu in XML

Posted on 2004-08-09
4
639 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
Comment Utility
<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
Comment Utility
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
Comment Utility

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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

744 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

14 Experts available now in Live!

Get 1:1 Help Now