|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > using xml to create options in a form |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|