<?xml version="1.0" encoding="utf-8"?>
<response list="true">
<audio>
<aid>253663595</aid>
<artist>Example</artist>
<duration>389</duration>
<lyrics_id>57485771</lyrics_id>
<genre>18</genre>
</audio>
<audio>
<aid>253663595</aid>
<artist>Example1</artist>
<duration>400</duration>
<lyrics_id>57485772</lyrics_id>
<genre>20</genre>
</audio>
</response>
源代码
XmlDocument allAudio = new XmlDocument();
allAudio.Load(@"e:\Audio.xml");
StreamWriter write_text = File.CreateText(@"e:\Audio.txt");
XmlNodeList audioNodes = allAudio.GetElementsByTagName("audio");
foreach (XmlNode audioNode in audioNodes)
{
XmlNode artistNode = audioNode["artist"];
write_text.WriteLine(String.Format("{0}", artistNode.Value));
}
write_text.Close();
嗨,我无法解析xml。我想在文件中写一些节点值,但结果我得到一个空的txt文件。
答案 0 :(得分:0)
您想:artistNode.InnerText
不是:artistNode.value