473,461 Members | 1,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Collection of XML Elements

Is there anyway to read a collection of xml elements in .NET? The XML
Reader class does not seem like it can do it. It reads the file
sequentially.

I want to read an xml file and get the collection of elements named
book. The for each book element I want to get its attributes and inner
element attributes.

Can this be done? Now it seems like you have to call readnextelement
multiple times.

Thanks in advance

Apr 10 '07 #1
2 5116
BillGatesFan wrote:
Is there anyway to read a collection of xml elements in .NET? The XML
Reader class does not seem like it can do it. It reads the file
sequentially.

I want to read an xml file and get the collection of elements named
book. The for each book element I want to get its attributes and inner
element attributes.
Do you know System.Xml.XmlDocument or
System.Xml.XPath.XPathDocument/XPathNavigator? Both read the complete
XML document into a tree structure and then allow you to use XPath to
select elements. So with XmlDocument and C# you could do e.g.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("file.xml");
XmlNodeList books = xmlDoc.SelectNodes("//book");
then you can iterate over the node list and do what you need to do (e.g.
access attributes or access child elements) for each book element node.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 10 '07 #2
On Apr 10, 12:28 pm, Martin Honnen <mahotr...@yahoo.dewrote:
BillGatesFanwrote:
Is there anyway to read a collection of xml elements in .NET? The XML
Reader class does not seem like it can do it. It reads the file
sequentially.
I want to read an xml file and get the collection of elements named
book. The for each book element I want to get its attributes and inner
element attributes.

Do you know System.Xml.XmlDocument or
System.Xml.XPath.XPathDocument/XPathNavigator? Both read the complete
XML document into a tree structure and then allow you to use XPath to
select elements. So with XmlDocument and C# you could do e.g.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("file.xml");
XmlNodeList books = xmlDoc.SelectNodes("//book");
then you can iterate over the node list and do what you need to do (e.g.
access attributes or access child elements) for each book element node.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thanks you helped me out

Apr 10 '07 #3

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

Similar topics

8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
8
by: Joseph | last post by:
I am attempting to create a function that will hide all SPANS within an ided DIV ="idMain", then only display one span, but this function gives an error when it gets to elChildElement as being...
1
by: Dan H. | last post by:
Hello, I have an application that requires a collection that is sorted by a double field first, and then by a long field. So, lets say I have an class that has 2 fields called time, priority. I...
0
by: emma middlebrook | last post by:
Tieing myself up in knots a bit here but am thinking about how to do the following two things ... 1. Unmodifiable ArrayList of elements of type T. If we are OK with checking at run-time we can...
4
by: Tamir Khason | last post by:
How can I convert (elegant way) Collection to Array without looping and new instances. E.G: I want to add elements of one menu to other, so secondMenu.MenuItems.AddRange(firstMenu.MenuItems);...
2
by: Tiësto | last post by:
Hi guys, I've trying to find a collection for a very common task without any luck. I only need a collection of Key/Value objects, cause I need to check whether a key as been added and if not, get...
5
by: Oberon | last post by:
I want to create a collection of records which will be permanently available at the application level in an ASP.NET application. How should I go about that? Lets say that the record structure...
10
by: Kathy Burke | last post by:
HI. in asp.net app, I have an xmlDocument that I transform to the client html. Using xsl I create a few textboxes to capture user input. Each of these are related to <data> elements in the xmlDoc....
5
by: Jeff Stewart | last post by:
Let's say I create a collection of DateTime objects like so: Dim clxn_Times As Collection = New Collection() Let's go on to say I add 3 elements to the collection. How do I pull off the...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.