msxml: implement indexed access to attributes,childNodes
Stefan Huehner
stefan at huehner.org
Thu Nov 3 05:09:42 CST 2005
Hi,
Changelog:
- adds indexed access to attributes (nodemap) and childNodes (nodelist). Some testcases for this are attached.
Mfg,
Stefan
-------------- next part --------------
? dlls/msxml3/2a28d54af65c42bbe78cc1552697c29e90dd6b6d.diff
? dlls/msxml3/msxml.diff
? dlls/msxml3/msxml1.diff
? dlls/msxml3/msxml2.diff
? dlls/msxml3/msxml3.diff
Index: dlls/msxml3/nodelist.c
===================================================================
RCS file: /home/wine/wine/dlls/msxml3/nodelist.c,v
retrieving revision 1.3
diff -u -p -r1.3 nodelist.c
--- dlls/msxml3/nodelist.c 31 Oct 2005 21:04:31 -0000 1.3
+++ dlls/msxml3/nodelist.c 3 Nov 2005 11:07:06 -0000
@@ -251,16 +251,56 @@ static HRESULT WINAPI xmlnodelist_get_it
long index,
IXMLDOMNode** listItem)
{
- FIXME("\n");
- return E_NOTIMPL;
+ xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
+ xmlNodePtr curr;
+ long nodeIndex = 0;
+
+ TRACE("%p %ld\n", This, index);
+
+ *listItem = NULL;
+
+ if (index < 0)
+ return S_FALSE;
+
+ curr = This->node;
+
+ for (nodeIndex = 0; nodeIndex < index; nodeIndex++) {
+ if (curr->next == NULL)
+ return S_FALSE;
+ else
+ curr = curr->next;
+ }
+
+ *listItem = create_node( curr );
+
+ return S_OK;
}
static HRESULT WINAPI xmlnodelist_get_length(
IXMLDOMNodeList* iface,
long* listLength)
{
- FIXME("\n");
- return E_NOTIMPL;
+
+ xmlNodePtr curr;
+ long nodeCount = 0;
+
+ xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
+
+ TRACE("%p\n", This);
+
+ if (This->node == NULL) {
+ *listLength = 0;
+ return S_OK;
+ }
+
+ curr = This->node;
+ nodeCount = 1;
+ while (curr->next != NULL) {
+ nodeCount++;
+ curr = curr->next;
+ }
+ *listLength = nodeCount;
+ return S_OK;
}
static HRESULT WINAPI xmlnodelist_nextNode(
Index: dlls/msxml3/nodemap.c
===================================================================
RCS file: /home/wine/wine/dlls/msxml3/nodemap.c,v
retrieving revision 1.6
diff -u -p -r1.6 nodemap.c
--- dlls/msxml3/nodemap.c 31 Oct 2005 21:04:31 -0000 1.6
+++ dlls/msxml3/nodemap.c 3 Nov 2005 11:07:06 -0000
@@ -196,16 +196,65 @@ static HRESULT WINAPI xmlnodemap_get_ite
long index,
IXMLDOMNode** listItem)
{
- FIXME("\n");
- return E_NOTIMPL;
+ xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
+ xmlNodePtr node;
+ xmlAttrPtr curr;
+ long attrIndex;
+
+ TRACE("%p %ld\n", This, index);
+
+ *listItem = NULL;
+
+ if (index < 0)
+ return S_FALSE;
+
+ node = xmlNodePtr_from_domnode( This->node, 0 );
+ curr = node->properties;
+
+ for (attrIndex = 0; attrIndex < index; attrIndex++) {
+ if (curr->next == NULL)
+ return S_FALSE;
+ else
+ curr = curr->next;
+ }
+
+ *listItem = create_node( (xmlNodePtr) curr );
+
+ return S_OK;
}
static HRESULT WINAPI xmlnodemap_get_length(
IXMLDOMNamedNodeMap *iface,
long* listLength)
{
- FIXME("\n");
- return E_NOTIMPL;
+ xmlNodePtr node;
+ xmlAttrPtr first;
+ xmlAttrPtr curr;
+ long attrCount;
+
+ xmlnodemap *This = impl_from_IXMLDOMNamedNodeMap( iface );
+
+ TRACE("%p\n", This);
+
+ node = xmlNodePtr_from_domnode( This->node, 0 );
+ if ( !node )
+ return E_FAIL;
+
+ first = node->properties;
+ if (first == NULL) {
+ *listLength = 0;
+ return S_OK;
+ }
+
+ curr = first;
+ attrCount = 1;
+ while (curr->next != NULL) {
+ attrCount++;
+ curr = curr->next;
+ }
+ *listLength = attrCount;
+
+ return S_OK;
}
static HRESULT WINAPI xmlnodemap_getQualifiedItem(
Index: dlls/msxml3/tests/domdoc.c
===================================================================
RCS file: /home/wine/wine/dlls/msxml3/tests/domdoc.c,v
retrieving revision 1.4
diff -u -p -r1.4 domdoc.c
--- dlls/msxml3/tests/domdoc.c 2 Nov 2005 19:55:30 -0000 1.4
+++ dlls/msxml3/tests/domdoc.c 3 Nov 2005 11:07:06 -0000
@@ -242,6 +242,7 @@ void test_domnode( void )
VARIANT_BOOL b;
BSTR str;
VARIANT var;
+ long count;
r = CoCreateInstance( &CLSID_DOMDocument, NULL,
CLSCTX_INPROC_SERVER, &IID_IXMLDOMDocument, (LPVOID*)&doc );
@@ -325,6 +326,38 @@ void test_domnode( void )
r = IXMLDOMNamedNodeMap_getNamedItem( map, str, &node );
ok( r == S_OK, "getNamedItem returned wrong code\n");
ok( node != NULL, "should be attributes\n");
+ SysFreeString( str );
+
+ /* test indexed access of attributes */
+ r = IXMLDOMNamedNodeMap_get_length( map, &count );
+ ok ( r == S_OK, "get_length wrong code\n");
+ ok ( count == 1, "get_length != 1\n");
+
+ node = NULL;
+ r = IXMLDOMNamedNodeMap_get_item( map, -1, &node);
+ ok ( r == S_FALSE, "get_item (-1) wrong code\n");
+ ok ( node == NULL, "there is no node\n");
+
+ node = NULL;
+ r = IXMLDOMNamedNodeMap_get_item( map, 1, &node);
+ ok ( r == S_FALSE, "get_item (1) wrong code\n");
+ ok ( node == NULL, "there is no attribute\n");
+
+ node = NULL;
+ r = IXMLDOMNamedNodeMap_get_item( map, 0, &node);
+ ok ( r == S_OK, "get_item (0) wrong code\n");
+ ok ( node != NULL, "should be attribute\n");
+
+ r = IXMLDOMNode_get_nodeName( node, NULL );
+ ok ( r == E_INVALIDARG, "get_nodeName (NULL) wrong code");
+
+ /* content doesn't matter here */
+ str = SysAllocString( szNonExistentFile );
+ r = IXMLDOMNode_get_nodeName( node, &str );
+ ok ( r == S_OK, "get_nodeName wrong code\n");
+ ok ( str != NULL, "str is null\n");
+ ok( !lstrcmpW( str, szdl ), "incorrect node name\n");
+ SysFreeString( str );
}
else
ok( FALSE, "no map\n");
More information about the wine-patches
mailing list