我想要一个数组持有一个结构与两个元素,以保持一个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