简体   繁体   中英

Xml parser doesn't work

<?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>

Source code

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();

Hi, I can't parse xml. I want write some node values in file, but as result I get an empty txt file.

You want: artistNode.InnerText

Not: artistNode.value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM