【问题标题】:How to assign plain XML to C# variable [duplicate]如何将纯 XML 分配给 C# 变量 [重复]
【发布时间】:2013-01-14 04:44:41
【问题描述】:

可能重复:
Use XML Literals in C#?

我可以在 Visual Basic 中做到这一点,我如何在 C# 中做到这一点

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

【问题讨论】:

标签: c# xml linq vb6


【解决方案1】:

试试:

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

【讨论】:

    【解决方案2】:
    XDocument document = XDocument.Parse("<Employees></Employees>")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-30
      • 1970-01-01
      • 2014-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多