msxml3: Use xmlNodeGetContent to get text data.

This commit is contained in:
Alistair Leslie-Hughes 2008-12-23 19:29:33 +11:00 committed by Alexandre Julliard
parent c6458f0fa6
commit 549befe706
2 changed files with 34 additions and 20 deletions

View File

@ -864,32 +864,18 @@ static HRESULT WINAPI xmlnode_get_text(
{
xmlnode *This = impl_from_IXMLDOMNode( iface );
BSTR str = NULL;
xmlChar *pContent;
TRACE("%p\n", This);
TRACE("%p type %d\n", This, This->node->type);
if ( !text )
return E_INVALIDARG;
switch(This->node->type)
pContent = xmlNodeGetContent((xmlNodePtr)This->node);
if(pContent)
{
case XML_ELEMENT_NODE:
case XML_ATTRIBUTE_NODE:
{
xmlNodePtr child = This->node->children;
if ( child && child->type == XML_TEXT_NODE )
str = bstr_from_xmlChar( child->content );
break;
}
case XML_TEXT_NODE:
case XML_CDATA_SECTION_NODE:
case XML_PI_NODE:
case XML_COMMENT_NODE:
str = bstr_from_xmlChar( This->node->content );
break;
default:
FIXME("Unhandled node type %d\n", This->node->type);
str = bstr_from_xmlChar(pContent);
xmlFree(pContent);
}
/* Always return a string. */

View File

@ -260,6 +260,20 @@ static BOOL compareIgnoreReturns(BSTR sLeft, BSTR sRight)
}
}
static BOOL compareIgnoreReturnsWhitespace(BSTR sLeft, BSTR sRight)
{
/* MSXML3 inserts whitespace where as libxml doesn't. */
for (;;)
{
while (*sLeft == '\r' || *sLeft == '\n' || *sLeft == ' ') sLeft++;
while (*sRight == '\r' || *sRight == '\n' || *sRight == ' ') sRight++;
if (*sLeft != *sRight) return FALSE;
if (!*sLeft) return TRUE;
sLeft++;
sRight++;
}
}
static void get_str_for_type(DOMNodeType type, char *buf)
{
switch (type)
@ -1706,6 +1720,7 @@ static void test_get_text(void)
VARIANT_BOOL b;
IXMLDOMDocument *doc;
IXMLDOMNode *node, *node2, *node3;
IXMLDOMNode *nodeRoot;
IXMLDOMNodeList *node_list;
IXMLDOMNamedNodeMap *node_map;
long len;
@ -1726,6 +1741,19 @@ static void test_get_text(void)
ok( r == S_OK, "ret %08x\n", r );
SysFreeString(str);
/* Test to get all child node text. */
r = IXMLDOMDocument_QueryInterface(doc, &IID_IXMLDOMNode, (LPVOID*)&nodeRoot);
ok( r == S_OK, "ret %08x\n", r );
if(r == S_OK)
{
r = IXMLDOMNode_get_text( nodeRoot, &str );
ok( r == S_OK, "ret %08x\n", r );
ok( compareIgnoreReturnsWhitespace(str, _bstr_("fn1.txt\n\n fn2.txt \n\nf1\n")), "wrong get_text\n");
SysFreeString(str);
IXMLDOMNode_Release(nodeRoot);
}
if (0) {
/* this test crashes on win9x */
r = IXMLDOMNodeList_QueryInterface(node_list, &IID_IDispatch, NULL);