473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Looping through nested XML

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
Nov 12 '05 #1
2 5413
Hi,

Instead of using a DataSet, try using an XmlDocument or XmlTextReader
instead.

Chris

"Cappy" <am**@c4ppy.net> wrote in message
news:2f**************************@posting.google.c om...
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

Nov 12 '05 #2
I did look into this method initialy.. but couldnt get my headround
looping through the tree and grabing the specific nodes..

Anyone got an pointers or sample code?

Amit

"Christopher Kimbell" <c_*******@REMOVETHISemail.comNOSPAM> wrote in message news:<40********@news.broadpark.no>...
Hi,

Instead of using a DataSet, try using an XmlDocument or XmlTextReader
instead.

Chris

"Cappy" <am**@c4ppy.net> wrote in message
news:2f**************************@posting.google.c om...
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

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sturnoff Megantic | last post by:
This seems like such a stupid little problem, but it's been bugging me for hours now. I have a 2D array called agents2d. I need to loop through it and display the info. Here is my code: echo...
2
by: paul | last post by:
Hi all, I have a 2D array, which I am trying to access, but I am having problems doing this: If, for instance, I use a nested for loop to go through the values, using something like echo...
0
by: Psybar Phreak | last post by:
hi all i have an array of Process objects, each elements has an id (process.id), and arrival time (process.at), processing time (process.pt) and a boolean indicating whether the process has...
1
by: Christian Gollwitzer | last post by:
Hi, I'm trying to loop over the elements in a hashmap of the STL-implementation by SGI. The point is, that because the key/value pair is stored as std::pair in the COntainer, the code becomes...
6
by: Dave | last post by:
I have to automate a process that assigns sales leads to sales people. For example: Every day we buy a list of sales leads, it ranges in size from 50 - 100 records. We have a team of sales...
5
by: Stimp | last post by:
This is a question I'm carrying over from a previous one I made today since I've simplified where the problem is... I have a datatable, tblFeatures, which has around 30 columns (one for each...
2
by: randy1200 | last post by:
My hope is that somebody has a thought on this, or can point to toward an article that's useful. I have the following: DataSet ds = new DataSet(); ds.ReadXml("MyData.xml"); Each MainTable...
11
by: boker | last post by:
i try to do nested looping like this for (i=0;i<=640;i++) { for(j=0;j<=640;j++) { if(getpixel(j,i)!=0) { printf("this a color pixel); } }
14
by: NetworkElf | last post by:
Hi all, Does anyone have some code that shows an example of how to loop through a range of IP addresses? I'm using text boxes to get a start and end value for the range. I was thinking about...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.