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);
74 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
75 IsEqualGUID( riid, &IID_IDispatch ) ||
76 IsEqualGUID( riid, &IID_IXMLDOMNodeList ) )
82 FIXME("interface %s not implemented\n", debugstr_guid(riid));
87 IXMLDOMNodeList_AddRef( iface );
92 static ULONG WINAPI xmlnodelist_AddRef(
93 IXMLDOMNodeList *iface )
95 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
96 return InterlockedIncrement( &This->ref );
99 static ULONG WINAPI xmlnodelist_Release(
100 IXMLDOMNodeList *iface )
102 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
105 ref = InterlockedDecrement( &This->ref );
108 xmldoc_release( This->parent->doc );
115 static HRESULT WINAPI xmlnodelist_GetTypeInfoCount(
116 IXMLDOMNodeList *iface,
119 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
121 TRACE("(%p)->(%p)\n", This, pctinfo);
128 static HRESULT WINAPI xmlnodelist_GetTypeInfo(
129 IXMLDOMNodeList *iface,
132 ITypeInfo** ppTInfo )
134 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
137 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
139 hr = get_typeinfo(IXMLDOMNodeList_tid, ppTInfo);
144 static HRESULT WINAPI xmlnodelist_GetIDsOfNames(
145 IXMLDOMNodeList *iface,
152 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
156 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
159 if(!rgszNames || cNames == 0 || !rgDispId)
162 hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
165 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
166 ITypeInfo_Release(typeinfo);
172 static HRESULT WINAPI xmlnodelist_Invoke(
173 IXMLDOMNodeList *iface,
178 DISPPARAMS* pDispParams,
180 EXCEPINFO* pExcepInfo,
183 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
187 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
188 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
190 hr = get_typeinfo(IXMLDOMNodeList_tid, &typeinfo);
193 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNodeList_iface, dispIdMember, wFlags,
194 pDispParams, pVarResult, pExcepInfo, puArgErr);
195 ITypeInfo_Release(typeinfo);
201 static HRESULT WINAPI xmlnodelist_get_item(
202 IXMLDOMNodeList* iface,
204 IXMLDOMNode** listItem)
206 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
210 TRACE("(%p)->(%d %p)\n", This, index, listItem);
220 curr = This->parent->children;
223 if(nodeIndex++ == index) break;
226 if(!curr) return S_FALSE;
228 *listItem = create_node( curr );
233 static HRESULT WINAPI xmlnodelist_get_length(
234 IXMLDOMNodeList* iface,
241 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
243 TRACE("(%p)->(%p)\n", This, listLength);
248 curr = This->parent->children;
255 *listLength = nodeCount;
259 static HRESULT WINAPI xmlnodelist_nextNode(
260 IXMLDOMNodeList* iface,
261 IXMLDOMNode** nextItem)
263 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
265 TRACE("(%p)->(%p)\n", This, nextItem );
275 *nextItem = create_node( This->current );
276 This->current = This->current->next;
280 static HRESULT WINAPI xmlnodelist_reset(
281 IXMLDOMNodeList* iface)
283 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
286 This->current = This->parent->children;
290 static HRESULT WINAPI xmlnodelist__newEnum(
291 IXMLDOMNodeList* iface,
294 xmlnodelist *This = impl_from_IXMLDOMNodeList( iface );
295 FIXME("(%p)->(%p)\n", This, ppUnk);
300 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl =
302 xmlnodelist_QueryInterface,
305 xmlnodelist_GetTypeInfoCount,
306 xmlnodelist_GetTypeInfo,
307 xmlnodelist_GetIDsOfNames,
309 xmlnodelist_get_item,
310 xmlnodelist_get_length,
311 xmlnodelist_nextNode,
313 xmlnodelist__newEnum,
316 IXMLDOMNodeList* create_children_nodelist( xmlNodePtr node )
318 xmlnodelist *nodelist;
320 nodelist = heap_alloc( sizeof *nodelist );
324 nodelist->IXMLDOMNodeList_iface.lpVtbl = &xmlnodelist_vtbl;
326 nodelist->parent = node;
327 nodelist->current = node->children;
329 xmldoc_add_ref( node->doc );
331 return &nodelist->IXMLDOMNodeList_iface;