From: Alistair Leslie-Hughes leslie_alistair@hotmail.com
The basic loop correctly finds the first element, however the second element repeats the first node, since it was incremented and the ns->next was skipped over. --- dlls/msxml3/element.c | 10 ++++++-- dlls/msxml3/tests/domdoc.c | 52 +++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/dlls/msxml3/element.c b/dlls/msxml3/element.c index 394a4b28201..72d6f1b1223 100644 --- a/dlls/msxml3/element.c +++ b/dlls/msxml3/element.c @@ -1819,10 +1819,16 @@ static HRESULT domelem_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode * if (!node->nsDef) return S_FALSE;
- attrIndex++; ns = node->nsDef; - for (; attrIndex < index && ns->next != NULL; attrIndex++) + while (attrIndex < index) + { + attrIndex++; + + if (!ns->next) + break; + ns = ns->next; + }
if (attrIndex < index) return S_FALSE; diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index 81f1235cd9b..76f0c827c2a 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -10196,6 +10196,13 @@ static const get_attributes_t get_attributes[] = {
static void test_get_attributes(void) { + const WCHAR *namespaces[] = + { + L"xmlns:oslc_am", + L"xmlns:rdf", + L"xmlns:dcterms", + L"xmlns:foaf" + }; const get_attributes_t *entry = get_attributes; IXMLDOMNamedNodeMap *map; IXMLDOMDocument *doc, *doc2; @@ -10205,7 +10212,7 @@ static void test_get_attributes(void) HRESULT hr; VARIANT v; BSTR str; - LONG length; + LONG length, i;
doc = create_document(&IID_IXMLDOMDocument);
@@ -10434,6 +10441,49 @@ static void test_get_attributes(void) }
IXMLDOMDocument_Release(doc); + + str = SysAllocString(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + L"<rdf:RDF xmlns:oslc_am="http://open-services.net/ns/am#%5C"" + L" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#%5C"" + L" xmlns:dcterms="http://purl.org/dc/terms/%5C"" + L" xmlns:foaf="http://xmlns.com/foaf/0.1/%5C" >" + L"</rdf:RDF>"); + + doc = create_document(&IID_IXMLDOMDocument2); + + hr = IXMLDOMDocument_loadXML(doc, str, &b); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(b == VARIANT_TRUE, "got %d\n", b); + + hr = IXMLDOMDocument_get_documentElement(doc, &elem); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + hr = IXMLDOMElement_get_attributes(elem, &map); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + + length = -1; + hr = IXMLDOMNamedNodeMap_get_length(map, &length); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(length == 4, "length %#lx.\n", length); + + for(i=0; i < length; i++) + { + hr = IXMLDOMNamedNodeMap_get_item(map, i, &node2); + ok( hr == S_OK, "Unexpected hr %#lx (%ld).\n", hr, i); + + hr = IXMLDOMNode_get_nodeName(node2, &str); + ok(hr == S_OK, "Unexpected hr %#lx.\n", hr); + ok(!lstrcmpW(str, namespaces[i]), "got %s\n", wine_dbgstr_w(str)); + SysFreeString(str); + + IXMLDOMNode_Release(node2); + } + + IXMLDOMNamedNodeMap_Release(map); + IXMLDOMElement_Release(elem); + + IXMLDOMDocument_Release(doc); + free_bstrs(); }