Solved

How can I Show an XmlDocument.innerXml Indented?

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I hook up a command with parameters to an WPF MVVM Menu Item in XAML? 2 26
using sqldatareader to populate cells in Excel-syntax 6 21
VS 2017 18 101
Get sourcecode path 14 46
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

679 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