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>
Writing XML with C (or any other programming language) is really simple, you don't need any library (on the other hand reading and parsing XML is a bit more complex). As someone already noted, your did a mistake in your original XML expression. The content must be between 30 and 50000 characters.
It consists of several modules: core syntax, meta-syntax, linking, style-bindings, and maybe more. Of these only the core syntax is common to all XML applications. Applications can choose to omit the other modules if they don't need them.
Personal thoughts on what the XML syntax should be. Compare with my earlier notes. XML is a base-language for expressing arbitrary structured data in text form. It consists of several modules: core syntax, meta-syntax, linking, style-bindings, and maybe more. Of these only the core syntax is common to all XML applications.
You can either do this based on a specific structure and handcode the entire nested foreach loop mess, or if your text file format is consistent enough, you could probably write a recursive function to do it for you. The other method of parsing XML is to use an XmlReader.
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.
XDocument document = XDocument.Parse("<Employees></Employees>")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With