📜  c# 将字符串解析为 xml - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:38.597000             🧑  作者: Mango

代码示例2
/*

    
        John
        Smith
    
    
        James
        White
    

*/

XmlDocument xml = new XmlDocument();
xml.LoadXml(myXmlString); // suppose that myXmlString contains "..."

XmlNodeList xnList = xml.SelectNodes("/Names/Name");
foreach (XmlNode xn in xnList)
{
  string firstName = xn["FirstName"].InnerText;
  string lastName = xn["LastName"].InnerText;
  Console.WriteLine("Name: {0} {1}", firstName, lastName);
}