尝试读取每个端点元素中的每个单独地址值,并在单独的文本框中显示每个地址值。尝试读取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