Re: newlines with XmlTextWriter
- From: "Andy Fish" <ajfish@xxxxxxxxxxxxxxxx>
- Date: Mon, 30 Jul 2007 16:11:00 +0100
I think I've got it now:
if you have a text node with an element after it, it will not reformat the
the element or any of its descendents.
that's probably quite a reasonable rule since most XML documents will tend
to have elements and writespace-only nodes at the top of the tree, and text
nodes at the bottom where whitespace is significant.
"Andy Fish" <ajfish@xxxxxxxxxxxxxxxx> wrote in message
news:u9b3Cpr0HHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
hmm, thanks martin, it appears you are correct. there is something a bit
more subtle going on here.
in the DOM tree, some of it was already formatted but new nodes I added in
weren't. when I serialise it, there are no newlines in the new sections.
I have a feeling that if there are any newlines in the tree (or maybe any
whitespace only text nodes) it assumes you are handling the line breaks
and it only puts its own in if there are none at all in the DOM.
"Martin Honnen" <mahotrash@xxxxxxxx> wrote in message
news:uaE9vCr0HHA.6072@xxxxxxxxxxxxxxxxxxxxxxx
Andy Fish wrote:
I would like to use an XmlTextWriter to format the XML so that each
element (or end element) appears on a new line, regardless of newlines
in the original document. The effect I'm looking for is something
similar to XMLSpy's pretty print.
I realise that, since whitespace is signiifcant, I am not going to get
out exactly the correct DOM document output, but I am formatting for
readability not automatic processing.
I can't see anything in XmlTextWriter or XmlWriterSettings to enable
this. is it possible?
Can you give an example of the formatting you want? Do you simply want
<root>
<foo>foo</foo>
<bar>bar</bar>
</root>
or even
<root>
<foo>
foo
</foo>
<bar>
bar
</bar>
</root>
? The first should work with XmlWriterSettings and Indent set to to true.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
.
- References:
- newlines with XmlTextWriter
- From: Andy Fish
- Re: newlines with XmlTextWriter
- From: Martin Honnen
- Re: newlines with XmlTextWriter
- From: Andy Fish
- newlines with XmlTextWriter
- Prev by Date: Validate against Schema and enter Error tags
- Next by Date: Re: Validate against Schema and enter Error tags
- Previous by thread: Re: newlines with XmlTextWriter
- Next by thread: Validate against Schema and enter Error tags
- Index(es):
Relevant Pages
|