Solved

Forcing a CrLF at the EOL of an XML node.

Posted on 2011-03-04
1
711 Views
Last Modified: 2013-12-17
What I want to do is should be very simple. Using either C# or VB.NET and MSXML 2 or higher, I want to FORCE an End of Line  (vbCrLF) on all Nodes within the XML output file. I want to do this so I can bring the file up in Visual Studio rather than in IE or FireFox. Some make think this is unusual; however, if the "pretty" format can be seen in VS, it can be seen in Every Text Editor.
The indenting doesn't have to work in dumb editors like NotePad but it would be nice if Visual Studio's EDI could format the file as well as the web browsers.

Thanks
Ken Jinks
0
Comment
Question by:jinksk1957
1 Comment
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 35038178
Hi jinksk1957;

If you want the XML document to be formatted when you write it to a file so that it can be loaded into a editor and viewed in "pretty" format you can do this:

// Create a new XML document
XmlDocument xDoc = new XmlDocument( );
// Load the document from the file system
xDoc.Load( "myDoc.xml" );

// Create an XML text writer to write the XML out with
XmlTextWriter xtw = new XmlTextWriter( "myDocFormatted.xml", null );
// Tell the XML writer to format the text
xtw.Formatting = Formatting.Indented;     
// Write the formatted XML file to the file system     
xDoc.WriteTo( xtw );
// Close the writter.
xtw.Close( );

Open in new window


See the XmlTextWriter for other formatting properties.

Fernando
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now