| re: Looping through nested XML
Hi,
Instead of using a DataSet, try using an XmlDocument or XmlTextReader
instead.
Chris
"Cappy" <amit@c4ppy.net> wrote in message
news:2f79b0ae.0402120350.6de1334a@posting.google.c om...[color=blue]
> I am writing an XML menu structure.
>
> I have the following XML file
>
> <MenuItems>
> <Item>
> <Name>Homepa5ge</Name>
> <URL>/index.aspx</URL>
> <Alt>Return to homepage</Alt>
> <Image>/images/navLocationOff.jpg</Image>
> <MouseOver>/images/navLocationOn.jpg</MouseOver>
> <SubMenu>
> <SubItem name="sub1">
> <LinkText>Item 1</LinkText>
> <LinkURL>www.page.com</LinkURL>
> </SubItem>
> <SubItem name="sub2">
> <LinkText>Item 2</LinkText>
> <LinkURL>www.page2.com</LinkURL>
> </SubItem>
> </SubMenu>
> </Item>
> <Item>
> <Name>NextLink</Name>
> <URL>/index.aspx</URL>
> <Alt>Go somewhere else</Alt>
> <Image>/images/navLocationOff.jpg</Image>
> <MouseOver>/images/navLocationOn.jpg</MouseOver>
> </Item>
> </MenuItems>
>
> I have read the xml file into a dataset using the following code and I
> have managed to loop through the parent xml nodes.
>
> menuDS.ReadXML("menu.xml");
>
> foreach (DataTable dt in menuDS.Tables)
> {
>
> foreach (DataRow dr in menuDS.Tables[0].Rows)
> {
>
> //draw parent node
> string name = dr["Name"].ToString();
> string url = dr["URL"].ToString();
> string alt = dr["Alt"].ToString();
> string image = dr["Image"].ToString();
> string mouseover = dr["MouseOver"].ToString();
>
> //create new href
> HtmlAnchor a = new HtmlAnchor();
> a.Name = name;
> a.HRef = url;
> a.Title = alt;
>
> //Need another for loop here to draw child <SubItem> of <item>
> in the xml file
>
>
>
> }
> }
>
> In the above code.. I dont not know how to get access to the child
> items to draw the submenu. Usualy.. dr.GetChildRows(relationShip) but
> I dont know how to access or create the relationship.
>
> Please help
> Amit[/color] |