Solved

Drop-down Menu in XML

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
carriage return in xslt cell 13 63
Web Application Architecture 6 75
Advice on what platform to use for a web app for AWS 3 94
Grunt No Clean Targets 6 109
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
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.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

895 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

13 Experts available now in Live!

Get 1:1 Help Now