By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,053 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,053 IT Pros & Developers. It's quick & easy.

Parse XML into Collection - general use code?

P: n/a
I'm a newbie so please bear with me...

I'm looking to parse XML into a Collection so that I can pass that
collection around to functions to extract data from it easily.

I'm hoping there is code already to parse std XML files into a
Collection? All I've found is code where the XML structure is already
known... I need to code to work no matter what the structure... it
would "figure out" what nodes are parents/children and such then place
them into a Collection appropriately.

Any help is appreciated!
Nov 12 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
An XmlDocument already defines a hierarchy of collections when it parses the
XML structure. A tree structure is created. You could use properties like
ChildNodes to enumerate the elements at a particular level.

This probably is not what you wanted so maybe you could provide more
information about the problem.

"Aaron" <al****@cox.net> wrote in message
news:85*************************@posting.google.co m...
I'm a newbie so please bear with me...

I'm looking to parse XML into a Collection so that I can pass that
collection around to functions to extract data from it easily.

I'm hoping there is code already to parse std XML files into a
Collection? All I've found is code where the XML structure is already
known... I need to code to work no matter what the structure... it
would "figure out" what nodes are parents/children and such then place
them into a Collection appropriately.

Any help is appreciated!

Nov 12 '05 #2

P: n/a
I'm looking for a simple way to parse std XML files into a vb.net
collection. Without needing to know what the data is or the header names
of what is in the file.
The parser would place the XML contents it into a collection and via the
structure of the collection, you'd know the hierarchy of the data.

thus wanting something like this...
<?xml version="1.0" encoding="UTF-8"?>
<collection>
<comment>Company employees</comment>
<section name="employee1">
<item key="name" value="Bob Johnson" />
<item key="department" value="Accounting" />
</section>
<section name="employee2">
<item key="name" value="Susan Fielding" />
<item key="department" value="Sales" />
</section>
</collection>

turn into a collection like this...

collection.comment.text = "Company employees"
collection.section.name = "employee1"
collection.section.name.employee1.item.name = "Bob Johnson"
collection.section.name.employee1.item.department = "Accounting"

... and so forth.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #3

P: n/a
Aaron Levey wrote:
collection.comment.text = "Company employees"
collection.section.name = "employee1"
collection.section.name.employee1.item.name = "Bob Johnson"
collection.section.name.employee1.item.department = "Accounting"

You cannot do it with *any* data, because above imply the structure of
data is known at development time. If the schema of your XML is known,
XML serialization is exactly what you are looking for.
For arbitrary XML - XPathDocument and XPath selections is the way to go,
if you need editing, then use XmlDocument.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.