Daniel Lehman : msxml3: Treat namespaces as floating attributes.

Alexandre Julliard julliard at winehq.org
Mon Oct 22 15:38:43 CDT 2018


Module: wine
Branch: master
Commit: 4460cb3377a045de8cde82d846e8e0d3592d5252
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=4460cb3377a045de8cde82d846e8e0d3592d5252

Author: Daniel Lehman <dlehman25 at gmail.com>
Date:   Mon Oct 15 21:14:34 2018 -0700

msxml3: Treat namespaces as floating attributes.

Signed-off-by: Daniel Lehman <dlehman25 at gmail.com>
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msxml3/element.c      | 68 +++++++++++++++++++++++++++++++++++-----------
 dlls/msxml3/tests/domdoc.c |  2 +-
 2 files changed, 53 insertions(+), 17 deletions(-)

diff --git a/dlls/msxml3/element.c b/dlls/msxml3/element.c
index 4faeed4..0ff26e4 100644
--- a/dlls/msxml3/element.c
+++ b/dlls/msxml3/element.c
@@ -1754,8 +1754,11 @@ static HRESULT domelem_remove_named_item(xmlNodePtr node, BSTR name, IXMLDOMNode
 
 static HRESULT domelem_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode **item)
 {
+    xmlNsPtr ns, xmlns;
     xmlAttrPtr curr;
     LONG attrIndex;
+    IUnknown *unk;
+    HRESULT hr;
 
     TRACE("(%p)->(%d %p)\n", node, index, item);
 
@@ -1764,42 +1767,75 @@ static HRESULT domelem_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode *
     if (index < 0)
         return S_FALSE;
 
+    attrIndex = 0;
     curr = node->properties;
-
-    for (attrIndex = 0; attrIndex < index; attrIndex++) {
-        if (curr->next == NULL)
-            return S_FALSE;
-        else
+    if (curr) {
+        for (; attrIndex < index && curr->next != NULL; attrIndex++)
             curr = curr->next;
+
+        if (attrIndex == index) {
+            *item = create_node( (xmlNodePtr) curr );
+            return S_OK;
+        }
     }
 
-    *item = create_node( (xmlNodePtr) curr );
+    if (!node->nsDef)
+        return S_FALSE;
 
-    return S_OK;
+    attrIndex++;
+    ns = node->nsDef;
+    for (; attrIndex < index && ns->next != NULL; attrIndex++)
+        ns = ns->next;
+
+    if (attrIndex < index)
+        return S_FALSE;
+
+    xmlns = xmlNewNs(NULL, BAD_CAST "http://www.w3.org/2000/xmlns/", BAD_CAST "xmlns");
+    if (!xmlns)
+        return E_OUTOFMEMORY;
+
+    curr = xmlNewNsProp(NULL, xmlns, ns->prefix, ns->href);
+    if (!curr) {
+        xmlFreeNs(xmlns);
+        return E_OUTOFMEMORY;
+    }
+    curr->doc = node->doc;
+
+    unk = create_attribute((xmlNodePtr)curr, TRUE);
+    if (!unk) {
+        xmlFreeNs(xmlns);
+        xmlFreeProp(curr);
+        return E_OUTOFMEMORY;
+    }
+
+    hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMNode, (void**)item);
+    IUnknown_Release(unk);
+
+    return hr;
 }
 
 static HRESULT domelem_get_length(const xmlNodePtr node, LONG *length)
 {
-    xmlAttrPtr first;
     xmlAttrPtr curr;
     LONG attrCount;
+    xmlNsPtr ns;
 
     TRACE("(%p)->(%p)\n", node, length);
 
     if( !length )
         return E_INVALIDARG;
 
-    first = node->properties;
-    if (first == NULL) {
-	*length = 0;
-	return S_OK;
+    attrCount = 0;
+    curr = node->properties;
+    while (curr) {
+        attrCount++;
+        curr = curr->next;
     }
 
-    curr = first;
-    attrCount = 1;
-    while (curr->next) {
+    ns = node->nsDef;
+    while (ns) {
         attrCount++;
-        curr = curr->next;
+        ns = ns->next;
     }
     *length = attrCount;
 
diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c
index b7b29e3..7911876 100644
--- a/dlls/msxml3/tests/domdoc.c
+++ b/dlls/msxml3/tests/domdoc.c
@@ -12891,7 +12891,7 @@ static void test_namespaces_as_attributes(void)
         len = -1;
         hr = IXMLDOMNamedNodeMap_get_length(map, &len);
         ok(SUCCEEDED(hr), "Failed to get map length, hr %#x.\n", hr);
-        todo_wine ok(len == 3, "got %d\n", len);
+        ok(len == 3, "got %d\n", len);
 
         for (i = 0; i < len; i++)
         {




More information about the wine-cvs mailing list