load XML data inside a hashtable

Last post 07-07-2008 5:30 AM by Samu Zhang - MSFT. 5 replies.

Sort Posts:

  • load XML data inside a hashtable

    07-02-2008, 11:01 PM

    can someone help me find a way to transfer data from an XML to a hashtable.  I need it in a hashtable because i need to have a key value pair.  The reason i also have two items per value is i need to do a rotation everythime a user goes to my site it will rotate the image. I've never done this before and not sure if it's possible.  I'm using visual studios 08 in C#

    XML:

    located inside App_Data(cake.xml)

    <cakeshop>
    <items value="cake">
      <item>
       <image>cake1.gif</image>
       <link>cake.aspx</link>
       <percent>50</percent>
    </item>
      <item>
       <image>cake2.gif</image>
       <link>cake2.aspx</link>
       <percent>50</percent>
    </item>
    </items>

    <items value="donut">
      <item>
       <image>donut1.gif</image>
       <link>donut.aspx</link>
       <percent>50</percent>
    </item>
      <item>
       <image>donut2.gif</image>
       <link>donut2.aspx</link>
       <percent>50</percent>
    </items>
    </cakeshop>

    --------------------------------------------------------------------------------------------------
    code is located inside the App_Code (cakerotation.cs)

    public static void CakeRotation()
    {
    XMLDocument objGetCake = new XMLDocument();
    objGetCake.Load(HttpContext.Current.Server.MapPath("~/App_Data/cake.xml"));

    if (null != objGetCake)
    {
          //this is where I get stuck because I'm not sure how to load the XML Data inside the HashTable.
    }

     }

    can anyone help me out?

    Thanks in advance.

  • Re: load XML data inside a hashtable

    07-02-2008, 11:23 PM
    • Loading...
    • Ganeshyb
    • Joined on 11-02-2007, 4:07 AM
    • Posts 201

    What do you want to store in the HashTable.

    Sample code for getting the items and no of children and put in hashtable 

    Hashtable ht = new Hashtable();

    System.Xml.XmlNodeList list = objGetCake.SelectNodes("\\items");foreach (System.Xml.XmlNode node in list)

    {

    ht[node.Attributes["value"].Value] = node.ChildNodes.Count;

    }

    Thanks
    Ganesh


    If you find my reply help you Mark it Answered.
  • Re: load XML data inside a hashtable

    07-02-2008, 11:29 PM

    I want to store the data that's inside the XML file.

    so I want the key to be the "cake" which is the value inside the <items value=""> node and the value would be the <image>,<link>,<percentage>

    is this possible?

  • Re: load XML data inside a hashtable

    07-03-2008, 12:16 AM
    • Loading...
    • Ganeshyb
    • Joined on 11-02-2007, 4:07 AM
    • Posts 201

    Your have 1 to Many relation ie Items has may item how do you want to represent this in hash or could you tell us how are you planning to use this hash ?

    Thanks
    Ganesh


    If you find my reply help you Mark it Answered.
  • Re: load XML data inside a hashtable

    07-03-2008, 10:13 PM

    i just want to be able to pull the data so that i can create a key value pair.  my goal is when the user goes to a page, lets say cake.aspx.  i can compare the items under the cake items and then do some kind of image rotation based on the two items under that <items value"cake">

     i just can't figure out how to grab these data out and put it in a hashtable i've been looking around the site and found nothing. I can't to the .net adrotator because i dont want the image to be changed when the page is refreshed. 

     does anyone have a clue on how i can solve this issue? Thanks.

  • Re: load XML data inside a hashtable

    07-07-2008, 5:30 AM
    Answer

    Hi newbie_2007,

    See here : http://forums.asp.net/t/1283744.aspx

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question.
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter