0

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");
1
  • after running the program it should create an xml that looks like <Users> </Users> Commented Oct 8, 2012 at 17:35

2 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

6 Comments

@IsraelRodriguez: what do you mean the same directory? which directory?
products.Save(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\hello.xml");
im just getting <Users /> is that ok? i want <Users> </Users>
@IsraelRodriguez: You can use AppDomain.CurrentDomain.BaseDirectory;
the same directory where the executable is at
|
0

You have an extra comma after "Users"

4 Comments

This is a comment - not an answer!
Why? That's the problem he's experiencing, I took his code and tested it and it's not working because of that. If this is not an answer, then this is not a question either.
It's an easy question - your answer is true but not a solution for the question.
The question was very generic ("it doesn't work") so I just thought that was the problem, hence my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.