Which collection type for XML nodes?

H

Hillbilly

I am beginning to work with code that repetitively generates a specific XML
node (primaryNode) noting the primaryNode will contain several subNodes. I
need to learn to efficiently build a collection of primaryNodes as each new
primaryNode is generated.

I want to learn LINQ to XML. The collection of nodes can be and will
eventually be written to the file system and perhaps stored in a SQL
database but I am thinking it would be best to build the collection in
memory first.

Which collection class lends itself well to this type of "gathering"
process?
 
M

Martin Honnen

Hillbilly said:
I am beginning to work with code that repetitively generates a specific
XML node (primaryNode) noting the primaryNode will contain several
subNodes. I need to learn to efficiently build a collection of
primaryNodes as each new primaryNode is generated.

I want to learn LINQ to XML. The collection of nodes can be and will
eventually be written to the file system and perhaps stored in a SQL
database but I am thinking it would be best to build the collection in
memory first.

Which collection class lends itself well to this type of "gathering"
process?

Well XDocument and XElement are container nodes in LINQ to XML so you
usually just use one of them to add child nodes. There is also
XStreamingElement to keep memory consumption small by using deferred
serialization.

If you don't want to use an XNode itself as the container of your nodes
then use a generic collection like List<XNode> for instance. There are
other collections like Stack or Queue, which one you use depends on how
you want to access the items in the collection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top