如何将纯XML分配给C#变量

本文关键字:变量 分配 XML | 更新日期: 2023-09-27 17:52:41

可能重复:
在C#中使用XML文本?

我可以在Visual Basic中完成,如何在C#中完成

    Dim xmlTree As XElement = <Employees></Employees>

如何将纯XML分配给C#变量

尝试:

XDocument document = XDocument.Parse("<Employees></Employees>")

XElement root = new XElement("Employees")

另一种方法是使用XmlDocument类:

XmlDocument document = new XmlDocument();
document.LoadXml("<Employees></Employees>");

但我建议使用XDocument。它比XmlDocument更新,具有更干净的API,并支持Linq-To-Xml。

XDocument document = XDocument.Parse("<Employees></Employees>")