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( ...@@ -664,12 +664,7 @@ static HRESULT WINAPI domdoc_get_documentElement(
*DOMElement = NULL; *DOMElement = NULL;
if ( !This->node )
return S_FALSE;
xmldoc = get_doc( This ); xmldoc = get_doc( This );
if ( !xmldoc )
return S_FALSE;
root = xmlDocGetRootElement( xmldoc ); root = xmlDocGetRootElement( xmldoc );
if ( !root ) if ( !root )
...@@ -811,7 +806,6 @@ static HRESULT WINAPI domdoc_createNode( ...@@ -811,7 +806,6 @@ static HRESULT WINAPI domdoc_createNode(
DOMNodeType node_type; DOMNodeType node_type;
xmlNodePtr xmlnode = NULL; xmlNodePtr xmlnode = NULL;
xmlChar *xml_name; xmlChar *xml_name;
xmlDocPtr xmldoc;
TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node); TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
...@@ -820,13 +814,6 @@ static HRESULT WINAPI domdoc_createNode( ...@@ -820,13 +814,6 @@ static HRESULT WINAPI domdoc_createNode(
xml_name = xmlChar_from_wchar((WCHAR*)name); 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) switch(node_type)
{ {
case NODE_ELEMENT: case NODE_ELEMENT:
...@@ -959,7 +946,8 @@ static HRESULT WINAPI domdoc_load( ...@@ -959,7 +946,8 @@ static HRESULT WINAPI domdoc_load(
{ {
domdoc *This = impl_from_IXMLDOMDocument( iface ); domdoc *This = impl_from_IXMLDOMDocument( iface );
LPWSTR filename = NULL; LPWSTR filename = NULL;
xmlDocPtr xmldoc; xmlDocPtr xmldoc = NULL;
HRESULT hr = S_FALSE;
TRACE("type %d\n", V_VT(&xmlSource) ); TRACE("type %d\n", V_VT(&xmlSource) );
...@@ -975,22 +963,26 @@ static HRESULT WINAPI domdoc_load( ...@@ -975,22 +963,26 @@ static HRESULT WINAPI domdoc_load(
filename = V_BSTR(&xmlSource); filename = V_BSTR(&xmlSource);
} }
if ( !filename ) if ( filename )
return S_FALSE;
xmldoc = doread( filename );
if ( !xmldoc )
{ {
This->error = E_FAIL; xmldoc = doread( filename );
return S_FALSE;
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; xmldoc->_private = 0;
attach_xmlnode(This->node, (xmlNodePtr) xmldoc); attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
*isSuccessful = VARIANT_TRUE; return hr;
return S_OK;
} }
...@@ -1084,9 +1076,10 @@ static HRESULT WINAPI domdoc_loadXML( ...@@ -1084,9 +1076,10 @@ static HRESULT WINAPI domdoc_loadXML(
VARIANT_BOOL* isSuccessful ) VARIANT_BOOL* isSuccessful )
{ {
domdoc *This = impl_from_IXMLDOMDocument( iface ); domdoc *This = impl_from_IXMLDOMDocument( iface );
xmlDocPtr xmldoc; xmlDocPtr xmldoc = NULL;
char *str; char *str;
int len; int len;
HRESULT hr = S_FALSE;
TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful ); TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
...@@ -1094,31 +1087,30 @@ static HRESULT WINAPI domdoc_loadXML( ...@@ -1094,31 +1087,30 @@ static HRESULT WINAPI domdoc_loadXML(
attach_xmlnode( This->node, NULL ); attach_xmlnode( This->node, NULL );
if ( !isSuccessful ) 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 )
{ {
This->error = E_FAIL; *isSuccessful = VARIANT_FALSE;
return S_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; xmldoc->_private = 0;
attach_xmlnode( This->node, (xmlNodePtr) xmldoc ); attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
*isSuccessful = VARIANT_TRUE; return hr;
return S_OK;
} }
...@@ -1325,6 +1317,7 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj) ...@@ -1325,6 +1317,7 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
{ {
domdoc *doc; domdoc *doc;
HRESULT hr; HRESULT hr;
xmlDocPtr xmldoc;
TRACE("(%p,%p)\n", pUnkOuter, ppObj); TRACE("(%p,%p)\n", pUnkOuter, ppObj);
...@@ -1337,9 +1330,19 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj) ...@@ -1337,9 +1330,19 @@ HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
doc->async = 0; doc->async = 0;
doc->error = S_OK; 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) if(!doc->node_unk)
{ {
xmlFreeDoc(xmldoc);
HeapFree(GetProcessHeap(), 0, doc); HeapFree(GetProcessHeap(), 0, doc);
return E_FAIL; return E_FAIL;
} }
......
...@@ -98,6 +98,7 @@ void test_domdoc( void ) ...@@ -98,6 +98,7 @@ void test_domdoc( void )
IXMLDOMDocument *doc = NULL; IXMLDOMDocument *doc = NULL;
IXMLDOMParseError *error; IXMLDOMParseError *error;
IXMLDOMElement *element = NULL; IXMLDOMElement *element = NULL;
IXMLDOMNode *node;
VARIANT_BOOL b; VARIANT_BOOL b;
VARIANT var; VARIANT var;
BSTR str; BSTR str;
...@@ -142,6 +143,13 @@ void test_domdoc( void ) ...@@ -142,6 +143,13 @@ void test_domdoc( void )
r = IXMLDOMDocument_get_documentElement( doc, &element ); r = IXMLDOMDocument_get_documentElement( doc, &element );
ok( r == S_FALSE, "should be no document element\n"); 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; b = VARIANT_TRUE;
str = SysAllocString( szIncomplete ); str = SysAllocString( szIncomplete );
r = IXMLDOMDocument_loadXML( doc, str, &b ); 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