Solved

Drop-down Menu in XML

Posted on 2004-08-09
4
645 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
[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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

688 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