嘗試讀取每個端點元素中的每個單獨地址值,並在單獨的文本框中顯示每個地址值。嘗試讀取XML文件中的值
<client>
<endpoint address="http://127.0.0.1:" />
<endpoint address="http://127.0.0.1:" />
<endpoint address="net.tcp://127.0.0.1:" />
</client>
我可以讀取XML數據並只顯示最後一個元素的值。這實際上是我第一次嘗試用C#開發任何東西。
下面是代碼的一點我已經寫:
XmlReader ReadFile = XmlReader.Create(AgentConfig.FileName);
while (ReadFile.Read())
{
if ((ReadFile.NodeType == XmlNodeType.Element) && (ReadFile.Name == "endpoint"))
{
if (ReadFile.HasAttributes)
{
textBox2.Text = ReadFile.GetAttribute("address");
textBox3.Text = ReadFile.GetAttribute("address");
}
}
}
在我將尋找我自己的答案其間,但是任何輸入肯定受到讚賞! :)
我建議尋找到的XDocument和LINQ to XML中的文本框 – TGH
謝謝,我一定會讀到這個。 – bitbreaker