Piotr Caban : msxml3: Skip the first XML declaration in file generated by domdoc_save.

Alexandre Julliard julliard at winehq.org
Wed Jul 9 06:10:27 CDT 2008


Module: wine
Branch: master
Commit: 616fd8206253f00fdff692e2d359ccba645e2649
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=616fd8206253f00fdff692e2d359ccba645e2649

Author: Piotr Caban <piotr.caban at gmail.com>
Date:   Tue Jul  8 20:57:35 2008 +0200

msxml3: Skip the first XML declaration in file generated by domdoc_save.

This is the last patch needed for Photoshop CS3 installer.

---

 dlls/msxml3/domdoc.c       |   20 ++++++++++++++++++--
 dlls/msxml3/tests/domdoc.c |    2 --
 2 files changed, 18 insertions(+), 4 deletions(-)

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 @@ static HRESULT WINAPI domdoc_save(
 {
     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 @@ static HRESULT WINAPI domdoc_save(
     }
 
     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 @@ static void test_DocumentSaveToFile(void)
 
     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");
 }




More information about the wine-cvs mailing list