473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Example needed: simple XML file and parsing

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!
Nov 12 '05 #1
3 4480
How about something like this:

Dim dstDataSet As New DataSet
dstDataSet.ReadXml(Server.MapPath(".") & "\Items.xml")
With DropDownList1
.DataSource = dstDataSet
.DataValueField = "id"
.DataTextField = "name"
.DataBind()
End With

Then create an Items.xml file that contains:

<?xml version="1.0" encoding="utf-8" ?>
<items>
<item>
<id>1</id>
<name>Fruits</name>
</item>
<item>
<id>2</id>
<name>Vegetables</name>
</item>
</items>
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl...
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!

Nov 12 '05 #2
Thanks Dan! I appreciate your example.

"Dan Cooper" <da********@tiscali.co.uk> wrote in message
news:OY*************@tk2msftngp13.phx.gbl...
How about something like this:

Dim dstDataSet As New DataSet
dstDataSet.ReadXml(Server.MapPath(".") & "\Items.xml")
With DropDownList1
.DataSource = dstDataSet
.DataValueField = "id"
.DataTextField = "name"
.DataBind()
End With

Then create an Items.xml file that contains:

<?xml version="1.0" encoding="utf-8" ?>
<items>
<item>
<id>1</id>
<name>Fruits</name>
</item>
<item>
<id>2</id>
<name>Vegetables</name>
</item>
</items>
"VB Programmer" <gr*********@go-intech.com> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl...
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!


Nov 12 '05 #3
VB Programmer wrote:
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).
--
Craig Deelsnyder
Microsoft MVP - ASP.NET
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nut Shell | last post by:
I needed to parse a csv file for my project. Could not find any so I put together this code. It works for general cases. Use it and let me know. Just Cut and paste the 2 functions in a new Form...
6
by: Ville Vainio | last post by:
Just posting this for the sake of google: Like everyone else, I figured it's time to start using the 'logging' module. I typically want to dump "info" level (and up) log information to...
8
by: Uwe Mayer | last post by:
Hi, can someone provide me with a running example for subclassing QWidget (or something similarly simple) in C++ and then creating SIP (4.x+) bindings for in for Python (2.3+)? I am looking...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
0
by: Ming Zhu | last post by:
Hi, all, I'm new to .NET and ASP.NET. I only use .NET Framework 1.0. I'm reading the book "C# developer's guide to ASP.NET". But I find there is no place to download the code used inside this...
3
by: VB Programmer | last post by:
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...
7
by: Miro | last post by:
Hi, ( using vb.net 2003 ) Im not quite sure what to look for in the help / online for this. Example: You have 2 seperate .exe files running ( both written in vb.net ) Is there a way to...
2
by: friend.blah | last post by:
can any one give a simple example for implementing mutex. I have 3 threads (taking different input files )enter into the same function at different times... The 3 threads need to exit/leave the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.