473,890 Members | 3,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing formatted XML

Dan
How would I write an XmlDocument to a file so that each node is properly
indented and followed by a carriage return?

Thanks...Dan
Nov 12 '05 #1
1 2932
http://msmvps.com/coad/archive/2004/06/22/8692.aspx
Using XmlDocument.Sav e(string file) produces a file with nicely indented
elements. XmlDocument.Out erXml returns a string without any formatting. If
you want a nicely formatted string (to display to the user, write to
console, etc), without directly writing to a file, you must use the
XmlTextWriter.
using System.IO;
using System.Xml;

public static string FormatXML(XmlDo cument doc)
{
// Create a stream buffer that can be read as a string
using (StringWriter sw = new StringWriter())

// Create a specialized writer for XML code
using (XmlTextWriter xtw = new XmlTextWriter(s w))
{
// Set the writer to use indented (hierarchical) elements
xtw.Formatting = System.Xml.Form atting.Indented ;

// Write the XML document to the stream
doc.WriteTo(xtw );

// Return the stream as a string
return sw.ToString();
}
}

"Dan" <Da*@discussion s.microsoft.com > wrote in message
news:E6******** *************** ***********@mic rosoft.com...
How would I write an XmlDocument to a file so that each node is properly
indented and followed by a carriage return?

Thanks...Dan

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3509
by: hpy_awad | last post by:
I am writing stings ((*cust).name),((*cust).address)to a file using fgets but rabish is being wrote to that file ? Look to my source please and help me finding the reason why this rabish is being written. /* Book name : File name : E:\programs\cpp\iti01\ch10\ex09_5p1.cpp Program discription: Adding name,Address to customer_record SETUP PROGRAM
2
2823
by: C.H. | last post by:
Hello, I am writing to a .txt file. Lots of data, about 1.1MB. It only took less than a second for VB6 to do so, but it took VB.NET one minute!! I am using a simple fileopen and print. Does anyone have any ideas? I've noticed that .NET runs slower for my other programs too. thanks in advance for any suggestions.
7
6121
by: utab | last post by:
Hi there, I am trying to read from a file and at the same time change certain fields of the same field, there are 6 fields in this file like 1 2 3 4 5 6 --------/--------/--------/--------/--------/--------/ // field_width=8 For example, I position my file pointer at the begining of the 4th fileld lets say 25th character(3*(field_width)+1) and when I try to
6
13144
by: redcic | last post by:
Hi all, I use the csv module of Python to write a file. My code is of the form : cw = csv.writer(open("out.txt", "wb")) cw.writerow() cw.writerow() And i get an out.txt file looking like:
0
9979
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10827
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7170
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6049
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4681
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4275
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.