473,402 Members | 2,053 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,402 software developers and data experts.

Xml replace method removes indentations

Hi,

I am using the document.replacechild method to replace some values. But when
used, it removes the previous indentation that was in the document for that
node. Actually looks like the CRLF is being removed for some reason, any
luck.

Eg...

The original doc
<locationAdd>

<friendlyName>

<ColumnNo>2</ColumnNo>

</friendlyName>

<ColumnNo>2</ColumnNo>

<currencyCode>

<ColumnNo>2</ColumnNo>

< /currencyCode>

</locationAdd>

The replaced doc...

<locationAdd>

<friendlyName>will</friendlyName>will<currencyCode>will</currencyCode></loca
tionAdd>

Nov 12 '05 #1
2 1678
It will do, the XmlDom has no concept of spacing, carriage returns or the
like. These are all this that can exist in a .xml file for readability when
we edit them, and when IE views the xml file, it ignores your spacing and
carriage returns and presents the XML in a predifined layout.

I think that what is happening is when you pass your document to the dom,
all the nodes are read out, your replacment occurs, then you convert it back
to a document that contains no spacing...

hope that helps.
Dan.

"Amendra" <am*****@virtusa.com> wrote in message
news:eF**************@TK2MSFTNGP11.phx.gbl...
Hi,

I am using the document.replacechild method to replace some values. But when
used, it removes the previous indentation that was in the document for that
node. Actually looks like the CRLF is being removed for some reason, any
luck.

Eg...

The original doc
<locationAdd>

<friendlyName>

<ColumnNo>2</ColumnNo>

</friendlyName>

<ColumnNo>2</ColumnNo>

<currencyCode>

<ColumnNo>2</ColumnNo>

< /currencyCode>

</locationAdd>

The replaced doc...

<locationAdd>

<friendlyName>will</friendlyName>will<currencyCode>will</currencyCode></loca
tionAdd>


Nov 12 '05 #2
Hello!

This came up a week ago. You can use the following method to format the
string of the Xml. Please take notice, that you are able to pass the
XmlDocument (or XmlNode) to the XmlTextWriter (instead of the string as in
this example).

These lines of code will pretty-print your Xml string ..

XmlTextReader r = new XmlTextReader(new StringReader(xmlString));
r.MoveToContent();
StringWriter sw = new StringWriter();
XmlTextWriter w = new XmlTextWriter(sw);
w.Formatting = Formatting.Indented;
w.WriteNode(r,false);
w.Close();
return sw.ToString();

--
venlig hilsen / with regards
anders borum
--
Nov 12 '05 #3

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

Similar topics

12
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so...
2
by: Amendra | last post by:
Hi, I am using the document.replacechild method to replace some values. But when used, it removes the previous indentation that was in the document for that node. Actually looks like the CRLF is...
7
by: McKirahan | last post by:
Can someone help me out? I'm looking for a regular expression that inserts a space into a string after every fourth byte (except the last). Specifically, this is to display credit card...
30
by: Philippe Bertrand | last post by:
Is this a bug in the C# compiler or CLR runtime? enum MyEnum { ZERO = 0, ONE = 1, TWO = 2 } class Foo { public Foo(string,object) { ... } public Foo(string,MyEnum) { ... } } Foo f = new...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
4
by: jgabbai | last post by:
Hi, What is the best way to white list a set of allowable characters using regex or replace? I understand it is safer to whitelist than to blacklist, but am not sure how to go about it. Many...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
3
by: Pascal | last post by:
bonjour hello I would like to trim a string of all its white spaces so i used myString.trim() but it doesn't work as supposed : unsecable space are remaining in the middle of my string... i...
2
by: Microsoft Newsgroups | last post by:
I am trying to consume a web service where there is a dot in the method name as defined in the portType and binding section of the WSDL file. Here is an example: <operation...
7
by: heavyone | last post by:
I am trying to write a removeFirst method for an ArrayList of the generic type. The removeFirst method is supposed to do a few things: 1) If the list is empty it throws an error. 2) It stores the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.