【发布时间】:2021-05-14 06:15:20
【问题描述】:
我有一个如下所示的 XML,我想在其中读取一个名为 1526726702 的节点。因此,这个特定的节点集合 sn-p,我具有列和行结构形式的数据结构。即列由 @987654322 表示@标签和行由<measValue>下的<measResults>表示。所以我有很多单元格,如'Local Cell ID=10'、'Local Cell ID=11'、'Local Cell ID=12'等。现在我的目标是在<measTypes> 部分下读取名为1526726740 和1526728300 的列,以获取第一个单元格“本地单元格ID = 10”的值为43.596 和390824。像这样,我们有很多特定列的行。如何我可以读取并获取此值吗?
XML 片段
<?xml version="1.0" encoding="UTF-8"?>
<measCollecFile xmlns="measCollec" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="Schedule.xsd">
<fileHeader fileFormatVersion="V7.2" testername="tea">
<fileSender elementType="SBT900"/>
<measCollec beginTime="2021-01-24T00:00:00+04:00"/>
</fileHeader>
<measData>
<managedElement userLabel="eelaBldg_474"/>
<measInfo measInfoId="726702">
</measInfo>
<measInfo measInfoId="1526">
</measInfo>
<measInfo measInfoId="1526726702">
<granPeriod duration="PT3600S" endTime="2021-01-24T01:00:00+04:00"/>
<repPeriod duration="PT3600S"/>
<measTypes>1526726737 1526726740 1526727483 1526728299 1526728300 1526728301 1526728302 1526728303 1526728304 1526728305 </measTypes>
<measValue measObjLdn="eelaBldg_474/Cell:eNodeB Function Name=eelaBldg_474, Local Cell ID=10, Cell Name=GhaleelaBldg_A_F1U, eNodeB ID=956474, Cell FDD TDD indication=CELL_TDD">
<measResults>41.699 43.596 9.241 2461846 390824 27358 0 1263996 5282350 7509028 </measResults>
</measValue>
<measValue measObjLdn="eelaBldg_474/Cell:eNodeB Function Name=eelaBldg_474, Local Cell ID=11, Cell Name=GhaleelaBldg_A_F1U, eNodeB ID=956474, Cell FDD TDD indication=CELL_TDD">
<measResults>42.699 46.596 9.241 2461846 390829 27358 0 1263996 5282350 7509028 </measResults>
</measValue>
<measValue measObjLdn="eelaBldg_474/Cell:eNodeB Function Name=eelaBldg_474, Local Cell ID=12, Cell Name=GhaleelaBldg_A_F1U, eNodeB ID=956474, Cell FDD TDD indication=CELL_TDD">
<measResults>43.699 49.596 9.241 2461846 390826 27358 0 1263996 5282350 7509028 </measResults>
</measValue>
</measInfo>
</measData>
</measCollecFile>
我试过的代码如下
using (XmlReader xr = XmlReader.Create(path))
{
xr.MoveToContent();
while (xr.Read())
{
while (xr.NodeType == XmlNodeType.Element && xr.LocalName == "measInfo" && xr.GetAttribute("measInfoId") == "1526726702")
{
try
{
XElement pin = (XElement)XNode.ReadFrom(xr);
string earfcndl = Getvalue(pin, "measTypes");
// string t = pin.Element("measTypes").Value;
var data = from atts in pin.Elements("measInfo")
select new
{
meas = (string)atts.Element("measTypes")
};
string measTypes = data.First().meas;
}
catch (Exception ex)
{
}
}
}
}
【问题讨论】:
标签: c# .net xml linq visual-studio-2010