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

XML Aesthetics

Hi folks,

If I have a .NET XmlDocument object into which I've imported a full node
from another document, I'm running into a formatting issue. The problem
arises when the imported node is nested at a different level in its
source document than its destination document (among other things) which
causes the indenting/whitespace characteristics of the resulting
document to be 'off'.

Not the most show-stopping problem in the world I know, but I was
surprised to find that there wasn't a member of XmlDocument that
're-normalised' the content into correct nested indents.

Have I missed something or am I really going to have bodge whitespace
and carriage-returns into the document to get it to look pretty?

Many thanks in advance.

Regards,

Neil B
Nov 12 '05 #1
2 925
Neil B wrote:
If I have a .NET XmlDocument object into which I've imported a full node
from another document, I'm running into a formatting issue. The problem
arises when the imported node is nested at a different level in its
source document than its destination document (among other things) which
causes the indenting/whitespace characteristics of the resulting
document to be 'off'.

Not the most show-stopping problem in the world I know, but I was
surprised to find that there wasn't a member of XmlDocument that
're-normalised' the content into correct nested indents.

Have I missed something or am I really going to have bodge whitespace
and carriage-returns into the document to get it to look pretty?


I'm not aware of any in-memory re-indenting XmlDocument facilities, but
you certancly can reindent document when serializing it:

XmlTextWriter w = new XmlTextWriter(...);
w.Formatting = Formatting.Indented;
doc.Save(w);
w.Close();

--
Oleg Tkachenko [XML MVP, MCP]
http://blog.tkachenko.com
Nov 12 '05 #2
Oleg Tkachenko [MVP] wrote:
Neil B wrote:
If I have a .NET XmlDocument object into which I've imported a full
node from another document, I'm running into a formatting issue. The
problem arises when the imported node is nested at a different level
in its source document than its destination document (among other
things) which causes the indenting/whitespace characteristics of the
resulting document to be 'off'.

Not the most show-stopping problem in the world I know, but I was
surprised to find that there wasn't a member of XmlDocument that
're-normalised' the content into correct nested indents.

Have I missed something or am I really going to have bodge whitespace
and carriage-returns into the document to get it to look pretty?

I'm not aware of any in-memory re-indenting XmlDocument facilities, but
you certancly can reindent document when serializing it:

XmlTextWriter w = new XmlTextWriter(...);
w.Formatting = Formatting.Indented;
doc.Save(w);
w.Close();

Oleg,

Indeed, it is that simple. Many thanks.

Neil B
Nov 12 '05 #3

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

Similar topics

90
by: Mark Hahn | last post by:
"Michael Geary" <Mike@Geary.com> wrote ... >Does anyone have some sample code where obj$func() would be used? > (Apologies if I missed it.) There have been so many messages about delegation...
25
by: Haines Brown | last post by:
I have a table with three columns, and I want the data in the first column to align left, while that in the remaining columns to align right: #testTable { text-align: right; } #leftcol {...
42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
258
by: Terry Andersen | last post by:
If I have: struct one_{ unsigned int one_1; unsigned short one_2; unsigned short one_3; }; struct two_{ unsigned int two_1;
3
by: VB Programmer | last post by:
In my ASP.NET application I have 1 standard HTML page. How do I: 1. Use a background image in one of my table cells? 2. Use a standard HTML text/input box with a specific font, size and...
150
by: tony | last post by:
If you have any PHP scripts which will not work in the current releases due to breaks in backwards compatibility then take a look at http://www.tonymarston.net/php-mysql/bc-is-everything.html and...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
100
by: Angel Tsankov | last post by:
Can someone recommend a good source of C/C++ coding style. Specifically, I am interested in commenting style and in particular how to indent comments and the commented code, rather than when to...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...
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.