noulouk
asked on
Format XmlDocument newline
Hi Experts,
My XmlDocument doesn't include any NewLine char.
So when I use:
System.Diagnostics.Debug.W riteLine(x mlDocument .OuterXml) ;
Then the text is written on 1 line.
I want the same XmlDocument to be formatted and displayed on several lines (each node on 1 line).
I don't want to rewrite all the XmlDocument: I want to format it at the end of the building.
Thanks in advance for your help.
My XmlDocument doesn't include any NewLine char.
So when I use:
System.Diagnostics.Debug.W
Then the text is written on 1 line.
I want the same XmlDocument to be formatted and displayed on several lines (each node on 1 line).
I don't want to rewrite all the XmlDocument: I want to format it at the end of the building.
Thanks in advance for your help.
ASKER
Thanks for this quick answer jimbobmcgee.
Your code achieve a part of the job, so we are near the final solution.
I get this formatting:
<item><subitem1></subitem1 >
<subitem2></subitem2>
<subitem3> </subitem3>
<subitem4></subitem4>
</item>
I'd like this:
<item>
<subitem1></subitem1>
<subitem2></subitem2>
<subitem3> </subitem3>
<subitem4></subitem4>
</item>
And my first line is something like this, so no formatting:
<?xml version="1.0" encoding="utf-8"?><?xml-st ylesheet type='text/xsl' href='/rss.xsl' version='1.0'?><!--descrip tion--><rs s version="2.0"><channel><ti tle>test</ title>
Your code achieve a part of the job, so we are near the final solution.
I get this formatting:
<item><subitem1></subitem1
<subitem2></subitem2>
<subitem3> </subitem3>
<subitem4></subitem4>
</item>
I'd like this:
<item>
<subitem1></subitem1>
<subitem2></subitem2>
<subitem3> </subitem3>
<subitem4></subitem4>
</item>
And my first line is something like this, so no formatting:
<?xml version="1.0" encoding="utf-8"?><?xml-st
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
private void TryMe()
{
Regex regEx = new Regex("</.+?>", RegexOptions.Multiline | RegexOptions.ECMAScript);
string outXml = regEx.Replace(xmlDoc.Outer
Debug.WriteLine(outXml);
}
private string InsertNewLine(Match m)
{
return string.Format("{0}{1}", m, Environment.NewLine);
}
HTH
J.