XML and newlines

Chris Tavares christophertavares at earthlink.net
Sat Feb 16 14:23:53 EST 2002


"Hans Nowak" <wurmy at earthlink.net> wrote in message
news:3C6E95FA.F95C914B at earthlink.net...
> Henrik Motakef wrote:
> >
> > Hans Nowak <wurmy at earthlink.net> writes:
> >
[ ...snip... ]
>
> That is probably my fault. Here's a short summary. I want to store a
> multiline string, containing newlines, in SQL Server, using an
> updategram in XML. I post the record. I retrieve the record back.
> Newlines are gone from the string.
>
> I get the records back as XML too. In raw, unparsed XML (just a string)
> the newlines are still there. As soon as I parse the XML, they are
> somehow removed. See my other post to Martin von Loewis.
>
> I don't know much about XML; if whitespace is considered insignificant,
> like in HTML, then it might be removed when parsing.
>

Whitespace in XML is a little odd. It depends on the DTD/Schema wether it's
significant or not. The normal solution is for the XML parser to have a
"preserveWhitespace" setting, which will guarantee that you get everything
(newlines and all). However, I took a spin through the minidom docs and
couldn't find anything. Hmm... guess that's why it's a "mini" DOM. Have you
tried using either SAX or 4DOM instead?

> > However, one thing that might possibly be related is that XML parsers
> > are required to convert all of the funky end-of-line markers around
> > (i.e. "\r\n", "\n", "\r") to a single newline "\n". Scince you Use SQL
> > Server, I assume that you are also running Windows, where the
> > "official" newline is "\r\n". Could that be related to your problem?
>

This is probably not a problem - MSXML is fairly flexible about such things,
and I'm sure that SQL server is either using that parser, or using a good
chunk of code from it.

 > It was part of a previous problem; the XML supposedly only contained \n,
> where \r\n was desirable. While investigating it, I stumbled upon a
> different, more serious problem-- no newlines at all.
>
> On a side note, any operating system with an Internet connection can talk
> to the SQL Server database using SQLXML. All you need is some HTTP
> functions (like Python has in httplib) to talk to it. No drivers needed.
> All communication with the server is done through XML. Pretty fly for
> a M$ product. ;-)
>

Yeah, MS does get some stuff right once in a while. The real question is -
what if you want to STOP somebody from talking to it over http?

-Chris






More information about the Python-list mailing list