Solved

Forcing a CrLF at the EOL of an XML node.

Posted on 2011-03-04
1
717 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 63

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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