different number of attributes per node !

  • Thread starter Thread starter C# newbie
  • Start date Start date
C

C# newbie

Hi guys,

While reading an xml file (with the purpose of saving all traversed node's
informaion into an array).
Please know that I want to save every node's attributes into an array and
since every node has DIFFERENT NUMBER of ATTRIBUTES what do you suggest me
to use ?


Thanks in advance
 
Newbie,

You could use an ArrayList of ArrayLists for this. The first arraylist
each for the nodes (you don't know how many nodes do you? In case
you do then you can use a fixed size XmlNode[] array) and then you
store a new ArrayList in each position of the first list to hold the
attributes.

HTH,

//Andreas
 
C# newbie,

You will want to use an ArrayList in this case, or even a Hashtable (for
easy lookup). Both of thest structures increase their size dynamically as
needed.

Hope this helps.
 
C# newbie said:
While reading an xml file (with the purpose of saving all traversed node's
informaion into an array).
Please know that I want to save every node's attributes into an array and
since every node has DIFFERENT NUMBER of ATTRIBUTES what do you suggest me
to use ?

Why not just use an ArrayList?
 
How about just creating a struct/class with the node to save and an
array of attributes and save that struct to an Array? Hope that helps
 
C# newbie said:
Hi guys,

While reading an xml file (with the purpose of saving all traversed node's
informaion into an array).
Please know that I want to save every node's attributes into an array and
since every node has DIFFERENT NUMBER of ATTRIBUTES what do you suggest me
to use ?


Thanks in advance

You may want to use a System.Collections.ArrayList instead of an array
if this is possible, it will do all the resizing for you.
 
Thanks Andreas,

Below is the class I did define, which keeps Nodes information. Now should
I create the second array (attribute holder) while running the program after
checking out the number of a node by xmode.Attributes.Count ?



public class CXmlElementCollection

{

private String strNodeItSelf = String.Empty;

private String strNodeText = String.Empty;

private String strParent = String.Empty;

//Accessible by others

public System.Collections.ArrayList alAtrribuesCollection = new
System.Collections.ArrayList();

.......

}



Andreas Håkansson said:
Newbie,

You could use an ArrayList of ArrayLists for this. The first arraylist
each for the nodes (you don't know how many nodes do you? In case
you do then you can use a fixed size XmlNode[] array) and then you
store a new ArrayList in each position of the first list to hold the
attributes.

HTH,

//Andreas



C# newbie said:
Hi guys,

While reading an xml file (with the purpose of saving all traversed node's
informaion into an array).
Please know that I want to save every node's attributes into an array and
since every node has DIFFERENT NUMBER of ATTRIBUTES what do you suggest me
to use ?


Thanks in advance
 
Thanks for your help


Nicholas Paldino said:
C# newbie,

You will want to use an ArrayList in this case, or even a Hashtable (for
easy lookup). Both of thest structures increase their size dynamically as
needed.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

C# newbie said:
Hi guys,

While reading an xml file (with the purpose of saving all traversed node's
informaion into an array).
Please know that I want to save every node's attributes into an array and
since every node has DIFFERENT NUMBER of ATTRIBUTES what do you suggest me
to use ?


Thanks in advance
 
Thanks for your help


Daniel Jin said:
arraylist like many have said, or even better, maybe a
NameValueCollection, so you can access attributes for a specific node by
attribute names instead of ordinal index.
 
Thanks for your help




Dilip Krishnan said:
How about just creating a struct/class with the node to save and an
array of attributes and save that struct to an Array? Hope that helps



--
Regards,
Dilip Krishnan
MCAD, MCSD.net
dilipdotnet at apdiya dot com
 
Back
Top