473,563 Members | 2,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

vb.net xml formatting whitespace

I have an xml file that I want to maintain the whitespace on and
spacing between my sections. I have something like this.

<!-- Comment lines A -->
<!-- Comment lines A -->
<A>
<B>test</B>
<B>test1</B>
<B>test2</B>
</A>
blank line here
<!-- Comment lines B -->
<!-- Comment lines B -->
<C>
<B>test</B>
<B>test1</B>
<B>test2</B>
</C>

I have written a little editor for users to maintain the various xml.
Everything works great except I want to keep the blank lines between my
groups. I have preservewhitesp ace set to True when I load/save the
document, but when I save it back out after replacing the edited node,
I lose formatting. This is what I end up with if <C> is replaced. If
I take out the preservewhitesp ace, I lose the blank lines in the xml
file.

<!-- Comment lines A -->
<!-- Comment lines A -->
<A>
<B>test</B>
<B>test1</B>
<B>test2</B>
</A>
blank line here
<!-- Comment lines B-->
<!-- Comment lines B-->
<C><B>test</B><B>test1</B><B>test2</B></C>

Here is the code I use to write the file back out.

Dim writer As XmlTextWriter = New
XmlTextWriter(_ mWorkingXMLFile Name, Nothing)
writer.Formatti ng = Formatting.Inde nted
_mWorkingXMLDoc .PreserveWhites pace = True
_mWorkingXMLDoc .Save(writer)
writer.Flush()
writer.Close()

I thought the combination of formatting.inde nted and whitespace=true
would work, but they seem to counteract each other. Any ideas ?

When I build my replacement XML, its just a string, then loaded into
another document. Do I just need CRLF in the proper locations ?

One other thing, when I write out the new xml, I want to verify that
the comments above the node exist, otherwise I want to create them.
How can I go about verifying this or inserting new ones in the proper
location ?

Many thanks !
Mark

Jan 26 '06 #1
0 1223

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

Similar topics

3
3566
by: Ray | last post by:
I have put together some pretty simple code for adding and removing elements from an XML file, but am having a problem with toxml writing out the correct format after I have called appendChild on a node. Here is a snippet: if (action == 'add'): newCluster = domi.createElement(elementType) newCluster.setAttribute("Name", elementName)...
3
2315
by: Ike | last post by:
Does anyone know where I can find example scritp for formatting text input? I want to have a text box where only legitiamte filesname under unix can be netered (no whitespace, only alphanumeric, must start alpha) -Ike
2
2046
by: vector | last post by:
Here is a function more or less exactly as I found it from somewhere on the internet. static string BeautifyXML(string sXML) { string result = ""; System.IO.MemoryStream ms = new System.IO.MemoryStream(); System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(ms, System.Text.Encoding.Unicode);
1
10163
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,...
2
1209
by: Simon M | last post by:
Hi, Hopefully someone can answer this; I am using aspx and c# to format XML using an XSL transform, the output is then written to the the response of the webform. When the page first loads the layout is not like it is described in the XSL... there is too much whitespace with gaps between things where there should be no gaps. If I save the...
25
2681
by: mdh | last post by:
Hi Group, Not looking for an answer, but more of an explanation. Thinking back to those heady days when you had the time to do them, may I ask this. Exercise 1-22 asks for a program to "fold" long input lines into 2 or more shorter lines before the nth column... etc etc. Now, there are numerous anwers on the web and in the "C answer...
93
3828
by: Phlip | last post by:
C++ers: Feast your eyes: void Home:: inherits (IdentifierPtr const& id) { ... }
6
1694
by: Jack | last post by:
Hi there, Given a standard .NET string, does anyone know what the regular expression would be to locate each (optional) formatting item in the string (or more likely does anyone have a link that will show me this). For instance, given the following simple string: "My phone number is {0} and my SSN is {1}" I want to enumerate (or create...
1
3099
by: JAM | last post by:
I'm trying to code some directory structure as my output / input file using XML. I would like to see formatiing with indentations. mimicking directory tree structure. Unfortunately the code such as this: using (XmlTextWriter xw = new XmlTextWriter("C:\\Temp\\test.xml", Encoding.UTF8)) { xw.Formatting = Formatting.Indented;...
0
7664
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...
0
7583
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...
0
7885
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. ...
1
7638
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...
0
7948
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...
1
5484
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1198
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
923
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...

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.