这是我的xml
<configuration>
<login>Your login id</login>
<password>Your password</password>
<option1>option1 value</option1>
<optiony>optionY value</optiony>
</configuration>
如何循环获取xml元素名称和元素值?
login, Your login id
password, Your password
Etc....
xml元素名称和值未知,它可以是任何值。
答案 0 :(得分:1)
XmlDocument doc = new XmlDocument();
doc.Load("yourfile.xml");
XmlElement eb = (XmlElement) doc.GetElementsByTagName("configuration")[0];
XmlNodeList elemList = eb.GetElementsByTagName("*");
string output="";
foreach (XmlElement el in elemList)
{
output += el.Name+", ";
output += el.InnerText+"\r\n";
}