msxml3: Skip the first XML declaration in file generated by domdoc_save. This is the last patch needed for Photoshop CS3 installer.
diff --git a/dlls/msxml3/domdoc.c b/dlls/msxml3/domdoc.c index 2b6b768..a2d7243 100644 --- a/dlls/msxml3/domdoc.c +++ b/dlls/msxml3/domdoc.c
@@ -1690,7 +1690,7 @@ { domdoc *This = impl_from_IXMLDOMDocument2( iface ); HANDLE handle; - xmlChar *mem; + xmlChar *mem, *p; int size; HRESULT ret = S_OK; DWORD written; @@ -1738,7 +1738,23 @@ } xmlDocDumpMemory(get_doc(This), &mem, &size); - if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size) + + /* + * libxml2 always adds XML declaration on top of the file and one for each processing instruction node in DOM tree. + * MSXML adds XML declaration only for processing instruction nodes. + * We skip the first XML declaration generated by libxml2 to get exactly what we need. + */ + p = mem; + if(size > 2 && p[0] == '<' && p[1] == '?') { + while(p < mem+size && (p[0] != '?' || p[1] != '>')) + p++; + p += 2; + while(p < mem+size && isspace(*p)) + p++; + size -= p-mem; + } + + if(!WriteFile(handle, p, (DWORD)size, &written, NULL) || written != (DWORD)size) { WARN("write error\n"); ret = S_FALSE;
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index 120ada5..08b8476 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c
@@ -3304,9 +3304,7 @@ ReadFile(file, buffer, sizeof(buffer), &read, NULL); ok(read != 0, "could not read file\n"); - todo_wine { ok(buffer[0] != '<' || buffer[1] != '?', "File contains processing instruction\n"); - } DeleteFile("test.xml"); }