VB said:
A dropdownlist in my ASP.NET webform needs to be populated from values taken
from an XML file. Can someone provide a (simple) sample XML file and a
parsing routine using VB.NET?
The values could be something like:
Fruits
Vegetables
Meats
Dairy
Thanks in advance!
Check out the System.Xml.XmlDocument class, it has load methods, etc. to
load in the doc or string. Then you use XPath to query and select the
nodes with your values (XmlDocument.SelectNodes I believe). Here's a
quick example snippet (sorry only example I could find quickly):
http://www.net-language.com/CodeExample.aspx?i=185
If it's decent XML, all of your values should be selectable at once (one
method call like above). Then you can bind the resulting XmlNodeList to
your dropdown. Each Container.DataItem will then be an XmlNode.
In the dropdown, set the DataTextField to the name of whatever property
of the XmlNode is the one to display on the screen (ie. "Text") and the
DataValueField as well (probably the same unless you have some other
attribute, etc. that is used for the value).