|
-
Jun 14th, 2010, 10:16 PM
#1
Thread Starter
Addicted Member
[RESOLVED] XML and VB.NET
Hi there,
I have an XML file, which follows...
Code:
<countries>
<country>
<name>Italy</name>
<value>I</value>
</country>
<country>
<name>Japan</name>
<value>J</value>
</country>
<country>
<name>Germany</name>
<value>G</value>
</country>
<country>
<name>USA</name>
<value>U</value>
</country>
</countries>
Question: How do I populate my Drop Down List using VB.NET? I'd like to code it in the aspx.vb file. I wish to have an output like this...
Code:
<asp:DropDownList ID="drpCountry" runat="server">
<asp:ListItem Value="I">Italy</asp:ListItem>
<asp:ListItem Value="J">Japan</asp:ListItem>
<asp:ListItem Value="G">Germany</asp:ListItem>
<asp:ListItem Value="U">USA</asp:ListItem>
</asp:DropDownList>
Thanks in advance
-
Jun 14th, 2010, 11:30 PM
#2
Frenzied Member
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Jun 15th, 2010, 01:21 AM
#3
Re: XML and VB.NET
One way, using XPath (because I am old school) would be to do the following:
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(Server.MapPath("XMLFile1.xml"))
Dim countryNodes As XmlNodeList = xmlDoc.SelectNodes("/countries/country")
For Each countryNode As XmlNode In countryNodes
Dim name As XmlNode = countryNode.SelectSingleNode("name")
Dim value As XmlNode = countryNode.SelectSingleNode("value")
Dim newListItem As New ListItem(name.InnerText, value.InnerText)
Me.DropDownList1.Items.Add(newListItem)
Next
End Sub
There are other methods that you could use, for instance LINQ to XML which would get you the values that you need from the XML Nodes, but really it is a matter of preference.
Hope that helps!!
Gary
-
Jun 15th, 2010, 07:25 PM
#4
Thread Starter
Addicted Member
Re: XML and VB.NET
Hi there,
Thanks Gary, that helps a lot 
Let me mark this thread as resolve and I'll post some questions later on, if I encounter some
-
Jun 15th, 2010, 07:26 PM
#5
Thread Starter
Addicted Member
Re: XML and VB.NET
 Originally Posted by avrail
Thanks for the links
-
Jun 15th, 2010, 07:49 PM
#6
Thread Starter
Addicted Member
Re: [RESOLVED] XML and VB.NET
Hi there,
Here's a question I have in mind, what are the practical uses of these kinds of XML files?
-
Jun 15th, 2010, 11:36 PM
#7
Frenzied Member
Re: [RESOLVED] XML and VB.NET
 Originally Posted by Claude2005
Hi there,
Here's a question I have in mind, what are the practical uses of these kinds of XML files?
a lot of things,
create menus, store informations, database what ever you want
You Don't Have to Rate Me.
I'm Not a Civilized Man I'm the Civilization it self
White or Black, Living or Dieing and 0 or 1 that's MY life
iam an Object in Object Oriented Life
my blog : http://refateid.blogspot.com/
twitter : @avrail
010011000111010101110110001000000100110101111001001000000101000001100011 
-
Jun 16th, 2010, 01:00 AM
#8
Re: [RESOLVED] XML and VB.NET
XML Files are typically used in a couple of specific situations. For instance,
1) You need to have a configuration file for your application that is both easy to navigate, but also easily human readable.
2) You need to exchange data between two systems, perhaps even across Operating System. XML format is easily understood by all systems.
3) You need a file to store some relational data, that doesn't warrant a full blown SQL Server instance.
But Claude, why the question, you seem to already be using XML, are you wanting to change the design?
Gary
-
Jun 16th, 2010, 03:13 AM
#9
Thread Starter
Addicted Member
Re: [RESOLVED] XML and VB.NET
Uhm, this will be the first time I'll be working with XML in ASP.NET. The purpose of this thread is just that I just want to expand my knowledge in programming. Right now, I can only formulate solutions basing on what I currently know. Knowing more stuff means I can formulate more efficient solutions.
are you wanting to change the design?
I didn't understand what you meant here
-
Jun 16th, 2010, 03:24 AM
#10
Re: [RESOLVED] XML and VB.NET
Ah, fair enough, that makes sense.
Basically, I was asking whether you are happy with the current usage of your XML file, or are you looking to change it to something else?
Gary
-
Jun 16th, 2010, 03:29 AM
#11
Thread Starter
Addicted Member
Re: [RESOLVED] XML and VB.NET
Oh that one, it's just a simple XML to make me understand how to manipulate a XML file . Most of the tutorials I found teach you on how to manipulate the XML file but they don't show the XML file so I really can't absorb anything they teach.
-
Jun 16th, 2010, 03:44 AM
#12
Re: [RESOLVED] XML and VB.NET
Ah, I see. I thought this was a file that you were already using in your application, i.e. you had already decided to use XML. That makes more sense.
It really comes down to how much data you have, what you are going to be doing with it, etc, all of these things will influence the decision about which data format to use.
Gary
-
Jun 16th, 2010, 03:50 AM
#13
Thread Starter
Addicted Member
Re: [RESOLVED] XML and VB.NET
Yep. I guess that sums it all up. I'll post questions here in case I encountered some.
Thanks guys, I appreciate it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|