Connecting Tech Pros Worldwide Forums | Help | Site Map

Parse XML into Collection - general use code?

Aaron
Guest
 
Posts: n/a
#1: Nov 12 '05
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!

Peter Rilling
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Parse XML into Collection - general use code?


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" <alevey@cox.net> wrote in message
news:859285cb.0312090917.c0b701a@posting.google.co m...[color=blue]
> 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![/color]


Aaron Levey
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Parse XML into Collection - general use code?


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!
Oleg Tkachenko
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Parse XML into Collection - general use code?


Aaron Levey wrote:
[color=blue]
> collection.comment.text = "Company employees"
> collection.section.name = "employee1"
> collection.section.name.employee1.item.name = "Bob Johnson"
> collection.section.name.employee1.item.department = "Accounting"[/color]
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

Closed Thread