Israel Rodriguez
Israel Rodriguez

Reputation: 209

C# Create xml from Scratch

I know this is probably an easy question, but im having trouble just creating an xml file that will only create its root

i Have the following code but it doesnt work

        XDocument products = new XDocument(
    new XDeclaration("1.0", "utf-8", ""),
      new XElement("Users",

      )
    );
        products.Save("hello.xml");

Upvotes: 0

Views: 653

Answers (2)

cuongle
cuongle

Reputation: 75296

You need to save some where in your disk:

 XDocument products = new XDocument(
                 new XDeclaration("1.0", "utf-8", ""),
                 new XElement("Users"));

products.Save("c:\\hello.xml");

Edit:

To save in current directory:

var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "hello.xml");
products.Save(path);

Upvotes: 4

Wasp
Wasp

Reputation: 3425

You have an extra comma after "Users"

Upvotes: 0

Related Questions