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
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
45 typedef struct _dom_pi
48 IXMLDOMProcessingInstruction IXMLDOMProcessingInstruction_iface
;
52 static inline dom_pi
*impl_from_IXMLDOMProcessingInstruction( IXMLDOMProcessingInstruction
*iface
)
54 return CONTAINING_RECORD(iface
, dom_pi
, IXMLDOMProcessingInstruction_iface
);
57 static HRESULT WINAPI
dom_pi_QueryInterface(
58 IXMLDOMProcessingInstruction
*iface
,
62 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
63 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
65 if ( IsEqualGUID( riid
, &IID_IXMLDOMProcessingInstruction
) ||
66 IsEqualGUID( riid
, &IID_IXMLDOMNode
) ||
67 IsEqualGUID( riid
, &IID_IDispatch
) ||
68 IsEqualGUID( riid
, &IID_IUnknown
) )
72 else if(node_query_interface(&This
->node
, riid
, ppvObject
))
74 return *ppvObject
? S_OK
: E_NOINTERFACE
;
78 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
83 IUnknown_AddRef((IUnknown
*)*ppvObject
);
87 static ULONG WINAPI
dom_pi_AddRef(
88 IXMLDOMProcessingInstruction
*iface
)
90 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
91 ULONG ref
= InterlockedIncrement( &This
->ref
);
92 TRACE("(%p)->(%d)\n", This
, ref
);
96 static ULONG WINAPI
dom_pi_Release(
97 IXMLDOMProcessingInstruction
*iface
)
99 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
100 ULONG ref
= InterlockedDecrement( &This
->ref
);
102 TRACE("(%p)->(%d)\n", This
, ref
);
105 destroy_xmlnode(&This
->node
);
112 static HRESULT WINAPI
dom_pi_GetTypeInfoCount(
113 IXMLDOMProcessingInstruction
*iface
,
116 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
118 TRACE("(%p)->(%p)\n", This
, pctinfo
);
125 static HRESULT WINAPI
dom_pi_GetTypeInfo(
126 IXMLDOMProcessingInstruction
*iface
,
127 UINT iTInfo
, LCID lcid
,
128 ITypeInfo
** ppTInfo
)
130 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
133 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
135 hr
= get_typeinfo(IXMLDOMProcessingInstruction_tid
, ppTInfo
);
140 static HRESULT WINAPI
dom_pi_GetIDsOfNames(
141 IXMLDOMProcessingInstruction
*iface
,
142 REFIID riid
, LPOLESTR
* rgszNames
,
143 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
145 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
149 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
152 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
155 hr
= get_typeinfo(IXMLDOMProcessingInstruction_tid
, &typeinfo
);
158 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
159 ITypeInfo_Release(typeinfo
);
165 static HRESULT WINAPI
dom_pi_Invoke(
166 IXMLDOMProcessingInstruction
*iface
,
167 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
168 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
169 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
171 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
175 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
176 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
178 hr
= get_typeinfo(IXMLDOMProcessingInstruction_tid
, &typeinfo
);
181 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMProcessingInstruction_iface
, dispIdMember
,
182 wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
183 ITypeInfo_Release(typeinfo
);
189 static HRESULT WINAPI
dom_pi_get_nodeName(
190 IXMLDOMProcessingInstruction
*iface
,
193 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
195 TRACE("(%p)->(%p)\n", This
, p
);
197 return node_get_nodeName(&This
->node
, p
);
200 static HRESULT WINAPI
dom_pi_get_nodeValue(
201 IXMLDOMProcessingInstruction
*iface
,
204 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
206 TRACE("(%p)->(%p)\n", This
, value
);
208 return node_get_content(&This
->node
, value
);
211 static HRESULT WINAPI
dom_pi_put_nodeValue(
212 IXMLDOMProcessingInstruction
*iface
,
215 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
219 TRACE("(%p)->(%s)\n", This
, debugstr_variant(&value
));
221 /* Cannot set data to a PI node whose target is 'xml' */
222 hr
= dom_pi_get_nodeName(iface
, &sTarget
);
225 static const WCHAR xmlW
[] = {'x','m','l',0};
226 if(lstrcmpW( sTarget
, xmlW
) == 0)
228 SysFreeString(sTarget
);
232 SysFreeString(sTarget
);
235 return node_put_value(&This
->node
, &value
);
238 static HRESULT WINAPI
dom_pi_get_nodeType(
239 IXMLDOMProcessingInstruction
*iface
,
240 DOMNodeType
* domNodeType
)
242 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
244 TRACE("(%p)->(%p)\n", This
, domNodeType
);
246 *domNodeType
= NODE_PROCESSING_INSTRUCTION
;
250 static HRESULT WINAPI
dom_pi_get_parentNode(
251 IXMLDOMProcessingInstruction
*iface
,
252 IXMLDOMNode
** parent
)
254 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
256 TRACE("(%p)->(%p)\n", This
, parent
);
258 return node_get_parent(&This
->node
, parent
);
261 static HRESULT WINAPI
dom_pi_get_childNodes(
262 IXMLDOMProcessingInstruction
*iface
,
263 IXMLDOMNodeList
** outList
)
265 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
267 TRACE("(%p)->(%p)\n", This
, outList
);
269 return node_get_child_nodes(&This
->node
, outList
);
272 static HRESULT WINAPI
dom_pi_get_firstChild(
273 IXMLDOMProcessingInstruction
*iface
,
274 IXMLDOMNode
** domNode
)
276 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
278 TRACE("(%p)->(%p)\n", This
, domNode
);
280 return return_null_node(domNode
);
283 static HRESULT WINAPI
dom_pi_get_lastChild(
284 IXMLDOMProcessingInstruction
*iface
,
285 IXMLDOMNode
** domNode
)
287 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
289 TRACE("(%p)->(%p)\n", This
, domNode
);
291 return return_null_node(domNode
);
294 static HRESULT WINAPI
dom_pi_get_previousSibling(
295 IXMLDOMProcessingInstruction
*iface
,
296 IXMLDOMNode
** domNode
)
298 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
300 TRACE("(%p)->(%p)\n", This
, domNode
);
302 return node_get_previous_sibling(&This
->node
, domNode
);
305 static HRESULT WINAPI
dom_pi_get_nextSibling(
306 IXMLDOMProcessingInstruction
*iface
,
307 IXMLDOMNode
** domNode
)
309 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
311 TRACE("(%p)->(%p)\n", This
, domNode
);
313 return node_get_next_sibling(&This
->node
, domNode
);
316 static HRESULT WINAPI
dom_pi_get_attributes(
317 IXMLDOMProcessingInstruction
*iface
,
318 IXMLDOMNamedNodeMap
** map
)
320 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
321 static const WCHAR xmlW
[] = {'x','m','l',0};
325 TRACE("(%p)->(%p)\n", This
, map
);
327 if (!map
) return E_INVALIDARG
;
331 hr
= node_get_nodeName(&This
->node
, &name
);
332 if (hr
!= S_OK
) return hr
;
334 if (!strcmpW(name
, xmlW
))
336 FIXME("not implemented for <?xml..?> declaration\n");
346 static HRESULT WINAPI
dom_pi_insertBefore(
347 IXMLDOMProcessingInstruction
*iface
,
348 IXMLDOMNode
* newNode
, VARIANT refChild
,
349 IXMLDOMNode
** outOldNode
)
351 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
353 FIXME("(%p)->(%p %s %p) needs test\n", This
, newNode
, debugstr_variant(&refChild
), outOldNode
);
355 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
358 static HRESULT WINAPI
dom_pi_replaceChild(
359 IXMLDOMProcessingInstruction
*iface
,
360 IXMLDOMNode
* newNode
,
361 IXMLDOMNode
* oldNode
,
362 IXMLDOMNode
** outOldNode
)
364 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
366 FIXME("(%p)->(%p %p %p) needs test\n", This
, newNode
, oldNode
, outOldNode
);
368 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
371 static HRESULT WINAPI
dom_pi_removeChild(
372 IXMLDOMProcessingInstruction
*iface
,
373 IXMLDOMNode
*child
, IXMLDOMNode
**oldChild
)
375 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
376 TRACE("(%p)->(%p %p)\n", This
, child
, oldChild
);
377 return node_remove_child(&This
->node
, child
, oldChild
);
380 static HRESULT WINAPI
dom_pi_appendChild(
381 IXMLDOMProcessingInstruction
*iface
,
382 IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
384 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
385 TRACE("(%p)->(%p %p)\n", This
, child
, outChild
);
386 return node_append_child(&This
->node
, child
, outChild
);
389 static HRESULT WINAPI
dom_pi_hasChildNodes(
390 IXMLDOMProcessingInstruction
*iface
,
393 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
394 TRACE("(%p)->(%p)\n", This
, ret
);
395 return node_has_childnodes(&This
->node
, ret
);
398 static HRESULT WINAPI
dom_pi_get_ownerDocument(
399 IXMLDOMProcessingInstruction
*iface
,
400 IXMLDOMDocument
**doc
)
402 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
403 TRACE("(%p)->(%p)\n", This
, doc
);
404 return node_get_owner_doc(&This
->node
, doc
);
407 static HRESULT WINAPI
dom_pi_cloneNode(
408 IXMLDOMProcessingInstruction
*iface
,
409 VARIANT_BOOL deep
, IXMLDOMNode
** outNode
)
411 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
412 TRACE("(%p)->(%d %p)\n", This
, deep
, outNode
);
413 return node_clone( &This
->node
, deep
, outNode
);
416 static HRESULT WINAPI
dom_pi_get_nodeTypeString(
417 IXMLDOMProcessingInstruction
*iface
,
420 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
421 static const WCHAR processinginstructionW
[] =
422 {'p','r','o','c','e','s','s','i','n','g','i','n','s','t','r','u','c','t','i','o','n',0};
424 TRACE("(%p)->(%p)\n", This
, p
);
426 return return_bstr(processinginstructionW
, p
);
429 static HRESULT WINAPI
dom_pi_get_text(
430 IXMLDOMProcessingInstruction
*iface
,
433 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
434 TRACE("(%p)->(%p)\n", This
, p
);
435 return node_get_text(&This
->node
, p
);
438 static HRESULT WINAPI
dom_pi_put_text(
439 IXMLDOMProcessingInstruction
*iface
,
442 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
443 TRACE("(%p)->(%s)\n", This
, debugstr_w(p
));
444 return node_put_text( &This
->node
, p
);
447 static HRESULT WINAPI
dom_pi_get_specified(
448 IXMLDOMProcessingInstruction
*iface
,
449 VARIANT_BOOL
* isSpecified
)
451 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
452 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
453 *isSpecified
= VARIANT_TRUE
;
457 static HRESULT WINAPI
dom_pi_get_definition(
458 IXMLDOMProcessingInstruction
*iface
,
459 IXMLDOMNode
** definitionNode
)
461 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
462 FIXME("(%p)->(%p)\n", This
, definitionNode
);
466 static HRESULT WINAPI
dom_pi_get_nodeTypedValue(
467 IXMLDOMProcessingInstruction
*iface
,
470 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
471 TRACE("(%p)->(%p)\n", This
, v
);
472 return node_get_content(&This
->node
, v
);
475 static HRESULT WINAPI
dom_pi_put_nodeTypedValue(
476 IXMLDOMProcessingInstruction
*iface
,
479 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
480 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
484 static HRESULT WINAPI
dom_pi_get_dataType(
485 IXMLDOMProcessingInstruction
*iface
,
488 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
489 TRACE("(%p)->(%p)\n", This
, typename
);
490 return return_null_var( typename
);
493 static HRESULT WINAPI
dom_pi_put_dataType(
494 IXMLDOMProcessingInstruction
*iface
,
497 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
499 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
507 static HRESULT WINAPI
dom_pi_get_xml(
508 IXMLDOMProcessingInstruction
*iface
,
511 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
513 TRACE("(%p)->(%p)\n", This
, p
);
515 return node_get_xml(&This
->node
, FALSE
, FALSE
, p
);
518 static HRESULT WINAPI
dom_pi_transformNode(
519 IXMLDOMProcessingInstruction
*iface
,
520 IXMLDOMNode
*node
, BSTR
*p
)
522 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
523 TRACE("(%p)->(%p %p)\n", This
, node
, p
);
524 return node_transform_node(&This
->node
, node
, p
);
527 static HRESULT WINAPI
dom_pi_selectNodes(
528 IXMLDOMProcessingInstruction
*iface
,
529 BSTR p
, IXMLDOMNodeList
** outList
)
531 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
532 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outList
);
533 return node_select_nodes(&This
->node
, p
, outList
);
536 static HRESULT WINAPI
dom_pi_selectSingleNode(
537 IXMLDOMProcessingInstruction
*iface
,
538 BSTR p
, IXMLDOMNode
** outNode
)
540 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
541 TRACE("(%p)->(%s %p)\n", This
, debugstr_w(p
), outNode
);
542 return node_select_singlenode(&This
->node
, p
, outNode
);
545 static HRESULT WINAPI
dom_pi_get_parsed(
546 IXMLDOMProcessingInstruction
*iface
,
547 VARIANT_BOOL
* isParsed
)
549 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
550 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
551 *isParsed
= VARIANT_TRUE
;
555 static HRESULT WINAPI
dom_pi_get_namespaceURI(
556 IXMLDOMProcessingInstruction
*iface
,
559 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
560 TRACE("(%p)->(%p)\n", This
, p
);
561 return node_get_namespaceURI(&This
->node
, p
);
564 static HRESULT WINAPI
dom_pi_get_prefix(
565 IXMLDOMProcessingInstruction
*iface
,
568 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
569 TRACE("(%p)->(%p)\n", This
, prefix
);
570 return return_null_bstr( prefix
);
573 static HRESULT WINAPI
dom_pi_get_baseName(
574 IXMLDOMProcessingInstruction
*iface
,
577 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
578 TRACE("(%p)->(%p)\n", This
, name
);
579 return node_get_base_name( &This
->node
, name
);
582 static HRESULT WINAPI
dom_pi_transformNodeToObject(
583 IXMLDOMProcessingInstruction
*iface
,
584 IXMLDOMNode
* domNode
, VARIANT var1
)
586 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
587 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
591 static HRESULT WINAPI
dom_pi_get_target(
592 IXMLDOMProcessingInstruction
*iface
,
595 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
597 TRACE("(%p)->(%p)\n", This
, p
);
599 /* target returns the same value as nodeName property */
600 return node_get_nodeName(&This
->node
, p
);
603 static HRESULT WINAPI
dom_pi_get_data(
604 IXMLDOMProcessingInstruction
*iface
,
607 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
611 TRACE("(%p)->(%p)\n", This
, p
);
616 hr
= IXMLDOMProcessingInstruction_get_nodeValue( iface
, &ret
);
625 static HRESULT WINAPI
dom_pi_put_data(
626 IXMLDOMProcessingInstruction
*iface
,
629 dom_pi
*This
= impl_from_IXMLDOMProcessingInstruction( iface
);
634 TRACE("(%p)->(%s)\n", This
, debugstr_w(data
) );
636 /* Cannot set data to a PI node whose target is 'xml' */
637 hr
= dom_pi_get_nodeName(iface
, &sTarget
);
640 static const WCHAR xmlW
[] = {'x','m','l',0};
641 if(lstrcmpW( sTarget
, xmlW
) == 0)
643 SysFreeString(sTarget
);
647 SysFreeString(sTarget
);
650 V_VT(&val
) = VT_BSTR
;
653 return IXMLDOMProcessingInstruction_put_nodeValue( iface
, val
);
656 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl
=
658 dom_pi_QueryInterface
,
661 dom_pi_GetTypeInfoCount
,
663 dom_pi_GetIDsOfNames
,
666 dom_pi_get_nodeValue
,
667 dom_pi_put_nodeValue
,
669 dom_pi_get_parentNode
,
670 dom_pi_get_childNodes
,
671 dom_pi_get_firstChild
,
672 dom_pi_get_lastChild
,
673 dom_pi_get_previousSibling
,
674 dom_pi_get_nextSibling
,
675 dom_pi_get_attributes
,
680 dom_pi_hasChildNodes
,
681 dom_pi_get_ownerDocument
,
683 dom_pi_get_nodeTypeString
,
686 dom_pi_get_specified
,
687 dom_pi_get_definition
,
688 dom_pi_get_nodeTypedValue
,
689 dom_pi_put_nodeTypedValue
,
693 dom_pi_transformNode
,
695 dom_pi_selectSingleNode
,
697 dom_pi_get_namespaceURI
,
700 dom_pi_transformNodeToObject
,
707 IUnknown
* create_pi( xmlNodePtr pi
)
711 This
= heap_alloc( sizeof *This
);
715 This
->IXMLDOMProcessingInstruction_iface
.lpVtbl
= &dom_pi_vtbl
;
718 init_xmlnode(&This
->node
, pi
, (IXMLDOMNode
*)&This
->IXMLDOMProcessingInstruction_iface
, NULL
);
720 return (IUnknown
*)&This
->IXMLDOMProcessingInstruction_iface
;