473,802 Members | 1,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5463
"TS" <ma*********@31 1.com> wrote in message news:et******** ******@TK2MSFTN GP11.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.NodeTyp e != XmlNodeType.Whi teSpace ) {
parentNode.Appe ndChild( 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.Formatti ng = Formatting.None ;
theDocument.Wri teTo( 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*********@31 1.com> wrote in message news:et******** ******@TK2MSFTN GP11.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.NodeTyp e != XmlNodeType.Whi teSpace ) {
parentNode.Appe ndChild( 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.Formatti ng = Formatting.None ;
theDocument.Wri teTo( 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
..PreserveWhite space = True

which keeps it from indenting and adding line breaks
"Derek Harmon" <lo*******@msn. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
"TS" <ma*********@31 1.com> wrote in message

news:et******** ******@TK2MSFTN GP11.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.NodeTyp e != XmlNodeType.Whi teSpace ) {
parentNode.Appe ndChild( 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.Formatti ng = Formatting.None ;
theDocument.Wri teTo( 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
6166
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 insert in the front. My code is give below. Is it possible to do without using XMLDOcument? Dim masterDoc As String = Request.PhysicalApplicationPath & "PageViews.xml" Dim writer As XmlTextWriter = Nothing
0
348
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
2559
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(); dstUsers.ReadXml("Users.xml"); DataTable dtbUsers = dstUsers.Tables; DataRow drwUser = dtbUsers.NewRow(); drwUser = "Test User 2"; dtbUsers.Rows.Add(drwUser);
1
9699
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
1828
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 am able to call this method from vb.net desktop client and add a record to the database(this I used to test if there is any problem in the webservice). My main requirement is to create a C++(native dll) wrapper what is recognized by a non...
11
6468
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); XPathNavigator nav = docNav.CreateNavigator(); XmlDocument doc = new XmlDocument(); doc.LoadXml("<DocumentData></DocumentData>"); XmlElement elem = doc.CreateElement(currentNodeName);
1
19079
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: <?xml version="1.0"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
1
1121
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 </LastName> </Dept>
2
9290
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 version="1.0" encoding="utf-8" ?> <AAA> <BBB> <CCC> <resource name="111">Content1</resource> <resource name="222">Content2</resource>
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10305
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3792
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.