Solved

Forcing a CrLF at the EOL of an XML node.

Posted on 2011-03-04
1
713 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Turn on intranet settings 1 42
how to read json value 2 32
execute SQL Stored Procedure 1000 times from vb.net 3 26
Not seen Link button 5 19
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 long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

20 Experts available now in Live!

Get 1:1 Help Now