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_IDispatch ) ||
62 IsEqualGUID( riid, &IID_IUnknown ) )
66 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
68 *ppvObject = IXMLDOMNode_from_impl(&This->node);
72 FIXME("Unsupported interface %s\n", debugstr_guid(riid));
76 IUnknown_AddRef((IUnknown*)*ppvObject);
80 static ULONG WINAPI dom_pi_AddRef(
81 IXMLDOMProcessingInstruction *iface )
83 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
84 return InterlockedIncrement( &This->ref );
87 static ULONG WINAPI dom_pi_Release(
88 IXMLDOMProcessingInstruction *iface )
90 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
93 ref = InterlockedDecrement( &This->ref );
96 destroy_xmlnode(&This->node);
97 HeapFree( GetProcessHeap(), 0, This );
103 static HRESULT WINAPI dom_pi_GetTypeInfoCount(
104 IXMLDOMProcessingInstruction *iface,
107 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
109 TRACE("(%p)->(%p)\n", This, pctinfo);
116 static HRESULT WINAPI dom_pi_GetTypeInfo(
117 IXMLDOMProcessingInstruction *iface,
118 UINT iTInfo, LCID lcid,
119 ITypeInfo** ppTInfo )
121 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
124 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
126 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, ppTInfo);
131 static HRESULT WINAPI dom_pi_GetIDsOfNames(
132 IXMLDOMProcessingInstruction *iface,
133 REFIID riid, LPOLESTR* rgszNames,
134 UINT cNames, LCID lcid, DISPID* rgDispId )
136 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
140 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
143 if(!rgszNames || cNames == 0 || !rgDispId)
146 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
149 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
150 ITypeInfo_Release(typeinfo);
156 static HRESULT WINAPI dom_pi_Invoke(
157 IXMLDOMProcessingInstruction *iface,
158 DISPID dispIdMember, REFIID riid, LCID lcid,
159 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
160 EXCEPINFO* pExcepInfo, UINT* puArgErr )
162 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
166 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
167 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
169 hr = get_typeinfo(IXMLDOMProcessingInstruction_tid, &typeinfo);
172 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
173 pVarResult, pExcepInfo, puArgErr);
174 ITypeInfo_Release(typeinfo);
180 static HRESULT WINAPI dom_pi_get_nodeName(
181 IXMLDOMProcessingInstruction *iface,
184 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
185 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
188 static HRESULT WINAPI dom_pi_get_nodeValue(
189 IXMLDOMProcessingInstruction *iface,
192 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
193 return IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
196 static HRESULT WINAPI dom_pi_put_nodeValue(
197 IXMLDOMProcessingInstruction *iface,
200 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
202 static const WCHAR szXML[] = {'x','m','l',0};
205 TRACE("%p\n", This );
207 /* Cannot set data to a PI node whose target is 'xml' */
208 hr = dom_pi_get_nodeName(iface, &sTarget);
211 if(lstrcmpW( sTarget, szXML) == 0)
213 SysFreeString(sTarget);
217 SysFreeString(sTarget);
220 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
223 static HRESULT WINAPI dom_pi_get_nodeType(
224 IXMLDOMProcessingInstruction *iface,
225 DOMNodeType* domNodeType )
227 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
228 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
231 static HRESULT WINAPI dom_pi_get_parentNode(
232 IXMLDOMProcessingInstruction *iface,
233 IXMLDOMNode** parent )
235 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
236 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
239 static HRESULT WINAPI dom_pi_get_childNodes(
240 IXMLDOMProcessingInstruction *iface,
241 IXMLDOMNodeList** outList)
243 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
244 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
247 static HRESULT WINAPI dom_pi_get_firstChild(
248 IXMLDOMProcessingInstruction *iface,
249 IXMLDOMNode** domNode)
251 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
252 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
255 static HRESULT WINAPI dom_pi_get_lastChild(
256 IXMLDOMProcessingInstruction *iface,
257 IXMLDOMNode** domNode)
259 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
260 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
263 static HRESULT WINAPI dom_pi_get_previousSibling(
264 IXMLDOMProcessingInstruction *iface,
265 IXMLDOMNode** domNode)
267 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
268 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
271 static HRESULT WINAPI dom_pi_get_nextSibling(
272 IXMLDOMProcessingInstruction *iface,
273 IXMLDOMNode** domNode)
275 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
276 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
279 static HRESULT WINAPI dom_pi_get_attributes(
280 IXMLDOMProcessingInstruction *iface,
281 IXMLDOMNamedNodeMap** attributeMap)
283 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
284 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
287 static HRESULT WINAPI dom_pi_insertBefore(
288 IXMLDOMProcessingInstruction *iface,
289 IXMLDOMNode* newNode, VARIANT var1,
290 IXMLDOMNode** outOldNode)
292 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
293 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
296 static HRESULT WINAPI dom_pi_replaceChild(
297 IXMLDOMProcessingInstruction *iface,
298 IXMLDOMNode* newNode,
299 IXMLDOMNode* oldNode,
300 IXMLDOMNode** outOldNode)
302 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
303 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
306 static HRESULT WINAPI dom_pi_removeChild(
307 IXMLDOMProcessingInstruction *iface,
308 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
310 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
311 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
314 static HRESULT WINAPI dom_pi_appendChild(
315 IXMLDOMProcessingInstruction *iface,
316 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
318 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
319 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
322 static HRESULT WINAPI dom_pi_hasChildNodes(
323 IXMLDOMProcessingInstruction *iface,
326 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
327 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
330 static HRESULT WINAPI dom_pi_get_ownerDocument(
331 IXMLDOMProcessingInstruction *iface,
332 IXMLDOMDocument** domDocument)
334 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
335 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
338 static HRESULT WINAPI dom_pi_cloneNode(
339 IXMLDOMProcessingInstruction *iface,
340 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
342 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
343 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
346 static HRESULT WINAPI dom_pi_get_nodeTypeString(
347 IXMLDOMProcessingInstruction *iface,
350 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
351 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
354 static HRESULT WINAPI dom_pi_get_text(
355 IXMLDOMProcessingInstruction *iface,
358 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
359 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
362 static HRESULT WINAPI dom_pi_put_text(
363 IXMLDOMProcessingInstruction *iface,
366 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
367 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
370 static HRESULT WINAPI dom_pi_get_specified(
371 IXMLDOMProcessingInstruction *iface,
374 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
375 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
378 static HRESULT WINAPI dom_pi_get_definition(
379 IXMLDOMProcessingInstruction *iface,
380 IXMLDOMNode** domNode)
382 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
383 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
386 static HRESULT WINAPI dom_pi_get_nodeTypedValue(
387 IXMLDOMProcessingInstruction *iface,
390 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
391 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
394 static HRESULT WINAPI dom_pi_put_nodeTypedValue(
395 IXMLDOMProcessingInstruction *iface,
398 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
399 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
402 static HRESULT WINAPI dom_pi_get_dataType(
403 IXMLDOMProcessingInstruction *iface,
406 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
407 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
410 static HRESULT WINAPI dom_pi_put_dataType(
411 IXMLDOMProcessingInstruction *iface,
414 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
415 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
418 static HRESULT WINAPI dom_pi_get_xml(
419 IXMLDOMProcessingInstruction *iface,
422 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
423 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
426 static HRESULT WINAPI dom_pi_transformNode(
427 IXMLDOMProcessingInstruction *iface,
428 IXMLDOMNode* domNode, BSTR* p)
430 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
431 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
434 static HRESULT WINAPI dom_pi_selectNodes(
435 IXMLDOMProcessingInstruction *iface,
436 BSTR p, IXMLDOMNodeList** outList)
438 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
439 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
442 static HRESULT WINAPI dom_pi_selectSingleNode(
443 IXMLDOMProcessingInstruction *iface,
444 BSTR p, IXMLDOMNode** outNode)
446 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
447 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
450 static HRESULT WINAPI dom_pi_get_parsed(
451 IXMLDOMProcessingInstruction *iface,
454 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
455 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
458 static HRESULT WINAPI dom_pi_get_namespaceURI(
459 IXMLDOMProcessingInstruction *iface,
462 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
463 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
466 static HRESULT WINAPI dom_pi_get_prefix(
467 IXMLDOMProcessingInstruction *iface,
470 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
471 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
474 static HRESULT WINAPI dom_pi_get_baseName(
475 IXMLDOMProcessingInstruction *iface,
478 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
479 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
482 static HRESULT WINAPI dom_pi_transformNodeToObject(
483 IXMLDOMProcessingInstruction *iface,
484 IXMLDOMNode* domNode, VARIANT var1)
486 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
487 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
490 static HRESULT WINAPI dom_pi_get_target(
491 IXMLDOMProcessingInstruction *iface,
494 /* target returns the same value as nodeName property */
495 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
496 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
499 static HRESULT WINAPI dom_pi_get_data(
500 IXMLDOMProcessingInstruction *iface,
503 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
510 hr = IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), &vRet );
519 static HRESULT WINAPI dom_pi_put_data(
520 IXMLDOMProcessingInstruction *iface,
523 dom_pi *This = impl_from_IXMLDOMProcessingInstruction( iface );
527 static const WCHAR szXML[] = {'x','m','l',0};
529 TRACE("%p %s\n", This, debugstr_w(data) );
531 /* Cannot set data to a PI node whose target is 'xml' */
532 hr = dom_pi_get_nodeName(iface, &sTarget);
535 if(lstrcmpW( sTarget, szXML) == 0)
537 SysFreeString(sTarget);
541 SysFreeString(sTarget);
544 V_VT(&val) = VT_BSTR;
547 hr = IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), val );
552 static const struct IXMLDOMProcessingInstructionVtbl dom_pi_vtbl =
554 dom_pi_QueryInterface,
557 dom_pi_GetTypeInfoCount,
559 dom_pi_GetIDsOfNames,
562 dom_pi_get_nodeValue,
563 dom_pi_put_nodeValue,
565 dom_pi_get_parentNode,
566 dom_pi_get_childNodes,
567 dom_pi_get_firstChild,
568 dom_pi_get_lastChild,
569 dom_pi_get_previousSibling,
570 dom_pi_get_nextSibling,
571 dom_pi_get_attributes,
576 dom_pi_hasChildNodes,
577 dom_pi_get_ownerDocument,
579 dom_pi_get_nodeTypeString,
582 dom_pi_get_specified,
583 dom_pi_get_definition,
584 dom_pi_get_nodeTypedValue,
585 dom_pi_put_nodeTypedValue,
589 dom_pi_transformNode,
591 dom_pi_selectSingleNode,
593 dom_pi_get_namespaceURI,
596 dom_pi_transformNodeToObject,
603 IUnknown* create_pi( xmlNodePtr pi )
607 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
611 This->lpVtbl = &dom_pi_vtbl;
614 init_xmlnode(&This->node, pi, (IUnknown*)&This->lpVtbl, NULL);
616 return (IUnknown*) &This->lpVtbl;