?
Solved

Forcing a CrLF at the EOL of an XML node.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 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