Module: wine Branch: master Commit: 46d08bb6cefa6372ef3f597a130d14ee62c662dc URL: http://source.winehq.org/git/wine.git/?a=commit;h=46d08bb6cefa6372ef3f597a13...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Sun Jul 8 22:49:43 2012 +0400
msxml3: Fix xml declaration output when it's specified in loaded document (in case of stream).
---
dlls/msxml3/domdoc.c | 13 +++++++--- dlls/msxml3/main.c | 1 - dlls/msxml3/tests/domdoc.c | 55 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/dlls/msxml3/domdoc.c b/dlls/msxml3/domdoc.c index 0c0df36..5ac03e1 100644 --- a/dlls/msxml3/domdoc.c +++ b/dlls/msxml3/domdoc.c @@ -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) { diff --git a/dlls/msxml3/main.c b/dlls/msxml3/main.c index 1553e77..6ecfdbc 100644 --- a/dlls/msxml3/main.c +++ b/dlls/msxml3/main.c @@ -209,7 +209,6 @@ static void init_libxslt(void) #endif }
- BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv) { MSXML_hInstance = hInstDLL; diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index d51b863..46b628f 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -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);