Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to write xml file like the fallowing

XML
<VersioningConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
  <Status>Enabled</Status>
</VersioningConfiguration>


when I am writing I am unable to get the XMLNS attribute on the root element.

I have find some solution in the net but I am getting xmlns for every child elements.

can any one help me to write like above mentioned.

thanks,
purna
Posted

the solution is


C#
using (XmlWriter writer = XmlWriter.Create(filepath))
            {
                XNamespace ns = "http://s3.amazonaws.com/doc/2006-03-01/";
                var doc = new XDocument(
                    new XElement(ns + "VersioningConfiguration"));
                doc.WriteTo(writer);
            }
 
Share this answer
 
Never one to self-promote (until now) may I suggest this tip:

Rewriting XML Files.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900