5

Possible Duplicate:
Use XML Literals in C#?

I can do this in Visual Basic, How can I do this in C#

    Dim xmlTree As XElement = <Employees></Employees>
Community
  • 1
  • 1
user357086
  • 404
  • 1
  • 9
  • 23
  • C# (at least 4 and below) does *not* support XML literals. `new XElement("Employees")` would work here, but XElement can also parse larger [verbatim] text. –  Jan 14 '13 at 04:46
  • http://stackoverflow.com/questions/8768762/use-xml-literals-in-c , http://www.codeproject.com/Tips/84852/TRICK-Xml-Literals-for-C – Mitch Wheat Jan 14 '13 at 04:49

2 Answers2

10

Try:

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

or

XElement root = new XElement("Employees")

Another way is using XmlDocument class:

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

but I recommend to use XDocument. It is newer than XmlDocument, it has more clean API and support Linq To Xml.

Alexander Balte
  • 900
  • 5
  • 11
1
XDocument document = XDocument.Parse("<Employees></Employees>")
user1331
  • 38
  • 7