2 * Node list implementation
4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 /* This file implements the object returned by childNodes property. Note that this is
42 * not the IXMLDOMNodeList returned by XPath querites - it's implemented in queryresult.c.
43 * They are different because the list returned by childNodes:
44 * - is "live" - changes to the XML tree are automatically reflected in the list
45 * - doesn't supports IXMLDOMSelection
46 * - note that an attribute node have a text child in DOM but not in the XPath data model
47 * thus the child is inaccessible by an XPath query
50 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
54 typedef struct _xmlnodelist
56 IXMLDOMNodeList IXMLDOMNodeList_iface;
62 static inline xmlnodelist *impl_from_IXMLDOMNodeList( IXMLDOMNodeList *iface )
64 return CONTAINING_RECORD(iface, xmlnodelist, IXMLDOMNodeList_iface);
67 static HRESULT WINAPI xmlnodelist_QueryInterface(
68 IXMLDOMNodeList *iface,
72 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
77 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
78 IsEqualGUID( riid, &IID_IDispatch ) ||
79 IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
85 FIXME("interface %s not implemented\n", debugstr_guid(riid));
90 IXMLDOMNodeList_AddRef( iface );
95 static ULONG WINAPI xmlnodelist_AddRef(
96 IXMLDOMNodeList *iface )
98 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
99 return InterlockedIncrement( &This->ref );
102 static ULONG WINAPI xmlnodelist_Release(
103 IXMLDOMNodeList *iface )
105 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
108 ref = InterlockedDecrement( &This->ref );
111 xmldoc_release( This->parent->doc );
118 static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(
119 IXMLDOMNodeList *iface,
122 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
124 TRACE("(%p)->(%p)\n", This, pctinfo);
131 static HRESULT WINAPI xmlnodelist_GetTypeInfo(
132 IXMLDOMNodeList *iface,
135 ITypeInfo** ppTInfo )
137 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
140 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
142 hr = get_typeinfo(IXMLDOMNodeList_tid, ppTInfo);
147 static HRESULT WINAPI xmlnodelist_GetIDsOfNames(
148 IXMLDOMNodeList *iface,
155 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
159 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
162 if(!rgszNames || cNames == 0 || !rgDispId)
165 hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
168 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
169 ITypeInfo_Release(typeinfo);
175 static HRESULT WINAPI xmlnodelist_Invoke(
176 IXMLDOMNodeList *iface,
181 DISPPARAMS* pDispParams,
183 EXCEPINFO* pExcepInfo,
186 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
190 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
191 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
193 hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
196 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNodeList_iface, dispIdMember, wFlags,
197 pDispParams, pVarResult, pExcepInfo, puArgErr);
198 ITypeInfo_Release(typeinfo);
204 static HRESULT WINAPI xmlnodelist_get_item(
205 IXMLDOMNodeList* iface,
207 IXMLDOMNode** listItem)
209 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
213 TRACE("(%p)->(%d %p)\n", This, index, listItem);
223 curr = This->parent->children;
226 if(nodeIndex++ == index) break;
229 if(!curr) return S_FALSE;
231 *listItem = create_node( curr );
236 static HRESULT WINAPI xmlnodelist_get_length(
237 IXMLDOMNodeList* iface,
244 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
246 TRACE("(%p)->(%p)\n", This, listLength);
251 curr = This->parent->children;
258 *listLength = nodeCount;
262 static HRESULT WINAPI xmlnodelist_nextNode(
263 IXMLDOMNodeList* iface,
264 IXMLDOMNode** nextItem)
266 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
268 TRACE("(%p)->(%p)\n", This, nextItem );
278 *nextItem = create_node( This->current );
279 This->current = This->current->next;
283 static HRESULT WINAPI xmlnodelist_reset(
284 IXMLDOMNodeList* iface)
286 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
289 This->current = This->parent->children;
293 static HRESULT WINAPI xmlnodelist__newEnum(
294 IXMLDOMNodeList* iface,
297 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
298 FIXME("(%p)->(%p)\n", This, ppUnk);
303 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
305 xmlnodelist_QueryInterface,
308 xmlnodelist_GetTypeInfoCount,
309 xmlnodelist_GetTypeInfo,
310 xmlnodelist_GetIDsOfNames,
312 xmlnodelist_get_item,
313 xmlnodelist_get_length,
314 xmlnodelist_nextNode,
316 xmlnodelist__newEnum,
319 IXMLDOMNodeList* create_children_nodelist( xmlNodePtr node )
321 xmlnodelist *nodelist;
323 nodelist = heap_alloc( sizeof *nodelist );
327 nodelist->IXMLDOMNodeList_iface.lpVtbl = &xmlnodelist_vtbl;
329 nodelist->parent = node;
330 nodelist->current = node->children;
332 xmldoc_add_ref( node->doc );
334 return &nodelist->IXMLDOMNodeList_iface;