Bug 186554 XMLSerializer does not serialize documentElement correctly. Extended document encoder API to make it possible to seriaalize a node. r=jfrancis, sr=bzbarsky.

This commit is contained in:
heikki%netscape.com 2003-04-15 18:13:13 +00:00
Родитель f03e3e63d9
Коммит e485f5fcdf
3 изменённых файлов: 20 добавлений и 9 удалений

Просмотреть файл

@ -197,6 +197,13 @@ public:
*/
NS_IMETHOD SetRange(nsIDOMRange* aRange) = 0;
/**
* If the node is set to a non-null value, then the
* node is used for encoding, otherwise the entire
* document or range or selection is encoded.
*/
NS_IMETHOD SetNode(nsIDOMNode* aNode) = 0;
/**
* Documents typically have an intrinsic character set.
* If no intrinsic value is found, the platform character set

Просмотреть файл

@ -107,6 +107,7 @@ public:
// Inherited methods from nsIDocumentEncoder
NS_IMETHOD SetSelection(nsISelection* aSelection);
NS_IMETHOD SetRange(nsIDOMRange* aRange);
NS_IMETHOD SetNode(nsIDOMNode* aNode);
NS_IMETHOD SetWrapColumn(PRUint32 aWC);
NS_IMETHOD SetCharset(const nsAString& aCharset);
NS_IMETHOD GetMimeType(nsAString& aMimeType);
@ -143,6 +144,7 @@ protected:
nsCOMPtr<nsIDocument> mDocument;
nsCOMPtr<nsISelection> mSelection;
nsCOMPtr<nsIDOMRange> mRange;
nsCOMPtr<nsIDOMNode> mNode;
nsCOMPtr<nsIOutputStream> mStream;
nsCOMPtr<nsIContentSerializer> mSerializer;
nsCOMPtr<nsIUnicodeEncoder> mUnicodeEncoder;
@ -263,6 +265,13 @@ nsDocumentEncoder::SetRange(nsIDOMRange* aRange)
return NS_OK;
}
NS_IMETHODIMP
nsDocumentEncoder::SetNode(nsIDOMNode* aNode)
{
mNode = aNode;
return NS_OK;
}
NS_IMETHODIMP
nsDocumentEncoder::SetCharset(const nsAString& aCharset)
{
@ -941,6 +950,9 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
rv = SerializeRangeToString(mRange, aOutputString);
mRange = nsnull;
} else if (mNode) {
rv = SerializeToStringRecursive(mNode, aOutputString);
mNode = nsnull;
} else {
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));
rv = mSerializer->AppendDocumentStart(domdoc, aOutputString);

Просмотреть файл

@ -38,7 +38,6 @@
#include "nsDOMSerializer.h"
#include "nsIDOMNode.h"
#include "nsIDOMRange.h"
#include "nsIDOMClassInfo.h"
#include "nsIOutputStream.h"
#include "nsIDocument.h"
@ -54,9 +53,6 @@
#include "nsICodebasePrincipal.h"
#include "nsIURI.h"
#include "nsLayoutCID.h" // XXX Need range CID
static NS_DEFINE_CID(kRangeCID,NS_RANGE_CID);
nsDOMSerializer::nsDOMSerializer()
{
}
@ -117,11 +113,7 @@ static nsresult SetUpEncoder(nsIDOMNode *aRoot, const char* aCharset, nsIDocumen
// If we are working on the entire document we do not need to specify which part to serialize
if (!entireDocument) {
nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
rv = range->SelectNode(aRoot);
if (NS_SUCCEEDED(rv)) {
rv = encoder->SetRange(range);
}
rv = encoder->SetNode(aRoot);
}
if (NS_SUCCEEDED(rv)) {