From 910d4e886dd97315d786a7f6dda9e6ac9f1221c8 Mon Sep 17 00:00:00 2001 From: "sicking%bigfoot.com" Date: Wed, 15 Oct 2003 20:10:47 +0000 Subject: [PATCH] Bug 199613: Don't put textnodes in the root of the document when parsing XML and XUL since the DOM doesn't allow that. r=peterv sr=jst --- content/base/src/nsDocumentEncoder.cpp | 10 ++++++++++ content/xml/document/src/nsXMLContentSink.cpp | 8 ++++---- content/xul/document/src/nsXULContentSink.cpp | 7 +++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/content/base/src/nsDocumentEncoder.cpp b/content/base/src/nsDocumentEncoder.cpp index 2217e523915..cae29c62e98 100644 --- a/content/base/src/nsDocumentEncoder.cpp +++ b/content/base/src/nsDocumentEncoder.cpp @@ -346,6 +346,15 @@ nsDocumentEncoder::SerializeNodeEnd(nsIDOMNode* aNode, } } + nsCOMPtr parent; + aNode->GetParentNode(getter_AddRefs(parent)); + if (parent) { + parent->GetNodeType(&type); + if (type == nsIDOMNode::DOCUMENT_NODE) { + aStr.Append((PRUnichar)'\n'); + } + } + return NS_OK; } @@ -920,6 +929,7 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString) rv = mSerializer->AppendDocumentStart(domdoc, aOutputString); if (NS_SUCCEEDED(rv)) { + aOutputString.Append((PRUnichar)'\n'); nsCOMPtr doc(do_QueryInterface(mDocument)); rv = SerializeToStringRecursive(doc, aOutputString); diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index 8b153be4403..2767562c996 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -1350,11 +1350,11 @@ NS_IMETHODIMP nsXMLContentSink::HandleCharacterData(const PRUnichar *aData, PRUint32 aLength) { - nsresult result = NS_OK; - if (aData) { - result = AddText(aData,aLength); + if (aData && mState != eXMLContentSinkState_InProlog && + mState != eXMLContentSinkState_InEpilog) { + return AddText(aData, aLength); } - return result; + return NS_OK; } NS_IMETHODIMP diff --git a/content/xul/document/src/nsXULContentSink.cpp b/content/xul/document/src/nsXULContentSink.cpp index 52387fe870e..fb9702e6789 100644 --- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -939,11 +939,10 @@ NS_IMETHODIMP XULContentSinkImpl::HandleCharacterData(const PRUnichar *aData, PRUint32 aLength) { - nsresult result = NS_OK; - if (aData) { - result = result = AddText(aData,aLength); + if (aData && mState != eInProlog && mState != eInEpilog) { + return AddText(aData, aLength); } - return result; + return NS_OK; } NS_IMETHODIMP