我有一个 XML 文件,我想遍历收集信息的每个子节点。
这是我的 C# 代码,它只选择一个节点,即我想在其子节点上使用 foreach 的 FieldData。
public void LoadXML() {
if (File.Exists("Data.xml")) {
//Reading XML
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Data.xml");
//Think something needs to reference Child nodes, so i may Foreach though them
XmlNodeList dataNodes = xmlDoc.SelectNodes("//FieldData");
TagContents[] ArrayNode;
foreach(XmlNode node in dataNodes) {
int Count = 0;
//int Max = node.ChildNodes.Count;
ArrayNode = new TagContents[Max];
ArrayNode[Count].TagName = node.Name;
ArrayNode[Count].TagValue = node.SelectSingleNode(ArrayNode[Count].TagName).InnerText;
Count = Count + 1;
}
} else {
MessageBox.Show("Could not find file Data.xml");
}
}
我的 XML 看起来像:
<?xml version="1.0"?>
<FieldData>
<property_details_branch IncludeInPDFExport="Yes" Mod="20010101010101"/>
<property_details_inspection_date IncludeInPDFExport="Yes" Mod="20120726200230">20120727220230+0200</property_details_inspection_date>
<property_details_type_of_ownership IncludeInPDFExport="Yes" Mod="20120726134107">Freehold</property_details_type_of_ownership>
</FieldData>