msxml3: Do not cast void pointers to other pointer types.
[wine/hacks.git] / dlls / msxml3 / element.c
bloba31f80ef799bb55602b7301a7fff55b7e6d46e7e
1 /*
2 * DOM Document implementation
4 * Copyright 2005 Mike McCormack
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
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "ole2.h"
31 #include "msxml2.h"
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
39 #ifdef HAVE_LIBXML2
41 typedef struct _domelem
43 const struct IXMLDOMElementVtbl *lpVtbl;
44 const struct IUnknownVtbl *lpInternalUnkVtbl;
45 IUnknown *pUnkOuter;
46 LONG ref;
47 IUnknown *node_unk;
48 IXMLDOMNode *node;
49 } domelem;
51 static inline domelem *impl_from_IXMLDOMElement( IXMLDOMElement *iface )
53 return (domelem *)((char*)iface - FIELD_OFFSET(domelem, lpVtbl));
56 static inline domelem *impl_from_InternalUnknown( IUnknown *iface )
58 return (domelem *)((char*)iface - FIELD_OFFSET(domelem, lpInternalUnkVtbl));
61 static inline xmlNodePtr get_element( domelem *This )
63 return xmlNodePtr_from_domnode( This->node, XML_ELEMENT_NODE );
66 static HRESULT WINAPI domelem_QueryInterface(
67 IXMLDOMElement *iface,
68 REFIID riid,
69 void** ppvObject )
71 domelem *This = impl_from_IXMLDOMElement( iface );
72 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
74 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
77 static ULONG WINAPI domelem_AddRef(
78 IXMLDOMElement *iface )
80 domelem *This = impl_from_IXMLDOMElement( iface );
81 return IUnknown_AddRef(This->pUnkOuter);
84 static ULONG WINAPI domelem_Release(
85 IXMLDOMElement *iface )
87 domelem *This = impl_from_IXMLDOMElement( iface );
88 return IUnknown_Release(This->pUnkOuter);
91 static HRESULT WINAPI domelem_GetTypeInfoCount(
92 IXMLDOMElement *iface,
93 UINT* pctinfo )
95 domelem *This = impl_from_IXMLDOMElement( iface );
97 TRACE("(%p)->(%p)\n", This, pctinfo);
99 *pctinfo = 1;
101 return S_OK;
104 static HRESULT WINAPI domelem_GetTypeInfo(
105 IXMLDOMElement *iface,
106 UINT iTInfo, LCID lcid,
107 ITypeInfo** ppTInfo )
109 domelem *This = impl_from_IXMLDOMElement( iface );
110 HRESULT hr;
112 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
114 hr = get_typeinfo(IXMLDOMElement_tid, ppTInfo);
116 return hr;
119 static HRESULT WINAPI domelem_GetIDsOfNames(
120 IXMLDOMElement *iface,
121 REFIID riid, LPOLESTR* rgszNames,
122 UINT cNames, LCID lcid, DISPID* rgDispId )
124 domelem *This = impl_from_IXMLDOMElement( iface );
125 ITypeInfo *typeinfo;
126 HRESULT hr;
128 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
129 lcid, rgDispId);
131 if(!rgszNames || cNames == 0 || !rgDispId)
132 return E_INVALIDARG;
134 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
135 if(SUCCEEDED(hr))
137 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
138 ITypeInfo_Release(typeinfo);
141 return hr;
144 static HRESULT WINAPI domelem_Invoke(
145 IXMLDOMElement *iface,
146 DISPID dispIdMember, REFIID riid, LCID lcid,
147 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
148 EXCEPINFO* pExcepInfo, UINT* puArgErr )
150 domelem *This = impl_from_IXMLDOMElement( iface );
151 ITypeInfo *typeinfo;
152 HRESULT hr;
154 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
155 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
157 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
158 if(SUCCEEDED(hr))
160 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
161 pVarResult, pExcepInfo, puArgErr);
162 ITypeInfo_Release(typeinfo);
165 return hr;
168 static HRESULT WINAPI domelem_get_nodeName(
169 IXMLDOMElement *iface,
170 BSTR* p )
172 domelem *This = impl_from_IXMLDOMElement( iface );
173 return IXMLDOMNode_get_nodeName( This->node, p );
176 static HRESULT WINAPI domelem_get_nodeValue(
177 IXMLDOMElement *iface,
178 VARIANT* var1 )
180 domelem *This = impl_from_IXMLDOMElement( iface );
181 return IXMLDOMNode_get_nodeValue( This->node, var1 );
184 static HRESULT WINAPI domelem_put_nodeValue(
185 IXMLDOMElement *iface,
186 VARIANT var1 )
188 domelem *This = impl_from_IXMLDOMElement( iface );
189 return IXMLDOMNode_put_nodeValue( This->node, var1 );
192 static HRESULT WINAPI domelem_get_nodeType(
193 IXMLDOMElement *iface,
194 DOMNodeType* domNodeType )
196 domelem *This = impl_from_IXMLDOMElement( iface );
197 return IXMLDOMNode_get_nodeType( This->node, domNodeType );
200 static HRESULT WINAPI domelem_get_parentNode(
201 IXMLDOMElement *iface,
202 IXMLDOMNode** parent )
204 domelem *This = impl_from_IXMLDOMElement( iface );
205 return IXMLDOMNode_get_parentNode( This->node, parent );
208 static HRESULT WINAPI domelem_get_childNodes(
209 IXMLDOMElement *iface,
210 IXMLDOMNodeList** outList)
212 domelem *This = impl_from_IXMLDOMElement( iface );
213 return IXMLDOMNode_get_childNodes( This->node, outList );
216 static HRESULT WINAPI domelem_get_firstChild(
217 IXMLDOMElement *iface,
218 IXMLDOMNode** domNode)
220 domelem *This = impl_from_IXMLDOMElement( iface );
221 return IXMLDOMNode_get_firstChild( This->node, domNode );
224 static HRESULT WINAPI domelem_get_lastChild(
225 IXMLDOMElement *iface,
226 IXMLDOMNode** domNode)
228 domelem *This = impl_from_IXMLDOMElement( iface );
229 return IXMLDOMNode_get_lastChild( This->node, domNode );
232 static HRESULT WINAPI domelem_get_previousSibling(
233 IXMLDOMElement *iface,
234 IXMLDOMNode** domNode)
236 domelem *This = impl_from_IXMLDOMElement( iface );
237 return IXMLDOMNode_get_previousSibling( This->node, domNode );
240 static HRESULT WINAPI domelem_get_nextSibling(
241 IXMLDOMElement *iface,
242 IXMLDOMNode** domNode)
244 domelem *This = impl_from_IXMLDOMElement( iface );
245 return IXMLDOMNode_get_nextSibling( This->node, domNode );
248 static HRESULT WINAPI domelem_get_attributes(
249 IXMLDOMElement *iface,
250 IXMLDOMNamedNodeMap** attributeMap)
252 domelem *This = impl_from_IXMLDOMElement( iface );
253 return IXMLDOMNode_get_attributes( This->node, attributeMap );
256 static HRESULT WINAPI domelem_insertBefore(
257 IXMLDOMElement *iface,
258 IXMLDOMNode* newNode, VARIANT var1,
259 IXMLDOMNode** outOldNode)
261 domelem *This = impl_from_IXMLDOMElement( iface );
262 return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
265 static HRESULT WINAPI domelem_replaceChild(
266 IXMLDOMElement *iface,
267 IXMLDOMNode* newNode,
268 IXMLDOMNode* oldNode,
269 IXMLDOMNode** outOldNode)
271 domelem *This = impl_from_IXMLDOMElement( iface );
272 return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
275 static HRESULT WINAPI domelem_removeChild(
276 IXMLDOMElement *iface,
277 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
279 domelem *This = impl_from_IXMLDOMElement( iface );
280 return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
283 static HRESULT WINAPI domelem_appendChild(
284 IXMLDOMElement *iface,
285 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
287 domelem *This = impl_from_IXMLDOMElement( iface );
288 return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
291 static HRESULT WINAPI domelem_hasChildNodes(
292 IXMLDOMElement *iface,
293 VARIANT_BOOL* pbool)
295 domelem *This = impl_from_IXMLDOMElement( iface );
296 return IXMLDOMNode_hasChildNodes( This->node, pbool );
299 static HRESULT WINAPI domelem_get_ownerDocument(
300 IXMLDOMElement *iface,
301 IXMLDOMDocument** domDocument)
303 domelem *This = impl_from_IXMLDOMElement( iface );
304 return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
307 static HRESULT WINAPI domelem_cloneNode(
308 IXMLDOMElement *iface,
309 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
311 domelem *This = impl_from_IXMLDOMElement( iface );
312 return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
315 static HRESULT WINAPI domelem_get_nodeTypeString(
316 IXMLDOMElement *iface,
317 BSTR* p)
319 domelem *This = impl_from_IXMLDOMElement( iface );
320 return IXMLDOMNode_get_nodeTypeString( This->node, p );
323 static HRESULT WINAPI domelem_get_text(
324 IXMLDOMElement *iface,
325 BSTR* p)
327 domelem *This = impl_from_IXMLDOMElement( iface );
328 return IXMLDOMNode_get_text( This->node, p );
331 static HRESULT WINAPI domelem_put_text(
332 IXMLDOMElement *iface,
333 BSTR p)
335 domelem *This = impl_from_IXMLDOMElement( iface );
336 return IXMLDOMNode_put_text( This->node, p );
339 static HRESULT WINAPI domelem_get_specified(
340 IXMLDOMElement *iface,
341 VARIANT_BOOL* pbool)
343 domelem *This = impl_from_IXMLDOMElement( iface );
344 return IXMLDOMNode_get_specified( This->node, pbool );
347 static HRESULT WINAPI domelem_get_definition(
348 IXMLDOMElement *iface,
349 IXMLDOMNode** domNode)
351 domelem *This = impl_from_IXMLDOMElement( iface );
352 return IXMLDOMNode_get_definition( This->node, domNode );
355 static HRESULT WINAPI domelem_get_nodeTypedValue(
356 IXMLDOMElement *iface,
357 VARIANT* var1)
359 domelem *This = impl_from_IXMLDOMElement( iface );
360 return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
363 static HRESULT WINAPI domelem_put_nodeTypedValue(
364 IXMLDOMElement *iface,
365 VARIANT var1)
367 domelem *This = impl_from_IXMLDOMElement( iface );
368 return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
371 static HRESULT WINAPI domelem_get_dataType(
372 IXMLDOMElement *iface,
373 VARIANT* var1)
375 domelem *This = impl_from_IXMLDOMElement( iface );
376 return IXMLDOMNode_get_dataType( This->node, var1 );
379 static HRESULT WINAPI domelem_put_dataType(
380 IXMLDOMElement *iface,
381 BSTR p)
383 domelem *This = impl_from_IXMLDOMElement( iface );
384 return IXMLDOMNode_put_dataType( This->node, p );
387 static HRESULT WINAPI domelem_get_xml(
388 IXMLDOMElement *iface,
389 BSTR* p)
391 domelem *This = impl_from_IXMLDOMElement( iface );
392 return IXMLDOMNode_get_xml( This->node, p );
395 static HRESULT WINAPI domelem_transformNode(
396 IXMLDOMElement *iface,
397 IXMLDOMNode* domNode, BSTR* p)
399 domelem *This = impl_from_IXMLDOMElement( iface );
400 return IXMLDOMNode_transformNode( This->node, domNode, p );
403 static HRESULT WINAPI domelem_selectNodes(
404 IXMLDOMElement *iface,
405 BSTR p, IXMLDOMNodeList** outList)
407 domelem *This = impl_from_IXMLDOMElement( iface );
408 return IXMLDOMNode_selectNodes( This->node, p, outList );
411 static HRESULT WINAPI domelem_selectSingleNode(
412 IXMLDOMElement *iface,
413 BSTR p, IXMLDOMNode** outNode)
415 domelem *This = impl_from_IXMLDOMElement( iface );
416 return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
419 static HRESULT WINAPI domelem_get_parsed(
420 IXMLDOMElement *iface,
421 VARIANT_BOOL* pbool)
423 domelem *This = impl_from_IXMLDOMElement( iface );
424 return IXMLDOMNode_get_parsed( This->node, pbool );
427 static HRESULT WINAPI domelem_get_namespaceURI(
428 IXMLDOMElement *iface,
429 BSTR* p)
431 domelem *This = impl_from_IXMLDOMElement( iface );
432 return IXMLDOMNode_get_namespaceURI( This->node, p );
435 static HRESULT WINAPI domelem_get_prefix(
436 IXMLDOMElement *iface,
437 BSTR* p)
439 domelem *This = impl_from_IXMLDOMElement( iface );
440 return IXMLDOMNode_get_prefix( This->node, p );
443 static HRESULT WINAPI domelem_get_baseName(
444 IXMLDOMElement *iface,
445 BSTR* p)
447 domelem *This = impl_from_IXMLDOMElement( iface );
448 return IXMLDOMNode_get_baseName( This->node, p );
451 static HRESULT WINAPI domelem_transformNodeToObject(
452 IXMLDOMElement *iface,
453 IXMLDOMNode* domNode, VARIANT var1)
455 domelem *This = impl_from_IXMLDOMElement( iface );
456 return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
459 static HRESULT WINAPI domelem_get_tagName(
460 IXMLDOMElement *iface,
461 BSTR* p)
463 domelem *This = impl_from_IXMLDOMElement( iface );
464 xmlNodePtr element;
465 DWORD len;
466 DWORD offset = 0;
467 LPWSTR str;
469 TRACE("%p\n", This );
471 if ( !This->node )
472 return E_FAIL;
474 element = get_element( This );
475 if ( !element )
476 return E_FAIL;
478 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, NULL, 0 );
479 if (element->ns)
480 len += MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, NULL, 0 );
481 str = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
482 if ( !str )
483 return E_OUTOFMEMORY;
484 if (element->ns)
486 offset = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, str, len );
487 str[offset - 1] = ':';
489 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, str + offset, len - offset );
490 *p = SysAllocString( str );
491 HeapFree( GetProcessHeap(), 0, str );
493 return S_OK;
496 static HRESULT WINAPI domelem_getAttribute(
497 IXMLDOMElement *iface,
498 BSTR name, VARIANT* value)
500 domelem *This = impl_from_IXMLDOMElement( iface );
501 xmlNodePtr element;
502 xmlChar *xml_name, *xml_value = NULL;
503 HRESULT hr = S_FALSE;
505 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), value);
507 if(!value || !name)
508 return E_INVALIDARG;
510 element = get_element( This );
511 if ( !element )
512 return E_FAIL;
514 V_BSTR(value) = NULL;
515 V_VT(value) = VT_NULL;
517 xml_name = xmlChar_from_wchar( name );
519 if(!xmlValidateNameValue(xml_name))
520 hr = E_FAIL;
521 else
522 xml_value = xmlGetNsProp(element, xml_name, NULL);
524 HeapFree(GetProcessHeap(), 0, xml_name);
525 if(xml_value)
527 V_VT(value) = VT_BSTR;
528 V_BSTR(value) = bstr_from_xmlChar( xml_value );
529 xmlFree(xml_value);
530 hr = S_OK;
533 return hr;
536 static HRESULT WINAPI domelem_setAttribute(
537 IXMLDOMElement *iface,
538 BSTR name, VARIANT value)
540 domelem *This = impl_from_IXMLDOMElement( iface );
541 xmlNodePtr element;
542 xmlChar *xml_name, *xml_value;
543 HRESULT hr;
544 VARIANT var;
546 TRACE("(%p)->(%s, var)\n", This, debugstr_w(name));
548 element = get_element( This );
549 if ( !element )
550 return E_FAIL;
552 VariantInit(&var);
553 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
554 if(hr != S_OK)
556 FIXME("VariantChangeType failed\n");
557 return hr;
560 xml_name = xmlChar_from_wchar( name );
561 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
563 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
564 hr = E_FAIL;
566 HeapFree(GetProcessHeap(), 0, xml_value);
567 HeapFree(GetProcessHeap(), 0, xml_name);
568 VariantClear(&var);
570 return hr;
573 static HRESULT WINAPI domelem_removeAttribute(
574 IXMLDOMElement *iface,
575 BSTR p)
577 FIXME("\n");
578 return E_NOTIMPL;
581 static HRESULT WINAPI domelem_getAttributeNode(
582 IXMLDOMElement *iface,
583 BSTR p, IXMLDOMAttribute** attributeNode )
585 domelem *This = impl_from_IXMLDOMElement( iface );
586 xmlChar *xml_name;
587 xmlNodePtr element;
588 xmlAttrPtr attr;
589 IUnknown *unk;
590 HRESULT hr = E_FAIL;
592 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
594 element = get_element( This );
595 if ( !element )
596 return E_FAIL;
598 xml_name = xmlChar_from_wchar(p);
600 attr = xmlHasProp(element, xml_name);
601 if(attr) {
602 unk = create_attribute((xmlNodePtr)attr);
603 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
604 IUnknown_Release(unk);
605 }else {
606 *attributeNode = NULL;
609 HeapFree(GetProcessHeap(), 0, xml_name);
611 return hr;
614 static HRESULT WINAPI domelem_setAttributeNode(
615 IXMLDOMElement *iface,
616 IXMLDOMAttribute* domAttribute,
617 IXMLDOMAttribute** attributeNode)
619 FIXME("\n");
620 return E_NOTIMPL;
623 static HRESULT WINAPI domelem_removeAttributeNode(
624 IXMLDOMElement *iface,
625 IXMLDOMAttribute* domAttribute,
626 IXMLDOMAttribute** attributeNode)
628 FIXME("\n");
629 return E_NOTIMPL;
632 static HRESULT WINAPI domelem_getElementsByTagName(
633 IXMLDOMElement *iface,
634 BSTR bstrName, IXMLDOMNodeList** resultList)
636 domelem *This = impl_from_IXMLDOMElement( iface );
637 LPWSTR szPattern;
638 HRESULT hr;
640 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(bstrName), resultList);
642 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(3+lstrlenW(bstrName)+1));
643 szPattern[0] = '.';
644 szPattern[1] = szPattern[2] = '/';
645 lstrcpyW(szPattern+3, bstrName);
646 TRACE("%s\n", debugstr_w(szPattern));
648 hr = queryresult_create(get_element(This), szPattern, resultList);
649 HeapFree(GetProcessHeap(), 0, szPattern);
651 return hr;
654 static HRESULT WINAPI domelem_normalize(
655 IXMLDOMElement *iface )
657 FIXME("\n");
658 return E_NOTIMPL;
661 static const struct IXMLDOMElementVtbl domelem_vtbl =
663 domelem_QueryInterface,
664 domelem_AddRef,
665 domelem_Release,
666 domelem_GetTypeInfoCount,
667 domelem_GetTypeInfo,
668 domelem_GetIDsOfNames,
669 domelem_Invoke,
670 domelem_get_nodeName,
671 domelem_get_nodeValue,
672 domelem_put_nodeValue,
673 domelem_get_nodeType,
674 domelem_get_parentNode,
675 domelem_get_childNodes,
676 domelem_get_firstChild,
677 domelem_get_lastChild,
678 domelem_get_previousSibling,
679 domelem_get_nextSibling,
680 domelem_get_attributes,
681 domelem_insertBefore,
682 domelem_replaceChild,
683 domelem_removeChild,
684 domelem_appendChild,
685 domelem_hasChildNodes,
686 domelem_get_ownerDocument,
687 domelem_cloneNode,
688 domelem_get_nodeTypeString,
689 domelem_get_text,
690 domelem_put_text,
691 domelem_get_specified,
692 domelem_get_definition,
693 domelem_get_nodeTypedValue,
694 domelem_put_nodeTypedValue,
695 domelem_get_dataType,
696 domelem_put_dataType,
697 domelem_get_xml,
698 domelem_transformNode,
699 domelem_selectNodes,
700 domelem_selectSingleNode,
701 domelem_get_parsed,
702 domelem_get_namespaceURI,
703 domelem_get_prefix,
704 domelem_get_baseName,
705 domelem_transformNodeToObject,
706 domelem_get_tagName,
707 domelem_getAttribute,
708 domelem_setAttribute,
709 domelem_removeAttribute,
710 domelem_getAttributeNode,
711 domelem_setAttributeNode,
712 domelem_removeAttributeNode,
713 domelem_getElementsByTagName,
714 domelem_normalize,
717 static HRESULT WINAPI Internal_QueryInterface(
718 IUnknown *iface,
719 REFIID riid,
720 void** ppvObject )
722 domelem *This = impl_from_InternalUnknown( iface );
723 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
725 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
726 IsEqualGUID( riid, &IID_IDispatch ) ||
727 IsEqualGUID( riid, &IID_IUnknown ) )
729 *ppvObject = &This->lpVtbl;
731 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
733 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
735 else
737 FIXME("interface %s not implemented\n", debugstr_guid(riid));
738 return E_NOINTERFACE;
741 IUnknown_AddRef( (IUnknown*)*ppvObject );
743 return S_OK;
746 static ULONG WINAPI Internal_AddRef(
747 IUnknown *iface )
749 domelem *This = impl_from_InternalUnknown( iface );
750 return InterlockedIncrement( &This->ref );
753 static ULONG WINAPI Internal_Release(
754 IUnknown *iface )
756 domelem *This = impl_from_InternalUnknown( iface );
757 ULONG ref;
759 ref = InterlockedDecrement( &This->ref );
760 if ( ref == 0 )
762 IUnknown_Release( This->node_unk );
763 HeapFree( GetProcessHeap(), 0, This );
766 return ref;
769 static const struct IUnknownVtbl internal_unk_vtbl =
771 Internal_QueryInterface,
772 Internal_AddRef,
773 Internal_Release
776 IUnknown* create_element( xmlNodePtr element, IUnknown *pUnkOuter )
778 domelem *This;
779 HRESULT hr;
781 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
782 if ( !This )
783 return NULL;
785 This->lpVtbl = &domelem_vtbl;
786 This->ref = 1;
787 This->lpInternalUnkVtbl = &internal_unk_vtbl;
789 if(pUnkOuter)
790 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
791 else
792 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
794 This->node_unk = create_basic_node( element, (IUnknown*)&This->lpVtbl );
795 if(!This->node_unk)
797 HeapFree(GetProcessHeap(), 0, This);
798 return NULL;
801 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
802 if(FAILED(hr))
804 IUnknown_Release(This->node_unk);
805 HeapFree( GetProcessHeap(), 0, This );
806 return NULL;
808 /* The ref on This->node is actually looped back into this object, so release it */
809 IXMLDOMNode_Release(This->node);
811 return (IUnknown*) &This->lpInternalUnkVtbl;
814 #endif