我想要一個數組持有一個結構與兩個元素,以保持一個XML標記名稱和它的值。試圖創建一個數組持有一個結構?
我想有數組這樣工作:
MyArrayStruct[Count].TagName = "Bla Bla";
MyArrayStruct[Count].TagValue = "Bla Bla Bla";
可能有的請幫助我得到這個工作。
public struct TagContents
{
String TagName;
String TagValue;
};
我有聲明數組的問題結構來有工作像我想,我什麼是工作像註釋掉的代碼。
public void LoadXML()
{
if (File.Exists("Data.xml"))
{
//Readin XML
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Data.xml");
XmlNodeList dataNodes = xmlDoc.SelectNodes("//FieldData");
//Count the nodes
int Max = 0;
foreach (XmlNode node in dataNodes)
{
Max = Max + 1;
}
int Count = 0;
//TagContents MyXmlPointer = new TagContents();
// MyXmlPointer[] ArrayNode;
// ArrayNode = new MyXmlPointer[Max];
foreach (XmlNode node in dataNodes)
{
// ArrayNode[Count].TagName =node.SelectSingleNode("Have not found what to put here yet but will get there").Name;
// ArrayNode[Count].TagValue =node.SelectSingleNode("Have not found what to put here yet but will get there").InnerText;
}
}
else
{
MessageBox.Show("Could not find file Data.xml");
}
}
究竟是不是工作? – waldrumpus 2012-08-01 10:50:11
我的評論部分它是我想要它做的但這不起作用 – Pomster 2012-08-01 10:51:28