Results 1 to 9 of 9

Thread: [RESOLVED] dropdownlist from xml

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Resolved [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>

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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")

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    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.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    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?

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: dropdownlist from xml

    So the XPath should be

    /Client/Name

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: [RESOLVED] dropdownlist from xml

    Gracias, mendhak

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] dropdownlist from xml

    No probs. (I know, late)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width