有没有办法在读取xml文件时推送/弹出书签?

时间:2014-03-05 03:19:49

标签: c# .net xmlreader

我正在阅读一个大型XML文件(LandXML格式的Triangulated Irregular Network)。目前我读得很好,它给出了正确的高程值(或斜率 - 无论我想要什么)。我想探索以不同方式阅读它的方法。 [注意:这样做的目的是通过从Dictionary更改为ptsDTMpoint数组来优化过程后期的其他操作,因此我需要在分配数组之前知道点数。]

以下代码目前有效:

// in scope as class members:
private Dictionary<ulong, ptsDTMpoint> allPoints;

// critical portion of currently sound method:
reader.ReadToDescendant("Pnts");
reader.Read();               // Would like to set a bookmark here
                             // or suspend reading here so I can
                             // Ulong numberOfPoints = countPoints(reader);
while (!(reader.Name.Equals("Pnts") && reader.NodeType.Equals(XmlNodeType.EndElement)))
{
   UInt64 id;
   if (reader.NodeType.Equals(XmlNodeType.Element))
   {
      UInt64.TryParse(reader.GetAttribute("id"), out id);
      reader.Read();
      if (reader.NodeType.Equals(XmlNodeType.Text))
      {
         scratchPoint = new ptsDTMpoint(reader.Value, id);
         if (allPoints == null)
         {                                                    // next line will change (later) to 
            allPoints = new Dictionary<ulong, ptsDTMpoint>(); // = new ptsDTMpoint[numberOfPoints]();
            myBoundingBox = new ptsBoundingBox2d(scratchPoint);
         }
         allPoints.Add(id, scratchPoint);    // also would change to allPoints[counter] = scratchPoint;
         myBoundingBox.expandByPoint(scratchPoint);
      }
   }
   reader.Read();
}

0 个答案:

没有答案