怎么c#把foreach遍历的值付给textBox1?
本来有2组值得,但是在textBox1只显示一组值,怎么改呢?privatevoidbutton1_Click(objectsender,EventArgse){doc....
本来有2组值得,但是在textBox1只显示一组值,怎么改呢?
private void button1_Click(object sender, EventArgs e)
{
doc.Load(@"C:\Users\ASUS\Desktop\XMLFile1.xml "); //加载Xml文件
XmlElement root = doc.DocumentElement; //获取根节点
XmlNodeList personNodes = root.GetElementsByTagName("Person"); //获取Person子节点集合
foreach (XmlNode node in personNodes)
{
string id = ((XmlElement)node).GetAttribute("id"); //获取Name属性值
string name = ((XmlElement)node).GetElementsByTagName("Name")[0].InnerText; //获取Age子XmlElement集合
string age = ((XmlElement)node).GetElementsByTagName("Age")[0].InnerText;
//Console.WriteLine("编号:" + id + "姓名:" + name + "年龄:" + age);
textBox1.Text= ("编号:" + id + "姓名:" + name + "年龄:" + age);
} 展开
private void button1_Click(object sender, EventArgs e)
{
doc.Load(@"C:\Users\ASUS\Desktop\XMLFile1.xml "); //加载Xml文件
XmlElement root = doc.DocumentElement; //获取根节点
XmlNodeList personNodes = root.GetElementsByTagName("Person"); //获取Person子节点集合
foreach (XmlNode node in personNodes)
{
string id = ((XmlElement)node).GetAttribute("id"); //获取Name属性值
string name = ((XmlElement)node).GetElementsByTagName("Name")[0].InnerText; //获取Age子XmlElement集合
string age = ((XmlElement)node).GetElementsByTagName("Age")[0].InnerText;
//Console.WriteLine("编号:" + id + "姓名:" + name + "年龄:" + age);
textBox1.Text= ("编号:" + id + "姓名:" + name + "年龄:" + age);
} 展开
展开全部
private void button1_Click(object sender, EventArgs e)
{
doc.Load(@"C:\Users\ASUS\Desktop\XMLFile1.xml "); //加载Xml文件
XmlElement root = doc.DocumentElement; //获取根节点
XmlNodeList personNodes = root.GetElementsByTagName("Person"); //获取Person子节点集合
foreach (XmlNode node in personNodes)
{
string id = ((XmlElement)node).GetAttribute("id"); //获取Name属性值
string name = ((XmlElement)node).GetElementsByTagName("Name")[0].InnerText; //获取Age子XmlElement集合
string age = ((XmlElement)node).GetElementsByTagName("Age")[0].InnerText;
//Console.WriteLine("编号:" + id + "姓名:" + name + "年龄:" + age);
/*****************此处做了修改*****************************/
textBox1.Text=textBox1.Text + ("编号:" + id + "姓名:" + name + "年龄:" + age);
}
{
doc.Load(@"C:\Users\ASUS\Desktop\XMLFile1.xml "); //加载Xml文件
XmlElement root = doc.DocumentElement; //获取根节点
XmlNodeList personNodes = root.GetElementsByTagName("Person"); //获取Person子节点集合
foreach (XmlNode node in personNodes)
{
string id = ((XmlElement)node).GetAttribute("id"); //获取Name属性值
string name = ((XmlElement)node).GetElementsByTagName("Name")[0].InnerText; //获取Age子XmlElement集合
string age = ((XmlElement)node).GetElementsByTagName("Age")[0].InnerText;
//Console.WriteLine("编号:" + id + "姓名:" + name + "年龄:" + age);
/*****************此处做了修改*****************************/
textBox1.Text=textBox1.Text + ("编号:" + id + "姓名:" + name + "年龄:" + age);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询