msxml3: Fix xml declaration output when it's specified in loaded document (in case of stream).

This commit is contained in:
Nikolay Sivov 2012-07-08 22:49:43 +04:00 committed by Alexandre Julliard
parent 1a0552443c
commit 46d08bb6ce
3 changed files with 59 additions and 10 deletions

View File

@ -371,13 +371,17 @@ void xmldoc_link_xmldecl(xmlDocPtr doc, xmlNodePtr node)
/* unlinks a first "<?xml" child if it was created */
xmlNodePtr xmldoc_unlink_xmldecl(xmlDocPtr doc)
{
xmlNodePtr node;
static const xmlChar xmlA[] = "xml";
xmlNodePtr node, first_child;
assert(doc != NULL);
if (doc->standalone != -1)
/* xml declaration node could be created automatically after parsing or added
to a tree later */
first_child = doc->children;
if (first_child && first_child->type == XML_PI_NODE && xmlStrEqual(first_child->name, xmlA))
{
node = doc->children;
node = first_child;
xmlUnlinkNode( node );
}
else
@ -2383,8 +2387,9 @@ static HRESULT WINAPI domdoc_save(
ret = IUnknown_QueryInterface(pUnk, &IID_IStream, (void**)&stream);
if(ret == S_OK)
{
int options = get_doc(This)->standalone == -1 ? XML_SAVE_NO_DECL : 0;
ctx = xmlSaveToIO(domdoc_stream_save_writecallback,
domdoc_stream_save_closecallback, stream, NULL, XML_SAVE_NO_DECL);
domdoc_stream_save_closecallback, stream, NULL, options);
if(!ctx)
{

View File

@ -209,7 +209,6 @@ static void init_libxslt(void)
#endif
}
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
{
MSXML_hInstance = hInstDLL;

View File

@ -1504,9 +1504,16 @@ static const WCHAR szComplete6[] = {
'<','o','p','e','n','>','<','/','o','p','e','n','>','\n',0
};
static const CHAR szNonUnicodeXML[] =
"<?xml version='1.0' encoding='Windows-1252'?>\n"
"<open></open>\n";
#define DECL_WIN_1252 \
"<?xml version=\"1.0\" encoding=\"Windows-1252\"?>"
static const char win1252xml[] =
DECL_WIN_1252
"<open></open>";
static const char win1252decl[] =
DECL_WIN_1252
;
static const char szExampleXML[] =
"<?xml version='1.0' encoding='utf-8'?>\n"
@ -2327,7 +2334,7 @@ if (0)
/* try a BSTR containing a Windows-1252 document */
b = VARIANT_TRUE;
str = SysAllocStringByteLen( szNonUnicodeXML, sizeof(szNonUnicodeXML) - 1 );
str = SysAllocStringByteLen( win1252xml, strlen(win1252xml) );
r = IXMLDOMDocument_loadXML( doc, str, &b );
ok( r == S_FALSE, "loadXML succeeded\n");
ok( b == VARIANT_FALSE, "succeeded in loading XML string\n");
@ -7238,10 +7245,14 @@ static void test_save(void)
IXMLDOMElement *root;
BSTR sOrig, sNew, filename;
char buffer[100];
IStream *stream;
HGLOBAL global;
VARIANT_BOOL b;
DWORD read = 0;
VARIANT dest;
HANDLE hfile;
HRESULT hr;
char *ptr;
doc = create_document(&IID_IXMLDOMDocument);
if (!doc) return;
@ -7327,6 +7338,40 @@ static void test_save(void)
hr = IXMLDOMDocument_save(doc, dest);
EXPECT_HR(hr, S_OK);
/* loaded data contains xml declaration */
hr = IXMLDOMDocument_loadXML(doc, _bstr_(win1252xml), &b);
EXPECT_HR(hr, S_OK);
CreateStreamOnHGlobal(NULL, TRUE, &stream);
V_VT(&dest) = VT_UNKNOWN;
V_UNKNOWN(&dest) = (IUnknown*)stream;
hr = IXMLDOMDocument_save(doc, dest);
EXPECT_HR(hr, S_OK);
hr = GetHGlobalFromStream(stream, &global);
EXPECT_HR(hr, S_OK);
ptr = GlobalLock(global);
ok(!memcmp(ptr, win1252decl, strlen(win1252decl)), "got wrong xml declaration\n");
GlobalUnlock(global);
IStream_Release(stream);
/* loaded data without xml declaration */
hr = IXMLDOMDocument_loadXML(doc, _bstr_("<a/>"), &b);
EXPECT_HR(hr, S_OK);
CreateStreamOnHGlobal(NULL, TRUE, &stream);
V_VT(&dest) = VT_UNKNOWN;
V_UNKNOWN(&dest) = (IUnknown*)stream;
hr = IXMLDOMDocument_save(doc, dest);
EXPECT_HR(hr, S_OK);
hr = GetHGlobalFromStream(stream, &global);
EXPECT_HR(hr, S_OK);
ptr = GlobalLock(global);
ok(ptr[0] == '<' && ptr[1] != '?', "got wrong start tag %c%c\n", ptr[0], ptr[1]);
GlobalUnlock(global);
IStream_Release(stream);
IXMLDOMDocument_Release(doc);
free_bstrs();
}
@ -10697,7 +10742,7 @@ static void test_load(void)
ok(hfile != INVALID_HANDLE_VALUE, "failed to create test file\n");
if(hfile == INVALID_HANDLE_VALUE) return;
ret = WriteFile(hfile, szNonUnicodeXML, sizeof(szNonUnicodeXML)-1, &written, NULL);
ret = WriteFile(hfile, win1252xml, strlen(win1252xml), &written, NULL);
ok(ret, "WriteFile failed\n");
CloseHandle(hfile);