XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 18th, 2003, 05:08 PM
don_sparko's Avatar
don_sparko don_sparko is offline
Digitally Challenged
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 280 don_sparko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 14 sec
Reputation Power: 6
using xml to create options in a form

can anyone show me an example of how to get xml values into an option on a form? i'm using asp if that helps. probably not. oh, here is some of my xml structure so you get an idea.
Code:
<?xml version='1.0'?>
<Hardware>
	<Listing>
		<HardwareID>1</HardwareID>
		<Manufacturer>Compaq</Manufacturer>
		<Product>EVO</Product>
	</Listing>
	<Listing>
		<HardwareID>2</HardwareID>
		<Manufacturer>IBM</Manufacturer>
		<Product>T30</Product>
	</Listing>
	<Listing>
		<HardwareID>3</HardwareID>
		<Manufacturer>Sony</Manufacturer>
		<Product>Vaio</Product>
	</Listing>
</Hardware>
__________________
My brain cells are like a storm trooper's armor: useless

Reply With Quote
  #2  
Old August 20th, 2003, 03:33 PM
Pahikua Pahikua is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 31 Pahikua User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 32 m 46 sec
Reputation Power: 7
I did this very thing at this website here:

http://www.thebestrentalsinhawaii.com

The rental search on the left side of the page is created using XML and XSLT.

Heres a short example of what I did.

The XML:

<?xml version="1.0" encoding="UTF-8"?>
<search>
<category name="some_name1">
<option value="1">Option Text1</option>
<option value="2">Option Text2</option>
<option value="3">Option Text3</option>
</category>
<category name="some_name2">
<option value="1">Option Text1</option>
<option value="2">Option Text2</option>
<option value="3">Option Text3</option>
</category>
<category name="some_name3">
<option value="1">Option Text1</option>
<option value="2">Option Text2</option>
<option value="3">Option Text3</option>
</category>
</search>

The XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<form action="form_name.php" method="post">
<xsl:apply-templates select="search/category"/>
<br/><br/>
<input type="submit" value="Search"/>
</form>
</xsl:template>

<xsl:template match="category">
<select name="{@name}">
<xsl:copy-of select="option"/><br/>
</select>
</xsl:template>

</xsl:stylesheet>

The <xsl:copy-of directive copies the entire option node of the XML directly to the page.

Hope this helps.

Last edited by Pahikua : August 20th, 2003 at 03:35 PM.

Reply With Quote
  #3  
Old September 2nd, 2003, 02:51 AM
unatratnag unatratnag is offline
Average Intelligence
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2003
Location: Ohio/Chicago
Posts: 678 unatratnag User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 22 sec
Reputation Power: 6
Send a message via AIM to unatratnag
It would be wise to leave the XML structure as is seeing as how it's purpose is just to marshall the data.

You need to pick your specification for dealing with the document. DOM tends to be a good beginner specification. You can easily start at the root element, use a .firstChild method (to get hardware 1), and then just iterate through the document with a .nextSibling method untill .nextSibling = NULL. It's pretty strait forward. You can then grab the info as needed with each iteration and print it to the combobox.

Reply With Quote
  #4  
Old September 16th, 2003, 11:34 AM
colinwebber colinwebber is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Cape Town, South Africa
Posts: 4 colinwebber User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cool Xorro on Sourceforge: 2-way iterative XSLT developement

I can highly recommend the opensource project Xorro. It will greatly simplify things for you!

- View a description:
URL

- Download the latest version with a demo:
URL

Good luck!

- Colin (xorro@thawte.com)

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > using xml to create options in a form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT