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 const tid_t dompi_se_tids[] = {
56 IXMLDOMProcessingInstruction_tid,
60 static inline dom_pi *impl_from_IXMLDOMProcessingInstruction( IXMLDOMProcessingInstruction *iface )
62 return CONTAINING_RECORD(iface, dom_pi, IXMLDOMProcessingInstruction_iface);
65 static HRESULT WINAPI dom_pi_QueryInterface(
66 IXMLDOMProcessingInstruction *iface,
70 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
71 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
73 if ( IsEqualGUID( riid, &IID_IXMLDOMProcessingInstruction ) ||
74 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
75 IsEqualGUID( riid, &IID_IDispatch ) ||
76 IsEqualGUID( riid, &IID_IUnknown ) )
80 else if(node_query_interface(&This->node, riid, ppvObject))
82 return *ppvObject ? S_OK : E_NOINTERFACE;
84 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
86 return node_create_supporterrorinfo(dompi_se_tids, ppvObject);
90 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
95 IUnknown_AddRef((IUnknown*)*ppvObject);
99 static ULONG WINAPI dom_pi_AddRef(
100 IXMLDOMProcessingInstruction *iface )
102 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
103 ULONG ref = InterlockedIncrement( &This->ref );
104 TRACE("(%p)->(%d)\n", This, ref);
108 static ULONG WINAPI dom_pi_Release(
109 IXMLDOMProcessingInstruction *iface )
111 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
112 ULONG ref = InterlockedDecrement( &This->ref );
114 TRACE("(%p)->(%d)\n", This, ref);
117 destroy_xmlnode(&This->node);
124 static HRESULT WINAPI dom_pi_GetTypeInfoCount(
125 IXMLDOMProcessingInstruction *iface,
128 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
130 TRACE("(%p)->(%p)\n", This, pctinfo);
137 static HRESULT WINAPI dom_pi_GetTypeInfo(
138 IXMLDOMProcessingInstruction *iface,
139 UINT iTInfo, LCID lcid,
140 ITypeInfo** ppTInfo )
142 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
144 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
146 return get_typeinfo(IXMLDOMProcessingInstruction_tid, ppTInfo);
149 static HRESULT WINAPI dom_pi_GetIDsOfNames(
150 IXMLDOMProcessingInstruction *iface,
151 REFIID riid, LPOLESTR* rgszNames,
152 UINT cNames, LCID lcid, DISPID* rgDispId )
154 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
158 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
161 if(!rgszNames || cNames == 0 || !rgDispId)
164 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
167 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
168 ITypeInfo_Release(typeinfo);
174 static HRESULT WINAPI dom_pi_Invoke(
175 IXMLDOMProcessingInstruction *iface,
176 DISPID dispIdMember, REFIID riid, LCID lcid,
177 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
178 EXCEPINFO* pExcepInfo, UINT* puArgErr )
180 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
184 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
185 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
187 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
190 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMProcessingInstruction_iface, dispIdMember,
191 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
192 ITypeInfo_Release(typeinfo);
198 static HRESULT WINAPI dom_pi_get_nodeName(
199 IXMLDOMProcessingInstruction *iface,
202 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
204 TRACE("(%p)->(%p)\n", This, p);
206 return node_get_nodeName(&This->node, p);
209 static HRESULT WINAPI dom_pi_get_nodeValue(
210 IXMLDOMProcessingInstruction *iface,
213 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
215 TRACE("(%p)->(%p)\n", This, value);
217 return node_get_content(&This->node, value);
220 static HRESULT WINAPI dom_pi_put_nodeValue(
221 IXMLDOMProcessingInstruction *iface,
224 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
228 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
230 /* Cannot set data to a PI node whose target is 'xml' */
231 hr = IXMLDOMProcessingInstruction_get_nodeName(iface, &target);
234 static const WCHAR xmlW[] = {'x','m','l',0};
235 if(!strcmpW(target, xmlW))
237 SysFreeString(target);
241 SysFreeString(target);
244 return node_put_value(&This->node, &value);
247 static HRESULT WINAPI dom_pi_get_nodeType(
248 IXMLDOMProcessingInstruction *iface,
249 DOMNodeType* domNodeType )
251 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
253 TRACE("(%p)->(%p)\n", This, domNodeType);
255 *domNodeType = NODE_PROCESSING_INSTRUCTION;
259 static HRESULT WINAPI dom_pi_get_parentNode(
260 IXMLDOMProcessingInstruction *iface,
261 IXMLDOMNode** parent )
263 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
265 TRACE("(%p)->(%p)\n", This, parent);
267 return node_get_parent(&This->node, parent);
270 static HRESULT WINAPI dom_pi_get_childNodes(
271 IXMLDOMProcessingInstruction *iface,
272 IXMLDOMNodeList** outList)
274 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
276 TRACE("(%p)->(%p)\n", This, outList);
278 return node_get_child_nodes(&This->node, outList);
281 static HRESULT WINAPI dom_pi_get_firstChild(
282 IXMLDOMProcessingInstruction *iface,
283 IXMLDOMNode** domNode)
285 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
287 TRACE("(%p)->(%p)\n", This, domNode);
289 return return_null_node(domNode);
292 static HRESULT WINAPI dom_pi_get_lastChild(
293 IXMLDOMProcessingInstruction *iface,
294 IXMLDOMNode** domNode)
296 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
298 TRACE("(%p)->(%p)\n", This, domNode);
300 return return_null_node(domNode);
303 static HRESULT WINAPI dom_pi_get_previousSibling(
304 IXMLDOMProcessingInstruction *iface,
305 IXMLDOMNode** domNode)
307 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
309 TRACE("(%p)->(%p)\n", This, domNode);
311 return node_get_previous_sibling(&This->node, domNode);
314 static HRESULT WINAPI dom_pi_get_nextSibling(
315 IXMLDOMProcessingInstruction *iface,
316 IXMLDOMNode** domNode)
318 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
320 TRACE("(%p)->(%p)\n", This, domNode);
322 return node_get_next_sibling(&This->node, domNode);
325 static HRESULT WINAPI dom_pi_get_attributes(
326 IXMLDOMProcessingInstruction *iface,
327 IXMLDOMNamedNodeMap** map)
329 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
330 static const WCHAR xmlW[] = {'x','m','l',0};
334 TRACE("(%p)->(%p)\n", This, map);
336 if (!map) return E_INVALIDARG;
340 hr = node_get_nodeName(&This->node, &name);
341 if (hr != S_OK) return hr;
343 if (!strcmpW(name, xmlW))
345 FIXME("created dummy map for <?xml ?>\n");
346 *map = create_nodemap(This->node.node, &dom_pi_attr_map);
356 static HRESULT WINAPI dom_pi_insertBefore(
357 IXMLDOMProcessingInstruction *iface,
358 IXMLDOMNode* newNode, VARIANT refChild,
359 IXMLDOMNode** outOldNode)
361 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
363 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
365 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
368 static HRESULT WINAPI dom_pi_replaceChild(
369 IXMLDOMProcessingInstruction *iface,
370 IXMLDOMNode* newNode,
371 IXMLDOMNode* oldNode,
372 IXMLDOMNode** outOldNode)
374 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
376 FIXME("(%p)->(%p %p %p) needs test\n", This, newNode, oldNode, outOldNode);
378 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
381 static HRESULT WINAPI dom_pi_removeChild(
382 IXMLDOMProcessingInstruction *iface,
383 IXMLDOMNode *child, IXMLDOMNode **oldChild)
385 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
386 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
387 return node_remove_child(&This->node, child, oldChild);
390 static HRESULT WINAPI dom_pi_appendChild(
391 IXMLDOMProcessingInstruction *iface,
392 IXMLDOMNode *child, IXMLDOMNode **outChild)
394 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
395 TRACE("(%p)->(%p %p)\n", This, child, outChild);
396 return node_append_child(&This->node, child, outChild);
399 static HRESULT WINAPI dom_pi_hasChildNodes(
400 IXMLDOMProcessingInstruction *iface,
403 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
404 TRACE("(%p)->(%p)\n", This, ret);
405 return node_has_childnodes(&This->node, ret);
408 static HRESULT WINAPI dom_pi_get_ownerDocument(
409 IXMLDOMProcessingInstruction *iface,
410 IXMLDOMDocument **doc)
412 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
413 TRACE("(%p)->(%p)\n", This, doc);
414 return node_get_owner_doc(&This->node, doc);
417 static HRESULT WINAPI dom_pi_cloneNode(
418 IXMLDOMProcessingInstruction *iface,
419 VARIANT_BOOL deep, IXMLDOMNode** outNode)
421 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
422 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
423 return node_clone( &This->node, deep, outNode );
426 static HRESULT WINAPI dom_pi_get_nodeTypeString(
427 IXMLDOMProcessingInstruction *iface,
430 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
431 static const WCHAR processinginstructionW[] =
432 {'p','r','o','c','e','s','s','i','n','g','i','n','s','t','r','u','c','t','i','o','n',0};
434 TRACE("(%p)->(%p)\n", This, p);
436 return return_bstr(processinginstructionW, p);
439 static HRESULT WINAPI dom_pi_get_text(
440 IXMLDOMProcessingInstruction *iface,
443 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
444 TRACE("(%p)->(%p)\n", This, p);
445 return node_get_text(&This->node, p);
448 static HRESULT WINAPI dom_pi_put_text(
449 IXMLDOMProcessingInstruction *iface,
452 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
453 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
454 return node_put_text( &This->node, p );
457 static HRESULT WINAPI dom_pi_get_specified(
458 IXMLDOMProcessingInstruction *iface,
459 VARIANT_BOOL* isSpecified)
461 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
462 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
463 *isSpecified = VARIANT_TRUE;
467 static HRESULT WINAPI dom_pi_get_definition(
468 IXMLDOMProcessingInstruction *iface,
469 IXMLDOMNode** definitionNode)
471 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
472 FIXME("(%p)->(%p)\n", This, definitionNode);
476 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
477 IXMLDOMProcessingInstruction *iface,
480 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
481 TRACE("(%p)->(%p)\n", This, v);
482 return node_get_content(&This->node, v);
485 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
486 IXMLDOMProcessingInstruction *iface,
489 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
490 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
494 static HRESULT WINAPI dom_pi_get_dataType(
495 IXMLDOMProcessingInstruction *iface,
498 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
499 TRACE("(%p)->(%p)\n", This, typename);
500 return return_null_var( typename );
503 static HRESULT WINAPI dom_pi_put_dataType(
504 IXMLDOMProcessingInstruction *iface,
507 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
509 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
517 static HRESULT WINAPI dom_pi_get_xml(
518 IXMLDOMProcessingInstruction *iface,
521 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
523 TRACE("(%p)->(%p)\n", This, p);
525 return node_get_xml(&This->node, FALSE, FALSE, p);
528 static HRESULT WINAPI dom_pi_transformNode(
529 IXMLDOMProcessingInstruction *iface,
530 IXMLDOMNode *node, BSTR *p)
532 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
533 TRACE("(%p)->(%p %p)\n", This, node, p);
534 return node_transform_node(&This->node, node, p);
537 static HRESULT WINAPI dom_pi_selectNodes(
538 IXMLDOMProcessingInstruction *iface,
539 BSTR p, IXMLDOMNodeList** outList)
541 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
542 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
543 return node_select_nodes(&This->node, p, outList);
546 static HRESULT WINAPI dom_pi_selectSingleNode(
547 IXMLDOMProcessingInstruction *iface,
548 BSTR p, IXMLDOMNode** outNode)
550 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
551 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
552 return node_select_singlenode(&This->node, p, outNode);
555 static HRESULT WINAPI dom_pi_get_parsed(
556 IXMLDOMProcessingInstruction *iface,
557 VARIANT_BOOL* isParsed)
559 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
560 FIXME("(%p)->(%p) stub!\n", This, isParsed);
561 *isParsed = VARIANT_TRUE;
565 static HRESULT WINAPI dom_pi_get_namespaceURI(
566 IXMLDOMProcessingInstruction *iface,
569 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
570 TRACE("(%p)->(%p)\n", This, p);
571 return node_get_namespaceURI(&This->node, p);
574 static HRESULT WINAPI dom_pi_get_prefix(
575 IXMLDOMProcessingInstruction *iface,
578 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
579 TRACE("(%p)->(%p)\n", This, prefix);
580 return return_null_bstr( prefix );
583 static HRESULT WINAPI dom_pi_get_baseName(
584 IXMLDOMProcessingInstruction *iface,
587 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
588 TRACE("(%p)->(%p)\n", This, name);
589 return node_get_base_name( &This->node, name );
592 static HRESULT WINAPI dom_pi_transformNodeToObject(
593 IXMLDOMProcessingInstruction *iface,
594 IXMLDOMNode* domNode, VARIANT var1)
596 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
597 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
601 static HRESULT WINAPI dom_pi_get_target(
602 IXMLDOMProcessingInstruction *iface,
605 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
607 TRACE("(%p)->(%p)\n", This, p);
609 /* target returns the same value as nodeName property */
610 return node_get_nodeName(&This->node, p);
613 static HRESULT WINAPI dom_pi_get_data(
614 IXMLDOMProcessingInstruction *iface,
617 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
621 TRACE("(%p)->(%p)\n", This, p);
626 hr = IXMLDOMProcessingInstruction_get_nodeValue( iface, &ret );
635 static HRESULT WINAPI dom_pi_put_data(
636 IXMLDOMProcessingInstruction *iface,
639 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
644 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
646 /* Cannot set data to a PI node whose target is 'xml' */
647 hr = IXMLDOMProcessingInstruction_get_nodeName(iface, &target);
650 static const WCHAR xmlW[] = {'x','m','l',0};
651 if(!strcmpW(target, xmlW))
653 SysFreeString(target);
657 SysFreeString(target);
660 V_VT(&val) = VT_BSTR;
663 return IXMLDOMProcessingInstruction_put_nodeValue( iface, val );
666 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
668 dom_pi_QueryInterface,
671 dom_pi_GetTypeInfoCount,
673 dom_pi_GetIDsOfNames,
676 dom_pi_get_nodeValue,
677 dom_pi_put_nodeValue,
679 dom_pi_get_parentNode,
680 dom_pi_get_childNodes,
681 dom_pi_get_firstChild,
682 dom_pi_get_lastChild,
683 dom_pi_get_previousSibling,
684 dom_pi_get_nextSibling,
685 dom_pi_get_attributes,
690 dom_pi_hasChildNodes,
691 dom_pi_get_ownerDocument,
693 dom_pi_get_nodeTypeString,
696 dom_pi_get_specified,
697 dom_pi_get_definition,
698 dom_pi_get_nodeTypedValue,
699 dom_pi_put_nodeTypedValue,
703 dom_pi_transformNode,
705 dom_pi_selectSingleNode,
707 dom_pi_get_namespaceURI,
710 dom_pi_transformNodeToObject,
717 static HRESULT dom_pi_get_qualified_item(const xmlNodePtr node, BSTR name, BSTR uri,
720 FIXME("(%p)->(%s %s %p): stub\n", node, debugstr_w(name), debugstr_w(uri), item);
724 static HRESULT dom_pi_get_named_item(const xmlNodePtr node, BSTR name, IXMLDOMNode **item)
726 FIXME("(%p)->(%s %p): stub\n", node, debugstr_w(name), item );
730 static HRESULT dom_pi_set_named_item(xmlNodePtr node, IXMLDOMNode *newItem, IXMLDOMNode **namedItem)
732 FIXME("(%p)->(%p %p): stub\n", node, newItem, namedItem );
736 static HRESULT dom_pi_remove_qualified_item(xmlNodePtr node, BSTR name, BSTR uri, IXMLDOMNode **item)
738 FIXME("(%p)->(%s %s %p): stub\n", node, debugstr_w(name), debugstr_w(uri), item);
742 static HRESULT dom_pi_remove_named_item(xmlNodePtr node, BSTR name, IXMLDOMNode **item)
744 FIXME("(%p)->(%s %p): stub\n", node, debugstr_w(name), item);
748 static HRESULT dom_pi_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode **item)
750 FIXME("(%p)->(%d %p): stub\n", node, index, item);
754 static HRESULT dom_pi_get_length(const xmlNodePtr node, LONG *length)
756 FIXME("(%p)->(%p): stub\n", node, length);
762 static HRESULT dom_pi_next_node(const xmlNodePtr node, LONG *iter, IXMLDOMNode **nextNode)
764 FIXME("(%p)->(%d %p): stub\n", node, *iter, nextNode);
768 static const struct nodemap_funcs dom_pi_attr_map = {
769 dom_pi_get_named_item,
770 dom_pi_set_named_item,
771 dom_pi_remove_named_item,
774 dom_pi_get_qualified_item,
775 dom_pi_remove_qualified_item,
779 static const tid_t dompi_iface_tids[] = {
780 IXMLDOMProcessingInstruction_tid,
784 static dispex_static_data_t dompi_dispex = {
786 IXMLDOMProcessingInstruction_tid,
791 IUnknown* create_pi( xmlNodePtr pi )
795 This = heap_alloc( sizeof *This );
799 This->IXMLDOMProcessingInstruction_iface.lpVtbl = &dom_pi_vtbl;
802 init_xmlnode(&This->node, pi, (IXMLDOMNode*)&This->IXMLDOMProcessingInstruction_iface, &dompi_dispex);
804 return (IUnknown*)&This->IXMLDOMProcessingInstruction_iface;