我想读取一个 XML 文件,然后将其显示到网页上,但我无法在 for 循环中执行此操作
XmlDocument doc = new XmlDocument();
doc.Load(@"c:/xmldatabase.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList nodes = root.SelectNodes("//User");
foreach (XmlNode node in nodes)
{
Label1.Text = node["Name"].InnerText;
Label3.Text = node["Contact"].InnerText;
Label4.Text = node["Email"].InnerText;
Label2.Text = node["City"].InnerText;
Label5.Text = node["Country"].InnerText;
}
我的 XML 有数据!
<?xml version="1.0"?>
<User-Profile>
<User>
<Name>Jhon</Name>
<Contact>4567897632</Contact>
<Email>pri@dfdcm.com</Email>
<City>xyz</City>
<Country>abc</Country>
</User>
<User>
<Name>Mike</Name>
<Contact>8888888</Contact>
<Email>acvb@dfdcm.com</Email>
<City>xrtty</City>
<Country>abffff</Country>
</User>
<User>
<Name>Stone</Name>
<Contact>875467</Contact>
<Email>dfttgh@dfdcm.com</Email>
<City>dfvbnj</City>
<Country>ddccvv</Country>
</User>
</User-Profile>
我想使用循环或任何东西显示所有数据并将这些数据分配给我的网页标签是否可能?这该怎么做?