473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

using appendChild using XmlDocument without indentation

TS
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?

thanks
Nov 12 '05 #1
3 5389
"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
Nov 12 '05 #2
"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
Nov 12 '05 #3
TS
thanks, but I found
..PreserveWhitespace = True

which keeps it from indenting and adding line breaks
"Derek Harmon" <lo*******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"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

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to...
0
by: TS | last post by:
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? thanks
1
by: Piyush Gupta | last post by:
Hi All, I am using following code snippet to add another user in Users.xml: ------------------------------------------------------------------- DataSet dstUsers = new DataSet();...
1
by: Peter Nofelt | last post by:
Hey All, I'm running into this issue with parsing through an xml document by tag name. Below is an example xml document: File Name: things.xml <things> <people> <name>Peter</name>
0
by: Sathya | last post by:
Hi, I have a vb.net webservice which takes XMLDocument as a parameter and returns bool. Signature of the method is some thing like this AddXmlEmpDetails(xmlEmp as XMLDocument) as Boolean. I...
11
by: ericms | last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I have tried the follwing with no luck: XmlDocument docNav = new XmlDocument(); docNav.LoadXml(xmlString);...
1
by: Mikus Sleiners | last post by:
I have a task to create xml document from c# code. I have example of that document should look like and also a xml schema. I wonder if i can use this xml schema somehow ? This is schema: ...
1
by: Abhijit D. Babar | last post by:
Hello, I have to generate XML file as follow, using XmlDocument. <Company> < Employee EID=”111” Description=” xyz”> <Dept DeptNo=”D10”> <FirstNameAbhijit </FirstName> <LastNameBabar...
2
by: yxq | last post by:
I want to add some elements to a XML file using XmlDocument, how to do? thank you very much. The original XML file like: //////////////////////////////////////////////////////// <?xml...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.