使用InnerText中的数据

时间:2019-04-10 11:14:55

标签: c# winforms coordinates xmlnode xmlnodelist

是否可以使用从InnerText中提取的数据作为像素的“ y”坐标位置?

我设法从.xml文件中获取字符串元素-标记为“ SequenceInfo”。

.xml文件示例:

ReactDOM

我得到指定节点的文本内容,如下所示:

316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316 ,316,316,316,316,316,316,316,316,316,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318 ,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,320,320,320,321,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,324,324,324,324,324,324,324,326,326,326,326,326,326,326,326,324,324,322,322,322,322,322,322,322,322,322,322,322,322,323,324,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,324,324,322,322,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320

此类数据存储在对象'xtr'(InnerText属性)中。

我们可以进一步推动这些数据吗?例如“ y”坐标?

下面我的代码的一部分:

<SequenceInfo HasSmoke="" Azimuth="267.2" Inclination="682" Zoom="10329" TowerName="Makoszka" Time="2015-03-18 13:10:22">
  <Horizon>316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,320,320,320,321,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,324,324,324,324,324,324,324,326,326,326,326,326,326,326,326,324,324,322,322,322,322,322,322,322,322,322,322,322,322,323,324,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,324,324,322,322,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320</Horizon>
</SequenceInfo>

2 个答案:

答案 0 :(得分:0)

尚不清楚您是否实际上已检索到数据,以及提取数据后要处理的数据...但是下面是一个示例,应该让您入门:

        // ... get the data from your XML somehow ...
        string data = "316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,316,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,318,320,320,320,321,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,322,324,324,324,324,324,324,324,326,326,326,326,326,326,326,326,324,324,322,322,322,322,322,322,322,322,322,322,322,322,323,324,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,326,324,324,322,322,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320,320";
        // Convert the Text Data to Points:
        var points = from y in data.Split(",".ToCharArray()) select new Point(0, int.Parse(y));
        // Do something with the Points:
        foreach(Point p in points)
        {
            Console.WriteLine(p.ToString());
        }

答案 1 :(得分:0)

问题解决了。 这是我的代码:

XmlDocument xtr = new XmlDocument();
            string fileName = OFD.FileName;
            FileInfo fileInfo = new FileInfo(fileName);
            string directoryFullPath = fileInfo.DirectoryName;
            fileName = Path.Combine(directoryFullPath, "info.xml");
            xtr.Load(fileName);
            XmlNodeList list = xtr.GetElementsByTagName("SequenceInfo");
            string[] punkty = xtr.InnerText.Split(',');
            List<Point> punkty1 = new List<Point>();
            for (int i = 0; i < punkty.Length; i++)
            {
                punkty1.Add(new Point { X = i, Y = int.Parse(punkty[i])});
            }