我正在处理的 XML 底部有多个代码表,我想查找来自 XML 顶部的代码并从 XML 底部的表中获取 CodeText。
下面是两个代码表:
<CodeTable Name="Codes - Days of Week">
<CodeText CodeValue="" />
<CodeText CodeValue="1">SUNDAY</CodeText>
<CodeText CodeValue="2">MONDAY</CodeText>
<CodeText CodeValue="3">TUESDAY</CodeText>
<CodeText CodeValue="4">WEDNESDAY</CodeText>
<CodeText CodeValue="5">THURSDAY</CodeText>
<CodeText CodeValue="6">FRIDAY</CodeText>
<CodeText CodeValue="7">SATURDAY</CodeText>
</CodeTable>
<CodeTable Name="Codes - Bus Type">
<CodeText CodeValue="" />
<CodeText CodeValue="0">NOT A BUS</CodeText>
<CodeText CodeValue="1">SCHOOL (PUBLIC OR PRIVATE)</CodeText>
<CodeText CodeValue="2">TRANSIT</CodeText>
<CodeText CodeValue="3">INTERCITY</CodeText>
<CodeText CodeValue="4">CHARTER</CodeText>
<CodeText CodeValue="5">OTHER</CodeText>
</CodeTable>
我可以使用以下代码行来访问代码表:
string CodeTableName = "Codes - Days of Week";
XmlNode CodeTableNode = doc.SelectSingleNode("//CodeTable[@Name=\"" + Convert.ToString(CodeTableName) + "\"]");
我已经能够使用以下内容来获取 Bus Type = 0 的 CodeText:
XmlNode CodeTextNode = doc.SelectSingleNode("//CodeText[@CodeValue=\"" + Convert.ToString(BusCode) + "\"]");
code_text = CodeTextNode.InnerText;
Console.WriteLine(code_text);
我想做的是以某种方式将这两者放在一起?所以我可以找到我需要的 CodeTable,然后根据 CodeValue 提取正确的 CodeText。