Re: newlines with XmlTextWriter

Tech-Archive recommends: Fix windows errors by optimizing your registry



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/




.



Relevant Pages

  • Re: Wild Card Search II
    ... >> Search for a paragraph starting with some letters followed by "." ... >> Include whitespace after ".": ... >> Apply the formatting to the result. ... >> Sub Test661 ...
    (microsoft.public.word.vba.general)
  • Re: FAQ Topic - What online resources are available? (2009-01-29)
    ... An Inconvenient API: The Theory of the DOM: ... this particular tree is an Internet Explorer ... because all that unnecessary whitespace would be ...
    (comp.lang.javascript)
  • Re: need a newline between paragraphs....
    ... every paragraph that is not on a ... consecutive newlines into exacty two newlines. ... required if there may be other adjacent whitespace, ... Gary Kline kline@xxxxxxxxxxx http://www.thought.org Public Service Unix ...
    (freebsd-questions)
  • Bjarnasons credentials ?
    ... That 80 line program only uses one C++ feature: ... The way I don't check for a null result from a malloc, ... my " variable names and lack of formatting ", ... I may add a lot of whitespace, formatting, ...
    (microsoft.public.win32.programmer.ui)
  • Re: childNodes.length IE and FF difference
    ... in element content will be treated simply as character data, and the DOM ... So, conversely, if the parser does pass on white space characters (and ... I thought that whitespace should be preserved because if CSS is to be used to display content, you can't remove whitespace that might be required by CSS, so better to preserve it and let CSS do its thing. ...
    (comp.lang.javascript)