Fred Heida wrote:
Using the XmlDocument and XMLElement::SetAttribute
is there away to indent the attribute per line, rather hen them having them
on the one line
e.g
<MyRoot Att1="Value1" Att2="Value2"></MyRoot>
but
<MyRoot
Att1="Value1"
Att2="Value2"
</MyRoot>
You can create custom XmlWriter to workaround it:
public class AttributeIndentingXmlTextWriter : XmlTextWriter
{
private TextWriter w;
private int depth;
//Add constructors as needed
public AttributeIndentingXmlTextWriter(TextWriter w)
: base(w)
{
this.w = w;
}
public override void WriteStartElement(string prefix, string
localName, string ns)
{
depth ++;
base.WriteStartElement(prefix, localName, ns);
}
public override void WriteFullEndElement()
{
depth--;
base.WriteFullEndElement();
}
public override void WriteEndElement()
{
depth--;
base.WriteEndElement();
}
public override void WriteStartAttribute(string prefix, string
localName, string ns)
{
if (base.Formatting == Formatting.Indented)
{
w.WriteLine();
for (int i=1; i<Indentation*depth; i++)
w.Write(IndentChar);
}
base.WriteStartAttribute(prefix, localName, ns);
}
}
Then save XmlDocument via instance of an AttributeIndentingXmlTextWriter.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com