Order in a data tree

Hi there,

I have developed a grasshopper component with Visual Studio in C# to filter nodes in a XML file.
I have managed to create a data tree, where nodes are grouped in lists in the data tree.
But the list-numbers are not ordered.
How to write code, so the list-numbers will appear as 0, 1, 2, 3, 4, 5 … and not 5, 6, 7, 9, 15, 16 … ?

Here is my C# Code:

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
pManager.AddTextParameter(“Path”, “Path”, “Path to XML file”, GH_ParamAccess.item);

    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)
        pManager.AddTextParameter("PointsTree", "PointsTree", "Temporary output", GH_ParamAccess.tree);

    protected override void SolveInstance(IGH_DataAccess DA)
        String path = System.String.Empty;
        DA.GetData(0, ref path);

        XmlDocument osmFile = new XmlDocument();

        List<List<string>> pointsDataTree = new List<List<string>>();

        XmlNodeList wayNodes = osmFile.SelectNodes("osm/way");

        foreach (XmlNode way in wayNodes)

            List<string> wayPoints = new List<string>();

            XmlNodeList refPoints = way.SelectNodes("nd");

         foreach (XmlNode refPoint in refPoints)
              string reference = refPoint.Attributes["ref"].Value;
              var wayNode = new OSMNode();
              wayNode.Node = reference;

                XmlNodeList tags = way.SelectNodes("tag");

                foreach (XmlNode tag in tags)
                    string key = tag.Attributes["k"].Value;
                    var wayKey = new OSMWay();
                    wayKey.Key = key;

                    if (key == "cycleway")


        DataTree<String> cyclewayPoints = new DataTree<String>();

        for (int i = 0; i < pointsDataTree.Count; i++)
            List<string> way = pointsDataTree[i];
            for (int j = 0; j < way.Count; j++)
                string point = way[j];

                    cyclewayPoints.Add(point, new GH_Path(i));

        DA.SetDataTree(0, cyclewayPoints);

You can renumber paths from DataTree. DataTree(T).RenumberPaths Method
However, it’s recommended to use GH_Structure instead of DataTree in a Grasshopper component.
I think you could try simplify paths method to use GH_Structure instead of DataTree. GH_Structure(T).Simplify Method

Well … the general case (and the orthodox way) for that sort of stuff is to sample your things in a List of a Custom Type (i.e. using a Class with suitable Properties, like a value, an index, a cat or a dog) and then perform flat or nested P/LINQ queries (GroupBy, OrderBy blah, blah).

That said if your horizon is beyond R/GH … avoid at any cost using non standard Data Collections (the likes of DataTrees).

Notify if you want an indicative demo C# on that matter.