[PATCH 2/6] msxml3: ignore whitespace nodes

Adam Martinson amartinson at codeweavers.com
Mon Sep 27 19:29:04 CDT 2010


---
 dlls/msxml3/msxml_private.h |   15 +++++++++++++++
 dlls/msxml3/node.c          |    9 +++++++++
 dlls/msxml3/nodelist.c      |    8 ++++++--
 dlls/msxml3/tests/domdoc.c  |   14 ++++++++++++++
 4 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/dlls/msxml3/msxml_private.h b/dlls/msxml3/msxml_private.h
index a1b3b9d..a00e544 100644
--- a/dlls/msxml3/msxml_private.h
+++ b/dlls/msxml3/msxml_private.h
@@ -221,6 +221,21 @@ static inline HRESULT return_null_ptr(void **p)
     return S_FALSE;
 }
 
+static inline BOOL is_empty_node(const xmlNodePtr node)
+{
+    int i;
+    BOOL res = TRUE;
+    if (node)
+    {
+        if (node->type != XML_TEXT_NODE)
+            res = FALSE;
+        for (i = 0; res && node->content[i]; ++i)
+            if (!isspace(node->content[i]))
+                res = FALSE;
+    }
+    return res;
+}
+
 #endif
 
 void* libxslt_handle;
diff --git a/dlls/msxml3/node.c b/dlls/msxml3/node.c
index d466780..0514a63 100644
--- a/dlls/msxml3/node.c
+++ b/dlls/msxml3/node.c
@@ -270,6 +270,15 @@ static HRESULT get_node(
     if ( !out )
         return E_INVALIDARG;
 
+    if (node && is_empty_node(node))
+    {
+        if (lstrcmpA(name, "firstChild") == 0 ||
+            lstrcmpA(name, "next") == 0)
+            node = node->next;
+        else if (lstrcmpA(name, "lastChild") == 0 ||
+                 lstrcmpA(name, "previous") == 0)
+            node = node->prev;
+    }
     /* if we don't have a doc, use our parent. */
     if(node && !node->doc && node->parent)
         node->doc = node->parent->doc;
diff --git a/dlls/msxml3/nodelist.c b/dlls/msxml3/nodelist.c
index beda9e0..a9369e9 100644
--- a/dlls/msxml3/nodelist.c
+++ b/dlls/msxml3/nodelist.c
@@ -218,7 +218,7 @@ static HRESULT WINAPI xmlnodelist_get_item(
     curr = This->parent->children;
     while(curr)
     {
-        if(nodeIndex++ == index) break;
+        if(!is_empty_node(curr) && nodeIndex++ == index) break;
         curr = curr->next;
     }
     if(!curr) return S_FALSE;
@@ -246,7 +246,8 @@ static HRESULT WINAPI xmlnodelist_get_length(
     curr = This->parent->children;
     while (curr)
     {
-        nodeCount++;
+        if (!is_empty_node(curr))
+            nodeCount++;
         curr = curr->next;
     }
 
@@ -267,6 +268,9 @@ static HRESULT WINAPI xmlnodelist_nextNode(
 
     *nextItem = NULL;
 
+    if (This->current && is_empty_node(This->current))
+        This->current = This->current->next;
+
     if (!This->current)
         return S_FALSE;
 
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index fa357af..7423b78 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -377,6 +377,9 @@ static void get_str_for_type(DOMNodeType type, char *buf)
         case NODE_DOCUMENT:
             strcpy(buf, "D");
             break;
+        case NODE_TEXT:
+            strcpy(buf, "T");
+            break;
         default:
             wsprintfA(buf, "[%d]", type);
     }
@@ -3099,6 +3102,17 @@ static void test_XPath(void)
     ole_check(IXMLDOMNode_selectNodes(elem1Node, _bstr_("//*[name()='foo:c']"), &list));
     expect_list_and_release(list, "E3.E4.E2.D1");
 
+    /* check that whitespace nodes are ignored */
+    node = NULL;
+    ole_check(IXMLDOMNode_selectSingleNode(elem1Node, _bstr_("//*[name()='bar:x']/.."), &node));
+    ok(node != NULL, "failed to get node\n");
+    if (node)
+    {
+        ole_check(IXMLDOMNode_get_childNodes(node, &list));
+        expect_list_and_release(list, "T1.E1.E4.E1.E2.D1 E2.E1.E4.E1.E2.D1 E3.E1.E4.E1.E2.D1 T4.E1.E4.E1.E2.D1 E5.E1.E4.E1.E2.D1");
+        IXMLDOMNode_Release(node);
+    }
+
     /* it has to be declared in SelectionNamespaces */
     todo_wine ole_check(IXMLDOMDocument2_setProperty(doc, _bstr_("SelectionNamespaces"),
         _variantbstr_("xmlns:test='urn:uuid:86B2F87F-ACB6-45cd-8B77-9BDB92A01A29'")));
-- 
1.7.2.3


--------------020600090102020801060203--



More information about the wine-patches mailing list