Huw Davies : msxml3: Always have a libxml doc associated with a domdoc object, even if the object has no nodes.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jun 27 15:49:10 CDT 2006


Module: wine
Branch: refs/heads/master
Commit: 54c85d3d044127bfc946de75e53f9c7ac3acf8d3
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=54c85d3d044127bfc946de75e53f9c7ac3acf8d3

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Jun 27 10:54:40 2006 +0100

msxml3: Always have a libxml doc associated with a domdoc object, even if the object has no nodes.

This means we don't need to add checks for NULL libxml node ptrs in our node implementation.

---

 dlls/msxml3/domdoc.c       |   93 +++++++++++++++++++++++---------------------
 dlls/msxml3/tests/domdoc.c |    8 ++++
 2 files changed, 56 insertions(+), 45 deletions(-)

diff --git a/dlls/msxml3/domdoc.c b/dlls/msxml3/domdoc.c
index 39e4768..b837288 100644
--- a/dlls/msxml3/domdoc.c
+++ b/dlls/msxml3/domdoc.c
@@ -664,12 +664,7 @@ static HRESULT WINAPI domdoc_get_documen
 
     *DOMElement = NULL;
 
-    if ( !This->node )
-        return S_FALSE;
-
     xmldoc = get_doc( This );
-    if ( !xmldoc )
-        return S_FALSE;
 
     root = xmlDocGetRootElement( xmldoc );
     if ( !root )
@@ -811,7 +806,6 @@ static HRESULT WINAPI domdoc_createNode(
     DOMNodeType node_type;
     xmlNodePtr xmlnode = NULL;
     xmlChar *xml_name;
-    xmlDocPtr xmldoc;
 
     TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
 
@@ -820,13 +814,6 @@ static HRESULT WINAPI domdoc_createNode(
 
     xml_name = xmlChar_from_wchar((WCHAR*)name);
 
-    if(!get_doc(This))
-    {
-        xmldoc = xmlNewDoc(NULL);
-        xmldoc->_private = 0;
-        attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
-    }
-
     switch(node_type)
     {
     case NODE_ELEMENT:
@@ -959,7 +946,8 @@ static HRESULT WINAPI domdoc_load(
 {
     domdoc *This = impl_from_IXMLDOMDocument( iface );
     LPWSTR filename = NULL;
-    xmlDocPtr xmldoc;
+    xmlDocPtr xmldoc = NULL;
+    HRESULT hr = S_FALSE;
 
     TRACE("type %d\n", V_VT(&xmlSource) );
 
@@ -975,22 +963,26 @@ static HRESULT WINAPI domdoc_load(
         filename = V_BSTR(&xmlSource);
     }
 
-    if ( !filename )
-        return S_FALSE;
-
-    xmldoc = doread( filename );
-    if ( !xmldoc )
+    if ( filename )
     {
-        This->error = E_FAIL;
-        return S_FALSE;
+        xmldoc = doread( filename );
+    
+        if ( !xmldoc )
+            This->error = E_FAIL;
+        else
+        {
+            hr = This->error = S_OK;
+            *isSuccessful = VARIANT_TRUE;
+        }
     }
 
-    This->error = S_OK;
+    if(!xmldoc)
+        xmldoc = xmlNewDoc(NULL);
+
     xmldoc->_private = 0;
     attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
 
-    *isSuccessful = VARIANT_TRUE;
-    return S_OK;
+    return hr;
 }
 
 
@@ -1084,9 +1076,10 @@ static HRESULT WINAPI domdoc_loadXML(
     VARIANT_BOOL* isSuccessful )
 {
     domdoc *This = impl_from_IXMLDOMDocument( iface );
-    xmlDocPtr xmldoc;
+    xmlDocPtr xmldoc = NULL;
     char *str;
     int len;
+    HRESULT hr = S_FALSE;
 
     TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
 
@@ -1094,31 +1087,30 @@ static HRESULT WINAPI domdoc_loadXML(
 
     attach_xmlnode( This->node, NULL );
 
-    if ( !isSuccessful )
-        return S_FALSE;
-
-    *isSuccessful = VARIANT_FALSE;
-
-    if ( !bstrXML )
-        return S_FALSE;
-
-    if ( !bstr_to_utf8( bstrXML, &str, &len ) )
-        return S_FALSE;
-
-    xmldoc = doparse( str, len );
-    HeapFree( GetProcessHeap(), 0, str );
-    if ( !xmldoc )
+    if ( isSuccessful )
     {
-        This->error = E_FAIL;
-        return S_FALSE;
+        *isSuccessful = VARIANT_FALSE;
+
+        if ( bstrXML  && bstr_to_utf8( bstrXML, &str, &len ) )
+        {
+            xmldoc = doparse( str, len );
+            HeapFree( GetProcessHeap(), 0, str );
+            if ( !xmldoc )
+                This->error = E_FAIL;
+            else
+            {
+                hr = This->error = S_OK;
+                *isSuccessful = VARIANT_TRUE;
+            }
+        }
     }
+    if(!xmldoc)
+        xmldoc = xmlNewDoc(NULL);
 
-    This->error = S_OK;
     xmldoc->_private = 0;
     attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
 
-    *isSuccessful = VARIANT_TRUE;
-    return S_OK;
+    return hr;
 }
 
 
@@ -1325,6 +1317,7 @@ HRESULT DOMDocument_create(IUnknown *pUn
 {
     domdoc *doc;
     HRESULT hr;
+    xmlDocPtr xmldoc;
 
     TRACE("(%p,%p)\n", pUnkOuter, ppObj);
 
@@ -1337,9 +1330,19 @@ HRESULT DOMDocument_create(IUnknown *pUn
     doc->async = 0;
     doc->error = S_OK;
 
-    doc->node_unk = create_basic_node( NULL, (IUnknown*)&doc->lpVtbl );
+    xmldoc = xmlNewDoc(NULL);
+    if(!xmldoc)
+    {
+        HeapFree(GetProcessHeap(), 0, doc);
+        return E_OUTOFMEMORY;
+    }
+
+    xmldoc->_private = 0;
+
+    doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
     if(!doc->node_unk)
     {
+        xmlFreeDoc(xmldoc);
         HeapFree(GetProcessHeap(), 0, doc);
         return E_FAIL;
     }
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index 68f1d1b..808ad93 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -98,6 +98,7 @@ void test_domdoc( void )
     IXMLDOMDocument *doc = NULL;
     IXMLDOMParseError *error;
     IXMLDOMElement *element = NULL;
+    IXMLDOMNode *node;
     VARIANT_BOOL b;
     VARIANT var;
     BSTR str;
@@ -142,6 +143,13 @@ void test_domdoc( void )
     r = IXMLDOMDocument_get_documentElement( doc, &element );
     ok( r == S_FALSE, "should be no document element\n");
 
+    /* try finding a node */
+    node = NULL;
+    str = SysAllocString( szstr1 );
+    r = IXMLDOMDocument_selectSingleNode( doc, str, &node );
+    ok( r == S_FALSE, "ret %08lx\n", r );
+    SysFreeString( str );
+
     b = VARIANT_TRUE;
     str = SysAllocString( szIncomplete );
     r = IXMLDOMDocument_loadXML( doc, str, &b );




More information about the wine-cvs mailing list