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 const struct nodemap_funcs dom_pi_attr_map;
54 static inline dom_pi *impl_from_IXMLDOMProcessingInstruction( IXMLDOMProcessingInstruction *iface )
56 return CONTAINING_RECORD(iface, dom_pi, IXMLDOMProcessingInstruction_iface);
59 static HRESULT WINAPI dom_pi_QueryInterface(
60 IXMLDOMProcessingInstruction *iface,
64 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
65 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
67 if ( IsEqualGUID( riid, &IID_IXMLDOMProcessingInstruction ) ||
68 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
69 IsEqualGUID( riid, &IID_IDispatch ) ||
70 IsEqualGUID( riid, &IID_IUnknown ) )
74 else if(node_query_interface(&This->node, riid, ppvObject))
76 return *ppvObject ? S_OK : E_NOINTERFACE;
80 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
85 IUnknown_AddRef((IUnknown*)*ppvObject);
89 static ULONG WINAPI dom_pi_AddRef(
90 IXMLDOMProcessingInstruction *iface )
92 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
93 ULONG ref = InterlockedIncrement( &This->ref );
94 TRACE("(%p)->(%d)\n", This, ref);
98 static ULONG WINAPI dom_pi_Release(
99 IXMLDOMProcessingInstruction *iface )
101 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
102 ULONG ref = InterlockedDecrement( &This->ref );
104 TRACE("(%p)->(%d)\n", This, ref);
107 destroy_xmlnode(&This->node);
114 static HRESULT WINAPI dom_pi_GetTypeInfoCount(
115 IXMLDOMProcessingInstruction *iface,
118 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
120 TRACE("(%p)->(%p)\n", This, pctinfo);
127 static HRESULT WINAPI dom_pi_GetTypeInfo(
128 IXMLDOMProcessingInstruction *iface,
129 UINT iTInfo, LCID lcid,
130 ITypeInfo** ppTInfo )
132 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
134 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
136 return get_typeinfo(IXMLDOMProcessingInstruction_tid, ppTInfo);
139 static HRESULT WINAPI dom_pi_GetIDsOfNames(
140 IXMLDOMProcessingInstruction *iface,
141 REFIID riid, LPOLESTR* rgszNames,
142 UINT cNames, LCID lcid, DISPID* rgDispId )
144 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
148 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
151 if(!rgszNames || cNames == 0 || !rgDispId)
154 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
157 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
158 ITypeInfo_Release(typeinfo);
164 static HRESULT WINAPI dom_pi_Invoke(
165 IXMLDOMProcessingInstruction *iface,
166 DISPID dispIdMember, REFIID riid, LCID lcid,
167 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
168 EXCEPINFO* pExcepInfo, UINT* puArgErr )
170 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
174 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
175 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
177 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
180 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMProcessingInstruction_iface, dispIdMember,
181 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
182 ITypeInfo_Release(typeinfo);
188 static HRESULT WINAPI dom_pi_get_nodeName(
189 IXMLDOMProcessingInstruction *iface,
192 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
194 TRACE("(%p)->(%p)\n", This, p);
196 return node_get_nodeName(&This->node, p);
199 static HRESULT WINAPI dom_pi_get_nodeValue(
200 IXMLDOMProcessingInstruction *iface,
203 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
205 TRACE("(%p)->(%p)\n", This, value);
207 return node_get_content(&This->node, value);
210 static HRESULT WINAPI dom_pi_put_nodeValue(
211 IXMLDOMProcessingInstruction *iface,
214 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
218 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
220 /* Cannot set data to a PI node whose target is 'xml' */
221 hr = dom_pi_get_nodeName(iface, &sTarget);
224 static const WCHAR xmlW[] = {'x','m','l',0};
225 if(lstrcmpW( sTarget, xmlW) == 0)
227 SysFreeString(sTarget);
231 SysFreeString(sTarget);
234 return node_put_value(&This->node, &value);
237 static HRESULT WINAPI dom_pi_get_nodeType(
238 IXMLDOMProcessingInstruction *iface,
239 DOMNodeType* domNodeType )
241 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
243 TRACE("(%p)->(%p)\n", This, domNodeType);
245 *domNodeType = NODE_PROCESSING_INSTRUCTION;
249 static HRESULT WINAPI dom_pi_get_parentNode(
250 IXMLDOMProcessingInstruction *iface,
251 IXMLDOMNode** parent )
253 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
255 TRACE("(%p)->(%p)\n", This, parent);
257 return node_get_parent(&This->node, parent);
260 static HRESULT WINAPI dom_pi_get_childNodes(
261 IXMLDOMProcessingInstruction *iface,
262 IXMLDOMNodeList** outList)
264 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
266 TRACE("(%p)->(%p)\n", This, outList);
268 return node_get_child_nodes(&This->node, outList);
271 static HRESULT WINAPI dom_pi_get_firstChild(
272 IXMLDOMProcessingInstruction *iface,
273 IXMLDOMNode** domNode)
275 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
277 TRACE("(%p)->(%p)\n", This, domNode);
279 return return_null_node(domNode);
282 static HRESULT WINAPI dom_pi_get_lastChild(
283 IXMLDOMProcessingInstruction *iface,
284 IXMLDOMNode** domNode)
286 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
288 TRACE("(%p)->(%p)\n", This, domNode);
290 return return_null_node(domNode);
293 static HRESULT WINAPI dom_pi_get_previousSibling(
294 IXMLDOMProcessingInstruction *iface,
295 IXMLDOMNode** domNode)
297 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
299 TRACE("(%p)->(%p)\n", This, domNode);
301 return node_get_previous_sibling(&This->node, domNode);
304 static HRESULT WINAPI dom_pi_get_nextSibling(
305 IXMLDOMProcessingInstruction *iface,
306 IXMLDOMNode** domNode)
308 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
310 TRACE("(%p)->(%p)\n", This, domNode);
312 return node_get_next_sibling(&This->node, domNode);
315 static HRESULT WINAPI dom_pi_get_attributes(
316 IXMLDOMProcessingInstruction *iface,
317 IXMLDOMNamedNodeMap** map)
319 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
320 static const WCHAR xmlW[] = {'x','m','l',0};
324 TRACE("(%p)->(%p)\n", This, map);
326 if (!map) return E_INVALIDARG;
330 hr = node_get_nodeName(&This->node, &name);
331 if (hr != S_OK) return hr;
333 if (!strcmpW(name, xmlW))
335 FIXME("created dummy map for <?xml ?>\n");
336 *map = create_nodemap(This->node.node, &dom_pi_attr_map);
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 static HRESULT dom_pi_get_qualified_item(const xmlNodePtr node, BSTR name, BSTR uri,
710 FIXME("(%p)->(%s %s %p): stub\n", node, debugstr_w(name), debugstr_w(uri), item);
714 static HRESULT dom_pi_get_named_item(const xmlNodePtr node, BSTR name, IXMLDOMNode **item)
716 FIXME("(%p)->(%s %p): stub\n", node, debugstr_w(name), item );
720 static HRESULT dom_pi_set_named_item(xmlNodePtr node, IXMLDOMNode *newItem, IXMLDOMNode **namedItem)
722 FIXME("(%p)->(%p %p): stub\n", node, newItem, namedItem );
726 static HRESULT dom_pi_remove_qualified_item(xmlNodePtr node, BSTR name, BSTR uri, IXMLDOMNode **item)
728 FIXME("(%p)->(%s %s %p): stub\n", node, debugstr_w(name), debugstr_w(uri), item);
732 static HRESULT dom_pi_remove_named_item(xmlNodePtr node, BSTR name, IXMLDOMNode **item)
734 FIXME("(%p)->(%s %p): stub\n", node, debugstr_w(name), item);
738 static HRESULT dom_pi_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode **item)
740 FIXME("(%p)->(%d %p): stub\n", node, index, item);
744 static HRESULT dom_pi_get_length(const xmlNodePtr node, LONG *length)
746 FIXME("(%p)->(%p): stub\n", node, length);
752 static HRESULT dom_pi_next_node(const xmlNodePtr node, LONG *iter, IXMLDOMNode **nextNode)
754 FIXME("(%p)->(%d %p): stub\n", node, *iter, nextNode);
758 static const struct nodemap_funcs dom_pi_attr_map = {
759 dom_pi_get_named_item,
760 dom_pi_set_named_item,
761 dom_pi_remove_named_item,
764 dom_pi_get_qualified_item,
765 dom_pi_remove_qualified_item,
769 static const tid_t dompi_iface_tids[] = {
770 IXMLDOMProcessingInstruction_tid,
774 static dispex_static_data_t dompi_dispex = {
776 IXMLDOMProcessingInstruction_tid,
781 IUnknown* create_pi( xmlNodePtr pi )
785 This = heap_alloc( sizeof *This );
789 This->IXMLDOMProcessingInstruction_iface.lpVtbl = &dom_pi_vtbl;
792 init_xmlnode(&This->node, pi, (IXMLDOMNode*)&This->IXMLDOMProcessingInstruction_iface, &dompi_dispex);
794 return (IUnknown*)&This->IXMLDOMProcessingInstruction_iface;