"TS" <ma*********@311.com> wrote in message news:et**************@TK2MSFTNGP11.phx.gbl...
HI, is there any option while using appendChild so that it doesn't do the
autotomatic indentation and line breaks so that the tags are appended back
to back?
AppendChild() affects the node tree of the XML document,
it doesn't directly affect it's formatting. If you're
copying nodes from another XML document, then perhaps
you're copying Whitespace XmlNodes. Don't copy them by
restricting calls to AppendChild with an if conditional
similar to this:
if ( theNode.NodeType != XmlNodeType.WhiteSpace ) {
parentNode.AppendChild( theNode);
}
If that's not the case, look at the classes you're using
to control the formatting (like XmlTextReader). By default,
these don't apply pretty-printing, but to make sure:
StreamWriter inner = new StreamWriter( fileStream);
//
// no CR-LF's.
//
inner.NewLine = String.Empty;
XmlTextWriter writer = new XmlTextWriter( inner);
//
// no tabs/indenting.
//
writer.Formatting = Formatting.None;
theDocument.WriteTo( writer);
This turns off linebreaking characters on the underlying
TextWriter subclass (in this example, StreamWriter, but
the property is available on any concrete TextWriter
[n.b., XmlTextWriter IS-A XmlWriter, not TextWriter]).
Finally, it turns off indentation/pretty-printing on the
XmlTextWriter, before writing out the XmlDocument
through the [non-formatting] Writers to the base
stream.
Derek Harmon