Solved

How can I Show an XmlDocument.innerXml Indented?

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

17 Experts available now in Live!

Get 1:1 Help Now