Solved

How can I Show an XmlDocument.innerXml Indented?

Posted on 2014-02-24
2
861 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 74

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
Comment Utility
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
Comment Utility
Thank You Very Much..!!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

18 Experts available now in Live!

Get 1:1 Help Now