2 * Node list implementation
4 * Copyright 2005 Mike McCormack
6 * iface 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 * iface 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #include "msxml_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
46 #ifdef HAVE_LIBXSLT_PATTERN_H
47 #include <libxslt/pattern.h>
49 #ifdef HAVE_LIBXSLT_TRANSFORM_H
50 #include <libxslt/transform.h>
54 xsltTransformContextPtr ctxt
;
55 xsltCompMatchPtr pattern
;
56 xsltStylesheetPtr sheet
;
59 static void xlst_info_init( struct xslt_info
*info
)
66 static int create_xslt_parser( struct xslt_info
*info
, xmlNodePtr node
, const xmlChar
*str
)
68 info
->sheet
= xsltNewStylesheet();
72 info
->ctxt
= xsltNewTransformContext( info
->sheet
, node
->doc
);
76 info
->pattern
= xsltCompilePattern( str
, node
->doc
,
77 node
, info
->sheet
, info
->ctxt
);
83 void free_xslt_info( struct xslt_info
*info
)
86 xsltFreeCompMatchList( info
->pattern
);
88 xsltFreeStylesheet( info
->sheet
);
90 xsltFreeTransformContext( info
->ctxt
);
93 static HRESULT
xslt_next_match( struct xslt_info
*info
, xmlNodePtr
*node
)
98 /* make sure that the current element matches the pattern */
103 r
= xsltTestCompMatchList( info
->ctxt
, *node
, info
->pattern
);
106 TRACE("Matched %p (%s)\n", *node
, (*node
)->name
);
111 ERR("Pattern match failed\n");
114 *node
= (*node
)->next
;
125 static void xlst_info_init( struct xslt_info
*info
)
129 void free_xslt_info( struct xslt_info
*info
)
133 static int create_xslt_parser( struct xslt_info
*info
, xmlNodePtr node
, const xmlChar
*str
)
135 MESSAGE("libxslt was missing at compile time\n");
139 static HRESULT
xslt_next_match( struct xslt_info
*info
, xmlNodePtr
*node
)
146 typedef struct _xmlnodelist
148 const struct IXMLDOMNodeListVtbl
*lpVtbl
;
152 struct xslt_info xinfo
;
155 static inline xmlnodelist
*impl_from_IXMLDOMNodeList( IXMLDOMNodeList
*iface
)
157 return (xmlnodelist
*)((char*)iface
- FIELD_OFFSET(xmlnodelist
, lpVtbl
));
160 static HRESULT WINAPI
xmlnodelist_QueryInterface(
161 IXMLDOMNodeList
*iface
,
165 TRACE("%p %p %p\n", iface
, debugstr_guid(riid
), ppvObject
);
167 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
168 IsEqualGUID( riid
, &IID_IDispatch
) ||
169 IsEqualGUID( riid
, &IID_IXMLDOMNodeList
) )
174 return E_NOINTERFACE
;
176 IXMLDOMNodeList_AddRef( iface
);
181 static ULONG WINAPI
xmlnodelist_AddRef(
182 IXMLDOMNodeList
*iface
)
184 xmlnodelist
*This
= impl_from_IXMLDOMNodeList( iface
);
185 return InterlockedIncrement( &This
->ref
);
188 static ULONG WINAPI
xmlnodelist_Release(
189 IXMLDOMNodeList
*iface
)
191 xmlnodelist
*This
= impl_from_IXMLDOMNodeList( iface
);
194 ref
= InterlockedDecrement( &This
->ref
);
197 free_xslt_info( &This
->xinfo
);
198 HeapFree( GetProcessHeap(), 0, This
);
204 static HRESULT WINAPI
xmlnodelist_GetTypeInfoCount(
205 IXMLDOMNodeList
*iface
,
212 static HRESULT WINAPI
xmlnodelist_GetTypeInfo(
213 IXMLDOMNodeList
*iface
,
216 ITypeInfo
** ppTInfo
)
222 static HRESULT WINAPI
xmlnodelist_GetIDsOfNames(
223 IXMLDOMNodeList
*iface
,
234 static HRESULT WINAPI
xmlnodelist_Invoke(
235 IXMLDOMNodeList
*iface
,
240 DISPPARAMS
* pDispParams
,
242 EXCEPINFO
* pExcepInfo
,
249 static HRESULT WINAPI
xmlnodelist_get_item(
250 IXMLDOMNodeList
* iface
,
252 IXMLDOMNode
** listItem
)
258 static HRESULT WINAPI
xmlnodelist_get_length(
259 IXMLDOMNodeList
* iface
,
266 static HRESULT WINAPI
xmlnodelist_nextNode(
267 IXMLDOMNodeList
* iface
,
268 IXMLDOMNode
** nextItem
)
270 xmlnodelist
*This
= impl_from_IXMLDOMNodeList( iface
);
273 TRACE("%p %p\n", This
, nextItem
);
275 r
= xslt_next_match( &This
->xinfo
, &This
->current
);
282 *nextItem
= create_node( This
->current
);
283 This
->current
= This
->current
->next
;
287 static HRESULT WINAPI
xmlnodelist_reset(
288 IXMLDOMNodeList
* iface
)
290 xmlnodelist
*This
= impl_from_IXMLDOMNodeList( iface
);
293 This
->current
= This
->node
;
297 static HRESULT WINAPI
xmlnodelist__newEnum(
298 IXMLDOMNodeList
* iface
,
306 static const struct IXMLDOMNodeListVtbl xmlnodelist_vtbl
=
308 xmlnodelist_QueryInterface
,
311 xmlnodelist_GetTypeInfoCount
,
312 xmlnodelist_GetTypeInfo
,
313 xmlnodelist_GetIDsOfNames
,
315 xmlnodelist_get_item
,
316 xmlnodelist_get_length
,
317 xmlnodelist_nextNode
,
319 xmlnodelist__newEnum
,
322 static xmlnodelist
*new_nodelist( xmlNodePtr node
)
324 xmlnodelist
*nodelist
;
326 nodelist
= HeapAlloc( GetProcessHeap(), 0, sizeof *nodelist
);
330 nodelist
->lpVtbl
= &xmlnodelist_vtbl
;
332 nodelist
->node
= node
;
333 nodelist
->current
= node
;
334 xlst_info_init( &nodelist
->xinfo
);
339 IXMLDOMNodeList
* create_nodelist( xmlNodePtr node
)
341 xmlnodelist
*nodelist
= new_nodelist( node
);
344 return (IXMLDOMNodeList
*) &nodelist
->lpVtbl
;
347 IXMLDOMNodeList
* create_filtered_nodelist( xmlNodePtr node
, const xmlChar
*str
)
349 xmlnodelist
*This
= new_nodelist( node
);
351 if (create_xslt_parser( &This
->xinfo
, node
, str
))
352 return (IXMLDOMNodeList
*) &This
->lpVtbl
;
354 IXMLDOMNodeList_Release( (IXMLDOMNodeList
*) &This
->lpVtbl
);