How can I transform XML into a List or String[]?

后端 未结 8 1754
半阙折子戏
半阙折子戏 2020-12-01 08:19

How can I transform the following XML into a List or String[]:


  1
  2<         


        
8条回答
  •  清歌不尽
    2020-12-01 09:10

    Here is a way using XmlDocument :

    // A string containing the XML data
    string xml = "12";
    // The list you want to fill
    ArrayList list = new ArrayList();
    
    XmlDocument doc = new XmlDocument();
    // Loading from a XML string (use Load() for file)
    doc.LoadXml(xml); 
    // Selecting node using XPath syntax
    XmlNodeList idNodes = doc.SelectNodes("Ids/id");
    // Filling the list
    foreach (XmlNode node in idNodes)
        list.Add(node.InnerText);
    

提交回复
热议问题