|
-
Nov 19th, 2008, 04:48 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] dropdownlist from xml
I have this loop:
Code:
foreach (XmlNode MyNodes in MyXmlDoc.SelectNodes("/Name"))
{
DDListClient.Items.Add(
new ListItem(MyNodes.ChildNodes[0].InnerText.ToString()));
}
and my xml is like below. I want to populate the "name" to my dropdownlist control, but it doesn't. What did i do wrong?
<Client>
<Name>test</Name>
<LastName>testing</LastName>
</Client>
-
Nov 20th, 2008, 10:58 AM
#2
Re: dropdownlist from xml
Your XPath is wrong. If youre XPath isn't wrong, then your XML is wrong.
Assuming the XML isn't wrong, and MyXmlDoc contains the entire XML file, then you should have multiple Client nodes under a root node. If you have multiple Client nodes, your Xpath should be used as
MyXmlDoc.SelectNodes("/Root/Client/Name")
-
Nov 20th, 2008, 02:55 PM
#3
Thread Starter
Frenzied Member
Re: dropdownlist from xml
medhak, this is how I read the xml.. and my xml is right:
DataSet MyDS = new DataSet();
MyDS.ReadXml(Server.MapPath("~/Client.xml"));
XmlDataDocument MyXmlDoc = new XmlDataDocument(MyDS);
I tried the root node you suggested, but it's not working.
-
Nov 20th, 2008, 03:15 PM
#4
Thread Starter
Frenzied Member
Re: dropdownlist from xml
oh I did a little bit more reserach this solves the issue:
XmlNode MyNodes in MyXmlDoc.SelectNodes("//Name")
But i don't know what // means?
-
Nov 24th, 2008, 05:35 AM
#5
Re: dropdownlist from xml
So the XML was right, but the XPath was wrong.
// does a recursive search across your XML and is very inefficient. You should be using the XPath to the node itself.
The
Code:
MyXmlDoc.SelectNodes("/Root/Client/Name")
method will work for you but I was simply guessing the name of the root node. You need to look at your XML (or show it to us) to figure out the proper path to the node you want.
-
Nov 24th, 2008, 02:24 PM
#6
Thread Starter
Frenzied Member
Re: dropdownlist from xml
It simply looks like this for my xml:
<Client>
<Name>test</Name>
<LastName>testing</LastName>
</Client>
and it's under the project files, which is the same as the default.aspx... I didn't put it in any other folder. I simply right click on solution and add an xml file.
-
Nov 26th, 2008, 04:40 AM
#7
Re: dropdownlist from xml
So the XPath should be
/Client/Name
-
Dec 12th, 2008, 01:03 PM
#8
Thread Starter
Frenzied Member
Re: [RESOLVED] dropdownlist from xml
-
Dec 22nd, 2008, 11:35 AM
#9
Re: [RESOLVED] dropdownlist from xml
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
|