Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Forcing a CrLF at the EOL of an XML node.

Posted on 2011-03-04
1
Medium Priority
?
725 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 64

Accepted Solution

by:
Fernando Soto earned 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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