473,657 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PreserveWhiteSp ace not preserving all whitespace

2 New Member
I'm using C# and .NET 2

I am creating an XmlDocument object and setting PreserveWhiteSp ace to True,
I use loadXMl to load XML from a file but when I look at the XML of the document object some of the whitespace has been stripped.

I need to EXACTLY maintain the original formatting of the file.

I want to use an XMLDocument as I need to query it using XPath and amend and add nodes.

Here is the original XML ...

Expand|Select|Wrap|Line Numbers
  1. <El1>
  2.   <El2>
  3.     <MCG 
  4.       class="UnionCodeGroup" 
  5.       version="1" 
  6.       PermissionSet="Full">
  7.       <MemberShip 
  8.         class="MembershipClass" 
  9.         version="1" 
  10.         Url="http://www.thescripts.com/"
  11.       />
  12.     </MCG>
  13.   <El2>
  14. </El1>
After I load it into the document it looks like this ...
Expand|Select|Wrap|Line Numbers
  1. <El1>
  2.   <El2>
  3.     <MCG class="UnionCodeGroup" version="1" PermissionSet="Full">
  4.       <MemberShip class="MembershipClass" version="1" Url="http://www.thescripts.com/"/>
  5.     </MCG>
  6.   <El2>
  7. </El1>

I know that it shouldn't make any difference as they are functionally the same but the 3rd party application that uses this file does requirte the formatting to be maintained (the attributes must be on different lines)

Any help on how I can preserve the original whitespace completely would be very welcome.

Thanks
May 3 '07 #1
2 2352
dorinbogdan
839 Recognized Expert Contributor
Welcome to TheScripts TSDN...

I'm afraid that the only solution to preserve exactly the text format is to open/edit the XML as simple text file.
The XMLDocument object seems to ignore spaces/new lines inside of < > tags.
May 3 '07 #2
Fergus Mcgee
2 New Member
Thanks for the reply. I suspected that was the case. I was trying to avoid treating it as a simple text file but feared it was the only solution.

Fergus
May 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1254
by: R | last post by:
Hello everybody. I've got problem with preserving whitespaces: $doc->preserveWhiteSpace = false; works fine up to the point when I try to load external XML file. // up to this point whitespaces are OK // load new DomDocument
1
1453
by: Oleg Dulin | last post by:
Colleagues: Does anyone know if there are less-lossy XML parsers and serializers that can capture and reproduce the structure of the input XML file including tabulation,whitespace, etc. ? We would love to know about experiences with parse/serialization approaches that have a greater infoset than that provided by SAX and DOM, especially related to ignorable whitespace and attributes ordering/whitespace. We are editing XML and want to...
1
10187
by: Riko Eksteen | last post by:
Hi I'm reading an xml file into an XmlDocument, adding some nodes, and writing it back out. I would like the nodes I add to assume the same level of indeting as the rest of the document. (I load the document with PreserveWhiteSpace = true.) I thought I could do this by using an XmlTextWriter with Formatting set to Formatting.Indented, but this doesn't work. The Formatting.Indented on the XmlTextWriter only indents my output when I...
16
5117
by: TTroy | last post by:
Hello, I'm relatively new to C and have gone through more than 4 books on it. None mentioned anything about integral promotion, arithmetic conversion, value preserving and unsigned preserving. And K&R2 mentions "signed extension" everywhere. Reading some old clc posts, I've beginning to realize that these books are over-generalizing the topic. I am just wondering what the difference between the following pairs of terms are: 1)...
0
1180
by: ryang | last post by:
Hi, PreserveWhitesapce property doesn't seem to work for me in various ways. Here are samples that I tried. First the XmlDocument is loaded with PreserveWhitespace = true. XmlDocument xmlDoc = new XmlDocument(); xmlDoc.PreserveWhitespace = true; xmlDoc.Load(validatingReader);
0
1819
by: Shaun Dore | last post by:
Hi, What is the Xml DOM PreserveWhitespace property supposed to do? I thought that setting it to false would remove the superfluous white spaces? For instance, in the following code I would expect the spaces after "for rent" would be stripped, but it's not the case. I know workarounds for this but I'm pretty sure in the old MSXML2.DomDocument this used to work very well. XmlDocument oXml = new XmlDocument(); oXml.PreserveWhitespace =...
3
8169
by: zjw2112 | last post by:
Hello. I have some javascript code that dynamically creates a textarea and sets the wrap value to hard, which I thought would preserve CR/LF in the textarea: var otherTextArea = document.createElement("textarea"); otherTextArea.setAttribute("rows", "10"); otherTextArea.setAttribute("cols", "30"); otherTextArea.setAttribute("id", "otherTextArea"); otherTextArea.setAttribute("wrap", "hard");
3
3292
by: sophia.agnes | last post by:
Dear all, I was going through the book "C a software engineering approach by darnell & Margolis" there was a section named sign preserving vs value preserving it is as follows sign preserving rule:- when signed and un signed objects meet in an expression, the result is
4
6796
by: =?Utf-8?B?TWFyaw==?= | last post by:
Hi... I just noticed something that seems counter-intuitive to me. By default an XmlDocument is set with PreserveWhitespace=false. This means that XmlDocument.Load() or .LoadXml() will strip/condense non-semantic whitespace. *But* I just found that if you take that self-same XmlDocument and do either XmlDocumentFragment node = doc.CreateDocumentFragment(); node.InnerXml = "<foo/>\r\n<bar/>";
0
8421
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
8325
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
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
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
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.