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
43 const struct IXMLDOMProcessingInstructionVtbl *lpVtbl;
47 static inline dom_pi *impl_from_IXMLDOMProcessingInstruction( IXMLDOMProcessingInstruction *iface )
49 return (dom_pi *)((char*)iface - FIELD_OFFSET(dom_pi, lpVtbl));
52 static HRESULT WINAPI dom_pi_QueryInterface(
53 IXMLDOMProcessingInstruction *iface,
57 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
58 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
60 if ( IsEqualGUID( riid, &IID_IXMLDOMProcessingInstruction ) ||
61 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
62 IsEqualGUID( riid, &IID_IDispatch ) ||
63 IsEqualGUID( riid, &IID_IUnknown ) )
67 else if(node_query_interface(&This->node, riid, ppvObject))
69 return *ppvObject ? S_OK : E_NOINTERFACE;
73 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
77 IUnknown_AddRef((IUnknown*)*ppvObject);
81 static ULONG WINAPI dom_pi_AddRef(
82 IXMLDOMProcessingInstruction *iface )
84 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
85 return InterlockedIncrement( &This->ref );
88 static ULONG WINAPI dom_pi_Release(
89 IXMLDOMProcessingInstruction *iface )
91 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
94 ref = InterlockedDecrement( &This->ref );
97 destroy_xmlnode(&This->node);
104 static HRESULT WINAPI dom_pi_GetTypeInfoCount(
105 IXMLDOMProcessingInstruction *iface,
108 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
110 TRACE("(%p)->(%p)\n", This, pctinfo);
117 static HRESULT WINAPI dom_pi_GetTypeInfo(
118 IXMLDOMProcessingInstruction *iface,
119 UINT iTInfo, LCID lcid,
120 ITypeInfo** ppTInfo )
122 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
125 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
127 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, ppTInfo);
132 static HRESULT WINAPI dom_pi_GetIDsOfNames(
133 IXMLDOMProcessingInstruction *iface,
134 REFIID riid, LPOLESTR* rgszNames,
135 UINT cNames, LCID lcid, DISPID* rgDispId )
137 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
141 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
144 if(!rgszNames || cNames == 0 || !rgDispId)
147 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
150 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
151 ITypeInfo_Release(typeinfo);
157 static HRESULT WINAPI dom_pi_Invoke(
158 IXMLDOMProcessingInstruction *iface,
159 DISPID dispIdMember, REFIID riid, LCID lcid,
160 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
161 EXCEPINFO* pExcepInfo, UINT* puArgErr )
163 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
167 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
168 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
170 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
173 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
174 pVarResult, pExcepInfo, puArgErr);
175 ITypeInfo_Release(typeinfo);
181 static HRESULT WINAPI dom_pi_get_nodeName(
182 IXMLDOMProcessingInstruction *iface,
185 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
187 TRACE("(%p)->(%p)\n", This, p);
189 return node_get_nodeName(&This->node, p);
192 static HRESULT WINAPI dom_pi_get_nodeValue(
193 IXMLDOMProcessingInstruction *iface,
196 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
198 TRACE("(%p)->(%p)\n", This, value);
200 return node_get_content(&This->node, value);
203 static HRESULT WINAPI dom_pi_put_nodeValue(
204 IXMLDOMProcessingInstruction *iface,
207 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
209 static const WCHAR szXML[] = {'x','m','l',0};
212 TRACE("(%p)->(v%d)\n", This, V_VT(&value));
214 /* Cannot set data to a PI node whose target is 'xml' */
215 hr = dom_pi_get_nodeName(iface, &sTarget);
218 if(lstrcmpW( sTarget, szXML) == 0)
220 SysFreeString(sTarget);
224 SysFreeString(sTarget);
227 return node_put_value(&This->node, &value);
230 static HRESULT WINAPI dom_pi_get_nodeType(
231 IXMLDOMProcessingInstruction *iface,
232 DOMNodeType* domNodeType )
234 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
236 TRACE("(%p)->(%p)\n", This, domNodeType);
238 *domNodeType = NODE_PROCESSING_INSTRUCTION;
242 static HRESULT WINAPI dom_pi_get_parentNode(
243 IXMLDOMProcessingInstruction *iface,
244 IXMLDOMNode** parent )
246 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
248 TRACE("(%p)->(%p)\n", This, parent);
250 return node_get_parent(&This->node, parent);
253 static HRESULT WINAPI dom_pi_get_childNodes(
254 IXMLDOMProcessingInstruction *iface,
255 IXMLDOMNodeList** outList)
257 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
259 TRACE("(%p)->(%p)\n", This, outList);
261 return node_get_child_nodes(&This->node, outList);
264 static HRESULT WINAPI dom_pi_get_firstChild(
265 IXMLDOMProcessingInstruction *iface,
266 IXMLDOMNode** domNode)
268 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
269 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
272 static HRESULT WINAPI dom_pi_get_lastChild(
273 IXMLDOMProcessingInstruction *iface,
274 IXMLDOMNode** domNode)
276 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
277 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
280 static HRESULT WINAPI dom_pi_get_previousSibling(
281 IXMLDOMProcessingInstruction *iface,
282 IXMLDOMNode** domNode)
284 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
285 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
288 static HRESULT WINAPI dom_pi_get_nextSibling(
289 IXMLDOMProcessingInstruction *iface,
290 IXMLDOMNode** domNode)
292 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
293 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
296 static HRESULT WINAPI dom_pi_get_attributes(
297 IXMLDOMProcessingInstruction *iface,
298 IXMLDOMNamedNodeMap** attributeMap)
300 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
301 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
304 static HRESULT WINAPI dom_pi_insertBefore(
305 IXMLDOMProcessingInstruction *iface,
306 IXMLDOMNode* newNode, VARIANT var1,
307 IXMLDOMNode** outOldNode)
309 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
310 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
313 static HRESULT WINAPI dom_pi_replaceChild(
314 IXMLDOMProcessingInstruction *iface,
315 IXMLDOMNode* newNode,
316 IXMLDOMNode* oldNode,
317 IXMLDOMNode** outOldNode)
319 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
320 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
323 static HRESULT WINAPI dom_pi_removeChild(
324 IXMLDOMProcessingInstruction *iface,
325 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
327 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
328 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
331 static HRESULT WINAPI dom_pi_appendChild(
332 IXMLDOMProcessingInstruction *iface,
333 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
335 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
336 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
339 static HRESULT WINAPI dom_pi_hasChildNodes(
340 IXMLDOMProcessingInstruction *iface,
343 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
344 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
347 static HRESULT WINAPI dom_pi_get_ownerDocument(
348 IXMLDOMProcessingInstruction *iface,
349 IXMLDOMDocument** domDocument)
351 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
352 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
355 static HRESULT WINAPI dom_pi_cloneNode(
356 IXMLDOMProcessingInstruction *iface,
357 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
359 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
360 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
363 static HRESULT WINAPI dom_pi_get_nodeTypeString(
364 IXMLDOMProcessingInstruction *iface,
367 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
368 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
371 static HRESULT WINAPI dom_pi_get_text(
372 IXMLDOMProcessingInstruction *iface,
375 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
376 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
379 static HRESULT WINAPI dom_pi_put_text(
380 IXMLDOMProcessingInstruction *iface,
383 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
384 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
387 static HRESULT WINAPI dom_pi_get_specified(
388 IXMLDOMProcessingInstruction *iface,
391 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
392 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
395 static HRESULT WINAPI dom_pi_get_definition(
396 IXMLDOMProcessingInstruction *iface,
397 IXMLDOMNode** domNode)
399 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
400 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
403 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
404 IXMLDOMProcessingInstruction *iface,
407 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
408 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
411 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
412 IXMLDOMProcessingInstruction *iface,
415 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
416 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
419 static HRESULT WINAPI dom_pi_get_dataType(
420 IXMLDOMProcessingInstruction *iface,
423 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
424 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
427 static HRESULT WINAPI dom_pi_put_dataType(
428 IXMLDOMProcessingInstruction *iface,
431 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
432 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
435 static HRESULT WINAPI dom_pi_get_xml(
436 IXMLDOMProcessingInstruction *iface,
439 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
440 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
443 static HRESULT WINAPI dom_pi_transformNode(
444 IXMLDOMProcessingInstruction *iface,
445 IXMLDOMNode* domNode, BSTR* p)
447 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
448 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
451 static HRESULT WINAPI dom_pi_selectNodes(
452 IXMLDOMProcessingInstruction *iface,
453 BSTR p, IXMLDOMNodeList** outList)
455 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
456 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
459 static HRESULT WINAPI dom_pi_selectSingleNode(
460 IXMLDOMProcessingInstruction *iface,
461 BSTR p, IXMLDOMNode** outNode)
463 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
464 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
467 static HRESULT WINAPI dom_pi_get_parsed(
468 IXMLDOMProcessingInstruction *iface,
471 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
472 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
475 static HRESULT WINAPI dom_pi_get_namespaceURI(
476 IXMLDOMProcessingInstruction *iface,
479 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
480 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
483 static HRESULT WINAPI dom_pi_get_prefix(
484 IXMLDOMProcessingInstruction *iface,
487 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
488 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
491 static HRESULT WINAPI dom_pi_get_baseName(
492 IXMLDOMProcessingInstruction *iface,
495 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
496 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
499 static HRESULT WINAPI dom_pi_transformNodeToObject(
500 IXMLDOMProcessingInstruction *iface,
501 IXMLDOMNode* domNode, VARIANT var1)
503 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
504 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
507 static HRESULT WINAPI dom_pi_get_target(
508 IXMLDOMProcessingInstruction *iface,
511 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
513 TRACE("(%p)->(%p)\n", This, p);
515 /* target returns the same value as nodeName property */
516 return node_get_nodeName(&This->node, p);
519 static HRESULT WINAPI dom_pi_get_data(
520 IXMLDOMProcessingInstruction *iface,
529 hr = IXMLDOMProcessingInstruction_get_nodeValue( iface, &vRet );
538 static HRESULT WINAPI dom_pi_put_data(
539 IXMLDOMProcessingInstruction *iface,
542 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
546 static const WCHAR szXML[] = {'x','m','l',0};
548 TRACE("(%p)->(%s)\n", This, debugstr_w(data) );
550 /* Cannot set data to a PI node whose target is 'xml' */
551 hr = dom_pi_get_nodeName(iface, &sTarget);
554 if(lstrcmpW( sTarget, szXML) == 0)
556 SysFreeString(sTarget);
560 SysFreeString(sTarget);
563 V_VT(&val) = VT_BSTR;
566 hr = IXMLDOMProcessingInstruction_put_nodeValue( iface, val );
571 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
573 dom_pi_QueryInterface,
576 dom_pi_GetTypeInfoCount,
578 dom_pi_GetIDsOfNames,
581 dom_pi_get_nodeValue,
582 dom_pi_put_nodeValue,
584 dom_pi_get_parentNode,
585 dom_pi_get_childNodes,
586 dom_pi_get_firstChild,
587 dom_pi_get_lastChild,
588 dom_pi_get_previousSibling,
589 dom_pi_get_nextSibling,
590 dom_pi_get_attributes,
595 dom_pi_hasChildNodes,
596 dom_pi_get_ownerDocument,
598 dom_pi_get_nodeTypeString,
601 dom_pi_get_specified,
602 dom_pi_get_definition,
603 dom_pi_get_nodeTypedValue,
604 dom_pi_put_nodeTypedValue,
608 dom_pi_transformNode,
610 dom_pi_selectSingleNode,
612 dom_pi_get_namespaceURI,
615 dom_pi_transformNodeToObject,
622 IUnknown* create_pi( xmlNodePtr pi )
626 This = heap_alloc( sizeof *This );
630 This->lpVtbl = &dom_pi_vtbl;
633 init_xmlnode(&This->node, pi, (IXMLDOMNode*)&This->lpVtbl, NULL);
635 return (IUnknown*) &This->lpVtbl;