我有一个 xml 文件,我想读取并输出它的数据,我的 xml 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<serverfiles>
<file name="picture1.jpg"/>
<file name="file1.txt"/>
<folder name="subfolder">
<file name="picture2.jpg"/>
<file name="file2.txt"/>
<folder name="anotherfolder">
<file name="file3.txt"/>
</folder>
</folder>
<folder name="anotherfolder"/>
</serverfiles>
并希望这样输出:
picture1.jpg
file1.txt
subfolder\picture2.jpg
subfolder\file2.txt
subfolder\anotherfolder\file3.txt
我试过这个:
string xml = new WebClient().DownloadString("");
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xml);
XmlElement element = xdoc.DocumentElement;
XmlAttributeCollection attr_coll = element.Attributes;
for(int i = 0; i < attr_coll.Count; i++)
{
string attr_name = attr_coll[i].Name;
}
但是在 for 循环计数中,我什么也得不到,有人可以帮助我。