?
Solved

How can I Show an XmlDocument.innerXml Indented?

Posted on 2014-02-24
2
Medium Priority
?
1,162 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 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