Solved

How can I Show an XmlDocument.innerXml Indented?

Posted on 2014-02-24
2
918 Views
Last Modified: 2014-02-24
Hi guys... I have this problem... I'm using an XmlDocument.innerXml in a message box... and I want the text indented inside the message box... I'm using this code inside a Function:

            private string convertXmlToString()
            {
            XmlDocument document = new XmlDocument();
            document.Load(@"C:\books.xml");
            string resp = Convert.ToString(MessageBox.Show(document.InnerXml, "Books"));
            return resp;        
            }
0
Comment
Question by:Conrado ZAVALA
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 39882792
You can load the child XML into a new XmlDocument. Then, create a new XmlWriter that has the appropriate indentation settings to which you can write the child XML as formatted:

e.g.

XmlDocument document = new XmlDocument();
XmlDocument subDocument = new XmlDocument();
XmlWriterSettings settings = new XmlWriterSettings() { Indent = true };
XmlWriter xWriter;
StringBuilder sb = new StringBuilder();

document.Load(@"C:\books.xml");
subDocument.LoadXml(document.InnerXml);
xWriter = XmlWriter.Create(sb, settings);
subDocument.WriteTo(xWriter);
xWriter.Flush();
xWriter.Close();

string resp = Convert.ToString(MessageBox.Show(sb.ToString(), "Books"));

Open in new window

0
 

Author Closing Comment

by:Conrado ZAVALA
ID: 39882814
Thank You Very Much..!!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPS jquery doesn't work 9 58
VB.NET Repostiory Pattern 7 35
Simple Injector with Web Service 4 38
MVC DDL Json Not Binding to Model 2 12
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

813 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

13 Experts available now in Live!

Get 1:1 Help Now