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 );
129 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
132 static HRESULT WINAPI dom_pi_GetTypeInfo(
133 IXMLDOMProcessingInstruction *iface,
134 UINT iTInfo, LCID lcid,
135 ITypeInfo** ppTInfo )
137 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
138 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
139 iTInfo, lcid, ppTInfo);
142 static HRESULT WINAPI dom_pi_GetIDsOfNames(
143 IXMLDOMProcessingInstruction *iface,
144 REFIID riid, LPOLESTR* rgszNames,
145 UINT cNames, LCID lcid, DISPID* rgDispId )
147 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
148 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
149 riid, rgszNames, cNames, lcid, rgDispId);
152 static HRESULT WINAPI dom_pi_Invoke(
153 IXMLDOMProcessingInstruction *iface,
154 DISPID dispIdMember, REFIID riid, LCID lcid,
155 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
156 EXCEPINFO* pExcepInfo, UINT* puArgErr )
158 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
159 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
160 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
163 static HRESULT WINAPI dom_pi_get_nodeName(
164 IXMLDOMProcessingInstruction *iface,
167 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
169 TRACE("(%p)->(%p)\n", This, p);
171 return node_get_nodeName(&This->node, p);
174 static HRESULT WINAPI dom_pi_get_nodeValue(
175 IXMLDOMProcessingInstruction *iface,
178 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
180 TRACE("(%p)->(%p)\n", This, value);
182 return node_get_content(&This->node, value);
185 static HRESULT WINAPI dom_pi_put_nodeValue(
186 IXMLDOMProcessingInstruction *iface,
189 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
193 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
195 /* Cannot set data to a PI node whose target is 'xml' */
196 hr = IXMLDOMProcessingInstruction_get_nodeName(iface, &target);
199 static const WCHAR xmlW[] = {'x','m','l',0};
200 if(!strcmpW(target, xmlW))
202 SysFreeString(target);
206 SysFreeString(target);
209 return node_put_value(&This->node, &value);
212 static HRESULT WINAPI dom_pi_get_nodeType(
213 IXMLDOMProcessingInstruction *iface,
214 DOMNodeType* domNodeType )
216 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
218 TRACE("(%p)->(%p)\n", This, domNodeType);
220 *domNodeType = NODE_PROCESSING_INSTRUCTION;
224 static HRESULT WINAPI dom_pi_get_parentNode(
225 IXMLDOMProcessingInstruction *iface,
226 IXMLDOMNode** parent )
228 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
230 TRACE("(%p)->(%p)\n", This, parent);
232 return node_get_parent(&This->node, parent);
235 static HRESULT WINAPI dom_pi_get_childNodes(
236 IXMLDOMProcessingInstruction *iface,
237 IXMLDOMNodeList** outList)
239 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
241 TRACE("(%p)->(%p)\n", This, outList);
243 return node_get_child_nodes(&This->node, outList);
246 static HRESULT WINAPI dom_pi_get_firstChild(
247 IXMLDOMProcessingInstruction *iface,
248 IXMLDOMNode** domNode)
250 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
252 TRACE("(%p)->(%p)\n", This, domNode);
254 return return_null_node(domNode);
257 static HRESULT WINAPI dom_pi_get_lastChild(
258 IXMLDOMProcessingInstruction *iface,
259 IXMLDOMNode** domNode)
261 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
263 TRACE("(%p)->(%p)\n", This, domNode);
265 return return_null_node(domNode);
268 static HRESULT WINAPI dom_pi_get_previousSibling(
269 IXMLDOMProcessingInstruction *iface,
270 IXMLDOMNode** domNode)
272 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
274 TRACE("(%p)->(%p)\n", This, domNode);
276 return node_get_previous_sibling(&This->node, domNode);
279 static HRESULT WINAPI dom_pi_get_nextSibling(
280 IXMLDOMProcessingInstruction *iface,
281 IXMLDOMNode** domNode)
283 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
285 TRACE("(%p)->(%p)\n", This, domNode);
287 return node_get_next_sibling(&This->node, domNode);
290 static HRESULT WINAPI dom_pi_get_attributes(
291 IXMLDOMProcessingInstruction *iface,
292 IXMLDOMNamedNodeMap** map)
294 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
295 static const WCHAR xmlW[] = {'x','m','l',0};
299 TRACE("(%p)->(%p)\n", This, map);
301 if (!map) return E_INVALIDARG;
305 hr = node_get_nodeName(&This->node, &name);
306 if (hr != S_OK) return hr;
308 if (!strcmpW(name, xmlW))
310 FIXME("created dummy map for <?xml ?>\n");
311 *map = create_nodemap(This->node.node, &dom_pi_attr_map);
321 static HRESULT WINAPI dom_pi_insertBefore(
322 IXMLDOMProcessingInstruction *iface,
323 IXMLDOMNode* newNode, VARIANT refChild,
324 IXMLDOMNode** outOldNode)
326 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
328 FIXME("(%p)->(%p %s %p) needs test\n", This, newNode, debugstr_variant(&refChild), outOldNode);
330 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
333 static HRESULT WINAPI dom_pi_replaceChild(
334 IXMLDOMProcessingInstruction *iface,
335 IXMLDOMNode* newNode,
336 IXMLDOMNode* oldNode,
337 IXMLDOMNode** outOldNode)
339 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
341 FIXME("(%p)->(%p %p %p) needs test\n", This, newNode, oldNode, outOldNode);
343 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
346 static HRESULT WINAPI dom_pi_removeChild(
347 IXMLDOMProcessingInstruction *iface,
348 IXMLDOMNode *child, IXMLDOMNode **oldChild)
350 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
351 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
352 return node_remove_child(&This->node, child, oldChild);
355 static HRESULT WINAPI dom_pi_appendChild(
356 IXMLDOMProcessingInstruction *iface,
357 IXMLDOMNode *child, IXMLDOMNode **outChild)
359 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
360 TRACE("(%p)->(%p %p)\n", This, child, outChild);
361 return node_append_child(&This->node, child, outChild);
364 static HRESULT WINAPI dom_pi_hasChildNodes(
365 IXMLDOMProcessingInstruction *iface,
368 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
369 TRACE("(%p)->(%p)\n", This, ret);
370 return node_has_childnodes(&This->node, ret);
373 static HRESULT WINAPI dom_pi_get_ownerDocument(
374 IXMLDOMProcessingInstruction *iface,
375 IXMLDOMDocument **doc)
377 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
378 TRACE("(%p)->(%p)\n", This, doc);
379 return node_get_owner_doc(&This->node, doc);
382 static HRESULT WINAPI dom_pi_cloneNode(
383 IXMLDOMProcessingInstruction *iface,
384 VARIANT_BOOL deep, IXMLDOMNode** outNode)
386 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
387 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
388 return node_clone( &This->node, deep, outNode );
391 static HRESULT WINAPI dom_pi_get_nodeTypeString(
392 IXMLDOMProcessingInstruction *iface,
395 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
396 static const WCHAR processinginstructionW[] =
397 {'p','r','o','c','e','s','s','i','n','g','i','n','s','t','r','u','c','t','i','o','n',0};
399 TRACE("(%p)->(%p)\n", This, p);
401 return return_bstr(processinginstructionW, p);
404 static HRESULT WINAPI dom_pi_get_text(
405 IXMLDOMProcessingInstruction *iface,
408 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
409 TRACE("(%p)->(%p)\n", This, p);
410 return node_get_text(&This->node, p);
413 static HRESULT WINAPI dom_pi_put_text(
414 IXMLDOMProcessingInstruction *iface,
417 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
418 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
419 return node_put_text( &This->node, p );
422 static HRESULT WINAPI dom_pi_get_specified(
423 IXMLDOMProcessingInstruction *iface,
424 VARIANT_BOOL* isSpecified)
426 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
427 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
428 *isSpecified = VARIANT_TRUE;
432 static HRESULT WINAPI dom_pi_get_definition(
433 IXMLDOMProcessingInstruction *iface,
434 IXMLDOMNode** definitionNode)
436 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
437 FIXME("(%p)->(%p)\n", This, definitionNode);
441 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
442 IXMLDOMProcessingInstruction *iface,
445 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
446 TRACE("(%p)->(%p)\n", This, v);
447 return node_get_content(&This->node, v);
450 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
451 IXMLDOMProcessingInstruction *iface,
454 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
455 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
459 static HRESULT WINAPI dom_pi_get_dataType(
460 IXMLDOMProcessingInstruction *iface,
463 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
464 TRACE("(%p)->(%p)\n", This, typename);
465 return return_null_var( typename );
468 static HRESULT WINAPI dom_pi_put_dataType(
469 IXMLDOMProcessingInstruction *iface,
472 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
474 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
482 static HRESULT WINAPI dom_pi_get_xml(
483 IXMLDOMProcessingInstruction *iface,
486 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
488 TRACE("(%p)->(%p)\n", This, p);
490 return node_get_xml(&This->node, FALSE, p);
493 static HRESULT WINAPI dom_pi_transformNode(
494 IXMLDOMProcessingInstruction *iface,
495 IXMLDOMNode *node, BSTR *p)
497 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
498 TRACE("(%p)->(%p %p)\n", This, node, p);
499 return node_transform_node(&This->node, node, p);
502 static HRESULT WINAPI dom_pi_selectNodes(
503 IXMLDOMProcessingInstruction *iface,
504 BSTR p, IXMLDOMNodeList** outList)
506 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
507 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
508 return node_select_nodes(&This->node, p, outList);
511 static HRESULT WINAPI dom_pi_selectSingleNode(
512 IXMLDOMProcessingInstruction *iface,
513 BSTR p, IXMLDOMNode** outNode)
515 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
516 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
517 return node_select_singlenode(&This->node, p, outNode);
520 static HRESULT WINAPI dom_pi_get_parsed(
521 IXMLDOMProcessingInstruction *iface,
522 VARIANT_BOOL* isParsed)
524 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
525 FIXME("(%p)->(%p) stub!\n", This, isParsed);
526 *isParsed = VARIANT_TRUE;
530 static HRESULT WINAPI dom_pi_get_namespaceURI(
531 IXMLDOMProcessingInstruction *iface,
534 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
535 TRACE("(%p)->(%p)\n", This, p);
536 return node_get_namespaceURI(&This->node, p);
539 static HRESULT WINAPI dom_pi_get_prefix(
540 IXMLDOMProcessingInstruction *iface,
543 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
544 TRACE("(%p)->(%p)\n", This, prefix);
545 return return_null_bstr( prefix );
548 static HRESULT WINAPI dom_pi_get_baseName(
549 IXMLDOMProcessingInstruction *iface,
552 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
553 TRACE("(%p)->(%p)\n", This, name);
554 return node_get_base_name( &This->node, name );
557 static HRESULT WINAPI dom_pi_transformNodeToObject(
558 IXMLDOMProcessingInstruction *iface,
559 IXMLDOMNode* domNode, VARIANT var1)
561 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
562 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
566 static HRESULT WINAPI dom_pi_get_target(
567 IXMLDOMProcessingInstruction *iface,
570 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
572 TRACE("(%p)->(%p)\n", This, p);
574 /* target returns the same value as nodeName property */
575 return node_get_nodeName(&This->node, p);
578 static HRESULT WINAPI dom_pi_get_data(
579 IXMLDOMProcessingInstruction *iface,
582 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
586 TRACE("(%p)->(%p)\n", This, p);
591 hr = IXMLDOMProcessingInstruction_get_nodeValue( iface, &ret );
600 static HRESULT WINAPI dom_pi_put_data(
601 IXMLDOMProcessingInstruction *iface,
604 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
608 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
610 /* cannot set data to a PI node whose target is 'xml' */
611 hr = IXMLDOMProcessingInstruction_get_nodeName(iface, &target);
614 static const WCHAR xmlW[] = {'x','m','l',0};
615 if(!strcmpW(target, xmlW))
617 SysFreeString(target);
621 SysFreeString(target);
624 return node_set_content(&This->node, data);
627 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
629 dom_pi_QueryInterface,
632 dom_pi_GetTypeInfoCount,
634 dom_pi_GetIDsOfNames,
637 dom_pi_get_nodeValue,
638 dom_pi_put_nodeValue,
640 dom_pi_get_parentNode,
641 dom_pi_get_childNodes,
642 dom_pi_get_firstChild,
643 dom_pi_get_lastChild,
644 dom_pi_get_previousSibling,
645 dom_pi_get_nextSibling,
646 dom_pi_get_attributes,
651 dom_pi_hasChildNodes,
652 dom_pi_get_ownerDocument,
654 dom_pi_get_nodeTypeString,
657 dom_pi_get_specified,
658 dom_pi_get_definition,
659 dom_pi_get_nodeTypedValue,
660 dom_pi_put_nodeTypedValue,
664 dom_pi_transformNode,
666 dom_pi_selectSingleNode,
668 dom_pi_get_namespaceURI,
671 dom_pi_transformNodeToObject,
678 static HRESULT dom_pi_get_qualified_item(const xmlNodePtr node, BSTR name, BSTR uri,
681 FIXME("(%p)->(%s %s %p): stub\n", node, debugstr_w(name), debugstr_w(uri), item);
685 static HRESULT dom_pi_get_named_item(const xmlNodePtr node, BSTR name, IXMLDOMNode **item)
687 FIXME("(%p)->(%s %p): stub\n", node, debugstr_w(name), item );
691 static HRESULT dom_pi_set_named_item(xmlNodePtr node, IXMLDOMNode *newItem, IXMLDOMNode **namedItem)
693 FIXME("(%p)->(%p %p): stub\n", node, newItem, namedItem );
697 static HRESULT dom_pi_remove_qualified_item(xmlNodePtr node, BSTR name, BSTR uri, IXMLDOMNode **item)
699 FIXME("(%p)->(%s %s %p): stub\n", node, debugstr_w(name), debugstr_w(uri), item);
703 static HRESULT dom_pi_remove_named_item(xmlNodePtr node, BSTR name, IXMLDOMNode **item)
705 FIXME("(%p)->(%s %p): stub\n", node, debugstr_w(name), item);
709 static HRESULT dom_pi_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode **item)
711 FIXME("(%p)->(%d %p): stub\n", node, index, item);
715 static HRESULT dom_pi_get_length(const xmlNodePtr node, LONG *length)
717 FIXME("(%p)->(%p): stub\n", node, length);
723 static HRESULT dom_pi_next_node(const xmlNodePtr node, LONG *iter, IXMLDOMNode **nextNode)
725 FIXME("(%p)->(%d %p): stub\n", node, *iter, nextNode);
729 static const struct nodemap_funcs dom_pi_attr_map = {
730 dom_pi_get_named_item,
731 dom_pi_set_named_item,
732 dom_pi_remove_named_item,
735 dom_pi_get_qualified_item,
736 dom_pi_remove_qualified_item,
740 static const tid_t dompi_iface_tids[] = {
741 IXMLDOMProcessingInstruction_tid,
745 static dispex_static_data_t dompi_dispex = {
747 IXMLDOMProcessingInstruction_tid,
752 IUnknown* create_pi( xmlNodePtr pi )
756 This = heap_alloc( sizeof *This );
760 This->IXMLDOMProcessingInstruction_iface.lpVtbl = &dom_pi_vtbl;
763 init_xmlnode(&This->node, pi, (IXMLDOMNode*)&This->IXMLDOMProcessingInstruction_iface, &dompi_dispex);
765 return (IUnknown*)&This->IXMLDOMProcessingInstruction_iface;