Commit 54c85d3d authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

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.
parent 3c56550e
......@@ -664,12 +664,7 @@ static HRESULT WINAPI domdoc_get_documentElement(
*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 *pUnkOuter, LPVOID *ppObj)
{
domdoc *doc;
HRESULT hr;
xmlDocPtr xmldoc;
TRACE("(%p,%p)\n", pUnkOuter, ppObj);
......@@ -1337,9 +1330,19 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
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;
}
......
......@@ -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 );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment