2 * DOM processing instruction node implementation
4 * Copyright 2006 Huw Davies
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
32 #include "msxml_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
40 typedef struct _dom_pi
42 const struct IXMLDOMProcessingInstructionVtbl
*lpVtbl
;
48 static inline dom_pi
*impl_from_IXMLDOMProcessingInstruction( IXMLDOMProcessingInstruction
*iface
)
50 return (dom_pi
*)((char*)iface
- FIELD_OFFSET(dom_pi
, lpVtbl
));
53 static HRESULT WINAPI
dom_pi_QueryInterface(
54 IXMLDOMProcessingInstruction
*iface
,
58 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
59 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
61 if ( IsEqualGUID( riid
, &IID_IXMLDOMProcessingInstruction
) ||
62 IsEqualGUID( riid
, &IID_IDispatch
) ||
63 IsEqualGUID( riid
, &IID_IUnknown
) )
67 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
69 return IUnknown_QueryInterface(This
->node_unk
, riid
, ppvObject
);
73 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
77 IXMLDOMProcessingInstruction_AddRef( iface
);
82 static ULONG WINAPI
dom_pi_AddRef(
83 IXMLDOMProcessingInstruction
*iface
)
85 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
86 return InterlockedIncrement( &This
->ref
);
89 static ULONG WINAPI
dom_pi_Release(
90 IXMLDOMProcessingInstruction
*iface
)
92 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
95 ref
= InterlockedDecrement( &This
->ref
);
98 IUnknown_Release( This
->node_unk
);
99 HeapFree( GetProcessHeap(), 0, This
);
105 static HRESULT WINAPI
dom_pi_GetTypeInfoCount(
106 IXMLDOMProcessingInstruction
*iface
,
109 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
111 TRACE("(%p)->(%p)\n", This
, pctinfo
);
118 static HRESULT WINAPI
dom_pi_GetTypeInfo(
119 IXMLDOMProcessingInstruction
*iface
,
120 UINT iTInfo
, LCID lcid
,
121 ITypeInfo
** ppTInfo
)
123 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
126 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
128 hr
= get_typeinfo(IXMLDOMProcessingInstruction_tid
, ppTInfo
);
133 static HRESULT WINAPI
dom_pi_GetIDsOfNames(
134 IXMLDOMProcessingInstruction
*iface
,
135 REFIID riid
, LPOLESTR
* rgszNames
,
136 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
138 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
142 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
145 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
148 hr
= get_typeinfo(IXMLDOMProcessingInstruction_tid
, &typeinfo
);
151 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
152 ITypeInfo_Release(typeinfo
);
158 static HRESULT WINAPI
dom_pi_Invoke(
159 IXMLDOMProcessingInstruction
*iface
,
160 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
161 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
162 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
164 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
168 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
169 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
171 hr
= get_typeinfo(IXMLDOMProcessingInstruction_tid
, &typeinfo
);
174 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
175 pVarResult
, pExcepInfo
, puArgErr
);
176 ITypeInfo_Release(typeinfo
);
182 static HRESULT WINAPI
dom_pi_get_nodeName(
183 IXMLDOMProcessingInstruction
*iface
,
186 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
187 return IXMLDOMNode_get_nodeName( This
->node
, p
);
190 static HRESULT WINAPI
dom_pi_get_nodeValue(
191 IXMLDOMProcessingInstruction
*iface
,
194 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
195 return IXMLDOMNode_get_nodeValue( This
->node
, var1
);
198 static HRESULT WINAPI
dom_pi_put_nodeValue(
199 IXMLDOMProcessingInstruction
*iface
,
202 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
204 static const WCHAR szXML
[] = {'x','m','l',0};
207 TRACE("%p\n", This
);
209 /* Cannot set data to a PI node whose target is 'xml' */
210 hr
= dom_pi_get_nodeName(iface
, &sTarget
);
213 if(lstrcmpW( sTarget
, szXML
) == 0)
215 SysFreeString(sTarget
);
219 SysFreeString(sTarget
);
222 return IXMLDOMNode_put_nodeValue( This
->node
, var1
);
225 static HRESULT WINAPI
dom_pi_get_nodeType(
226 IXMLDOMProcessingInstruction
*iface
,
227 DOMNodeType
* domNodeType
)
229 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
230 return IXMLDOMNode_get_nodeType( This
->node
, domNodeType
);
233 static HRESULT WINAPI
dom_pi_get_parentNode(
234 IXMLDOMProcessingInstruction
*iface
,
235 IXMLDOMNode
** parent
)
237 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
238 return IXMLDOMNode_get_parentNode( This
->node
, parent
);
241 static HRESULT WINAPI
dom_pi_get_childNodes(
242 IXMLDOMProcessingInstruction
*iface
,
243 IXMLDOMNodeList
** outList
)
245 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
246 return IXMLDOMNode_get_childNodes( This
->node
, outList
);
249 static HRESULT WINAPI
dom_pi_get_firstChild(
250 IXMLDOMProcessingInstruction
*iface
,
251 IXMLDOMNode
** domNode
)
253 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
254 return IXMLDOMNode_get_firstChild( This
->node
, domNode
);
257 static HRESULT WINAPI
dom_pi_get_lastChild(
258 IXMLDOMProcessingInstruction
*iface
,
259 IXMLDOMNode
** domNode
)
261 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
262 return IXMLDOMNode_get_lastChild( This
->node
, domNode
);
265 static HRESULT WINAPI
dom_pi_get_previousSibling(
266 IXMLDOMProcessingInstruction
*iface
,
267 IXMLDOMNode
** domNode
)
269 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
270 return IXMLDOMNode_get_previousSibling( This
->node
, domNode
);
273 static HRESULT WINAPI
dom_pi_get_nextSibling(
274 IXMLDOMProcessingInstruction
*iface
,
275 IXMLDOMNode
** domNode
)
277 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
278 return IXMLDOMNode_get_nextSibling( This
->node
, domNode
);
281 static HRESULT WINAPI
dom_pi_get_attributes(
282 IXMLDOMProcessingInstruction
*iface
,
283 IXMLDOMNamedNodeMap
** attributeMap
)
285 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
286 return IXMLDOMNode_get_attributes( This
->node
, attributeMap
);
289 static HRESULT WINAPI
dom_pi_insertBefore(
290 IXMLDOMProcessingInstruction
*iface
,
291 IXMLDOMNode
* newNode
, VARIANT var1
,
292 IXMLDOMNode
** outOldNode
)
294 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
295 return IXMLDOMNode_insertBefore( This
->node
, newNode
, var1
, outOldNode
);
298 static HRESULT WINAPI
dom_pi_replaceChild(
299 IXMLDOMProcessingInstruction
*iface
,
300 IXMLDOMNode
* newNode
,
301 IXMLDOMNode
* oldNode
,
302 IXMLDOMNode
** outOldNode
)
304 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
305 return IXMLDOMNode_replaceChild( This
->node
, newNode
, oldNode
, outOldNode
);
308 static HRESULT WINAPI
dom_pi_removeChild(
309 IXMLDOMProcessingInstruction
*iface
,
310 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
312 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
313 return IXMLDOMNode_removeChild( This
->node
, domNode
, oldNode
);
316 static HRESULT WINAPI
dom_pi_appendChild(
317 IXMLDOMProcessingInstruction
*iface
,
318 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
320 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
321 return IXMLDOMNode_appendChild( This
->node
, newNode
, outNewNode
);
324 static HRESULT WINAPI
dom_pi_hasChildNodes(
325 IXMLDOMProcessingInstruction
*iface
,
328 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
329 return IXMLDOMNode_hasChildNodes( This
->node
, pbool
);
332 static HRESULT WINAPI
dom_pi_get_ownerDocument(
333 IXMLDOMProcessingInstruction
*iface
,
334 IXMLDOMDocument
** domDocument
)
336 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
337 return IXMLDOMNode_get_ownerDocument( This
->node
, domDocument
);
340 static HRESULT WINAPI
dom_pi_cloneNode(
341 IXMLDOMProcessingInstruction
*iface
,
342 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
344 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
345 return IXMLDOMNode_cloneNode( This
->node
, pbool
, outNode
);
348 static HRESULT WINAPI
dom_pi_get_nodeTypeString(
349 IXMLDOMProcessingInstruction
*iface
,
352 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
353 return IXMLDOMNode_get_nodeTypeString( This
->node
, p
);
356 static HRESULT WINAPI
dom_pi_get_text(
357 IXMLDOMProcessingInstruction
*iface
,
360 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
361 return IXMLDOMNode_get_text( This
->node
, p
);
364 static HRESULT WINAPI
dom_pi_put_text(
365 IXMLDOMProcessingInstruction
*iface
,
368 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
369 return IXMLDOMNode_put_text( This
->node
, p
);
372 static HRESULT WINAPI
dom_pi_get_specified(
373 IXMLDOMProcessingInstruction
*iface
,
376 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
377 return IXMLDOMNode_get_specified( This
->node
, pbool
);
380 static HRESULT WINAPI
dom_pi_get_definition(
381 IXMLDOMProcessingInstruction
*iface
,
382 IXMLDOMNode
** domNode
)
384 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
385 return IXMLDOMNode_get_definition( This
->node
, domNode
);
388 static HRESULT WINAPI
dom_pi_get_nodeTypedValue(
389 IXMLDOMProcessingInstruction
*iface
,
392 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
393 return IXMLDOMNode_get_nodeTypedValue( This
->node
, var1
);
396 static HRESULT WINAPI
dom_pi_put_nodeTypedValue(
397 IXMLDOMProcessingInstruction
*iface
,
400 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
401 return IXMLDOMNode_put_nodeTypedValue( This
->node
, var1
);
404 static HRESULT WINAPI
dom_pi_get_dataType(
405 IXMLDOMProcessingInstruction
*iface
,
408 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
409 return IXMLDOMNode_get_dataType( This
->node
, var1
);
412 static HRESULT WINAPI
dom_pi_put_dataType(
413 IXMLDOMProcessingInstruction
*iface
,
416 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
417 return IXMLDOMNode_put_dataType( This
->node
, p
);
420 static HRESULT WINAPI
dom_pi_get_xml(
421 IXMLDOMProcessingInstruction
*iface
,
424 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
425 return IXMLDOMNode_get_xml( This
->node
, p
);
428 static HRESULT WINAPI
dom_pi_transformNode(
429 IXMLDOMProcessingInstruction
*iface
,
430 IXMLDOMNode
* domNode
, BSTR
* p
)
432 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
433 return IXMLDOMNode_transformNode( This
->node
, domNode
, p
);
436 static HRESULT WINAPI
dom_pi_selectNodes(
437 IXMLDOMProcessingInstruction
*iface
,
438 BSTR p
, IXMLDOMNodeList
** outList
)
440 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
441 return IXMLDOMNode_selectNodes( This
->node
, p
, outList
);
444 static HRESULT WINAPI
dom_pi_selectSingleNode(
445 IXMLDOMProcessingInstruction
*iface
,
446 BSTR p
, IXMLDOMNode
** outNode
)
448 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
449 return IXMLDOMNode_selectSingleNode( This
->node
, p
, outNode
);
452 static HRESULT WINAPI
dom_pi_get_parsed(
453 IXMLDOMProcessingInstruction
*iface
,
456 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
457 return IXMLDOMNode_get_parsed( This
->node
, pbool
);
460 static HRESULT WINAPI
dom_pi_get_namespaceURI(
461 IXMLDOMProcessingInstruction
*iface
,
464 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
465 return IXMLDOMNode_get_namespaceURI( This
->node
, p
);
468 static HRESULT WINAPI
dom_pi_get_prefix(
469 IXMLDOMProcessingInstruction
*iface
,
472 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
473 return IXMLDOMNode_get_prefix( This
->node
, p
);
476 static HRESULT WINAPI
dom_pi_get_baseName(
477 IXMLDOMProcessingInstruction
*iface
,
480 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
481 return IXMLDOMNode_get_baseName( This
->node
, p
);
484 static HRESULT WINAPI
dom_pi_transformNodeToObject(
485 IXMLDOMProcessingInstruction
*iface
,
486 IXMLDOMNode
* domNode
, VARIANT var1
)
488 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
489 return IXMLDOMNode_transformNodeToObject( This
->node
, domNode
, var1
);
492 static HRESULT WINAPI
dom_pi_get_target(
493 IXMLDOMProcessingInstruction
*iface
,
496 /* target returns the same value as nodeName property */
497 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
498 return IXMLDOMNode_get_nodeName( This
->node
, p
);
501 static HRESULT WINAPI
dom_pi_get_data(
502 IXMLDOMProcessingInstruction
*iface
,
505 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
512 hr
= IXMLDOMNode_get_nodeValue( This
->node
, &vRet
);
521 static HRESULT WINAPI
dom_pi_put_data(
522 IXMLDOMProcessingInstruction
*iface
,
525 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
529 static const WCHAR szXML
[] = {'x','m','l',0};
531 TRACE("%p %s\n", This
, debugstr_w(data
) );
533 /* Cannot set data to a PI node whose target is 'xml' */
534 hr
= dom_pi_get_nodeName(iface
, &sTarget
);
537 if(lstrcmpW( sTarget
, szXML
) == 0)
539 SysFreeString(sTarget
);
543 SysFreeString(sTarget
);
546 V_VT(&val
) = VT_BSTR
;
549 hr
= IXMLDOMNode_put_nodeValue( This
->node
, val
);
554 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl
=
556 dom_pi_QueryInterface
,
559 dom_pi_GetTypeInfoCount
,
561 dom_pi_GetIDsOfNames
,
564 dom_pi_get_nodeValue
,
565 dom_pi_put_nodeValue
,
567 dom_pi_get_parentNode
,
568 dom_pi_get_childNodes
,
569 dom_pi_get_firstChild
,
570 dom_pi_get_lastChild
,
571 dom_pi_get_previousSibling
,
572 dom_pi_get_nextSibling
,
573 dom_pi_get_attributes
,
578 dom_pi_hasChildNodes
,
579 dom_pi_get_ownerDocument
,
581 dom_pi_get_nodeTypeString
,
584 dom_pi_get_specified
,
585 dom_pi_get_definition
,
586 dom_pi_get_nodeTypedValue
,
587 dom_pi_put_nodeTypedValue
,
591 dom_pi_transformNode
,
593 dom_pi_selectSingleNode
,
595 dom_pi_get_namespaceURI
,
598 dom_pi_transformNodeToObject
,
605 IUnknown
* create_pi( xmlNodePtr pi
)
610 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
614 This
->lpVtbl
= &dom_pi_vtbl
;
617 This
->node_unk
= create_basic_node( pi
, (IUnknown
*)&This
->lpVtbl
);
620 HeapFree(GetProcessHeap(), 0, This
);
624 hr
= IUnknown_QueryInterface(This
->node_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&This
->node
);
627 IUnknown_Release(This
->node_unk
);
628 HeapFree( GetProcessHeap(), 0, This
);
631 /* The ref on This->node is actually looped back into this object, so release it */
632 IXMLDOMNode_Release(This
->node
);
634 return (IUnknown
*) &This
->lpVtbl
;