|
-
Aug 14th, 2006, 08:03 PM
#1
Thread Starter
Fanatic Member
Xml: Append with \n
I have a code that looks like
Code:
[Test] public void Test()
{
XmlDocument doc = new XmlDocument();
XmlElement e = doc.CreateElement("database");
e.SetAttribute("name", "Northwind");
e.SetAttribute("type", "MSSQL");
doc.PrependChild(e);
XmlElement ee = doc.CreateElement("table");
ee.SetAttribute("name", "Categories");
e.PrependChild(ee);
Console.WriteLine(e.OuterXml);
}
When tested, it looks like
Code:
<database name="Northwind" type="MSSQL"><table name="Categories" /></database>
What I really want is something like
Code:
<database name="Northwind" type="MSSQL">
<table name="Categories" />
</database>
Any help?
Last edited by nebulom; Oct 5th, 2006 at 07:36 PM.
-
Sep 30th, 2006, 03:14 PM
#2
Hyperactive Member
Re: Xml: Append with \n
That's a good question. I would also like to know the answer to this
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Oct 1st, 2006, 04:31 AM
#3
Re: Xml: Append with \n
I believe that XmlDocument.Save() formats the XML
-
Oct 3rd, 2006, 10:17 PM
#4
Re: Xml: Append with \n
Yes. Make sure the PreserveWhiteSpace property is set to false and then call Save() to output the document with auto-indenting.
Code:
doc.Save(Console.Out);
-
Oct 5th, 2006, 02:34 PM
#5
Hyperactive Member
Re: Xml: Append with \n
 Originally Posted by axion_sa
I believe that XmlDocument.Save() formats the XML 
thank you. You are correct Thank you for the help !
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
-
Oct 5th, 2006, 07:36 PM
#6
Thread Starter
Fanatic Member
Re: Xml: Append with \n
Thanks for the reply but I haven't got much time to test this one. But a truly thanks for you guys. I'm not with C# for now so I haven't tested it. Fortunately, Bram is happy (and so am I) that the .Save method formats the code. Thanks, this is resolved.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|