msvcrt/tests: Remove a space before a '\n'.
[wine/gsoc-2012-control.git] / dlls / msxml3 / element.c
blob4f0bce93acc9845504f8c4fc59d8d8fe2702083e
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 = S_FALSE;
592 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
594 if(!attributeNode)
595 return E_FAIL;
597 *attributeNode = NULL;
599 element = get_element( This );
600 if ( !element )
601 return E_FAIL;
603 xml_name = xmlChar_from_wchar(p);
605 if(!xmlValidateNameValue(xml_name))
607 HeapFree(GetProcessHeap(), 0, xml_name);
608 return E_FAIL;
611 attr = xmlHasProp(element, xml_name);
612 if(attr) {
613 unk = create_attribute((xmlNodePtr)attr);
614 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
615 IUnknown_Release(unk);
618 HeapFree(GetProcessHeap(), 0, xml_name);
620 return hr;
623 static HRESULT WINAPI domelem_setAttributeNode(
624 IXMLDOMElement *iface,
625 IXMLDOMAttribute* domAttribute,
626 IXMLDOMAttribute** attributeNode)
628 FIXME("\n");
629 return E_NOTIMPL;
632 static HRESULT WINAPI domelem_removeAttributeNode(
633 IXMLDOMElement *iface,
634 IXMLDOMAttribute* domAttribute,
635 IXMLDOMAttribute** attributeNode)
637 FIXME("\n");
638 return E_NOTIMPL;
641 static HRESULT WINAPI domelem_getElementsByTagName(
642 IXMLDOMElement *iface,
643 BSTR bstrName, IXMLDOMNodeList** resultList)
645 domelem *This = impl_from_IXMLDOMElement( iface );
646 LPWSTR szPattern;
647 xmlNodePtr element;
648 HRESULT hr;
650 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(bstrName), resultList);
652 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(3+lstrlenW(bstrName)+1));
653 szPattern[0] = '.';
654 szPattern[1] = szPattern[2] = '/';
655 lstrcpyW(szPattern+3, bstrName);
656 TRACE("%s\n", debugstr_w(szPattern));
658 element = get_element(This);
659 if (!element)
660 hr = E_FAIL;
661 else
662 hr = queryresult_create(element, szPattern, resultList);
663 HeapFree(GetProcessHeap(), 0, szPattern);
665 return hr;
668 static HRESULT WINAPI domelem_normalize(
669 IXMLDOMElement *iface )
671 FIXME("\n");
672 return E_NOTIMPL;
675 static const struct IXMLDOMElementVtbl domelem_vtbl =
677 domelem_QueryInterface,
678 domelem_AddRef,
679 domelem_Release,
680 domelem_GetTypeInfoCount,
681 domelem_GetTypeInfo,
682 domelem_GetIDsOfNames,
683 domelem_Invoke,
684 domelem_get_nodeName,
685 domelem_get_nodeValue,
686 domelem_put_nodeValue,
687 domelem_get_nodeType,
688 domelem_get_parentNode,
689 domelem_get_childNodes,
690 domelem_get_firstChild,
691 domelem_get_lastChild,
692 domelem_get_previousSibling,
693 domelem_get_nextSibling,
694 domelem_get_attributes,
695 domelem_insertBefore,
696 domelem_replaceChild,
697 domelem_removeChild,
698 domelem_appendChild,
699 domelem_hasChildNodes,
700 domelem_get_ownerDocument,
701 domelem_cloneNode,
702 domelem_get_nodeTypeString,
703 domelem_get_text,
704 domelem_put_text,
705 domelem_get_specified,
706 domelem_get_definition,
707 domelem_get_nodeTypedValue,
708 domelem_put_nodeTypedValue,
709 domelem_get_dataType,
710 domelem_put_dataType,
711 domelem_get_xml,
712 domelem_transformNode,
713 domelem_selectNodes,
714 domelem_selectSingleNode,
715 domelem_get_parsed,
716 domelem_get_namespaceURI,
717 domelem_get_prefix,
718 domelem_get_baseName,
719 domelem_transformNodeToObject,
720 domelem_get_tagName,
721 domelem_getAttribute,
722 domelem_setAttribute,
723 domelem_removeAttribute,
724 domelem_getAttributeNode,
725 domelem_setAttributeNode,
726 domelem_removeAttributeNode,
727 domelem_getElementsByTagName,
728 domelem_normalize,
731 static HRESULT WINAPI Internal_QueryInterface(
732 IUnknown *iface,
733 REFIID riid,
734 void** ppvObject )
736 domelem *This = impl_from_InternalUnknown( iface );
737 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
739 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
740 IsEqualGUID( riid, &IID_IDispatch ) ||
741 IsEqualGUID( riid, &IID_IUnknown ) )
743 *ppvObject = &This->lpVtbl;
745 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
747 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
749 else
751 FIXME("interface %s not implemented\n", debugstr_guid(riid));
752 return E_NOINTERFACE;
755 IUnknown_AddRef( (IUnknown*)*ppvObject );
757 return S_OK;
760 static ULONG WINAPI Internal_AddRef(
761 IUnknown *iface )
763 domelem *This = impl_from_InternalUnknown( iface );
764 return InterlockedIncrement( &This->ref );
767 static ULONG WINAPI Internal_Release(
768 IUnknown *iface )
770 domelem *This = impl_from_InternalUnknown( iface );
771 ULONG ref;
773 ref = InterlockedDecrement( &This->ref );
774 if ( ref == 0 )
776 IUnknown_Release( This->node_unk );
777 HeapFree( GetProcessHeap(), 0, This );
780 return ref;
783 static const struct IUnknownVtbl internal_unk_vtbl =
785 Internal_QueryInterface,
786 Internal_AddRef,
787 Internal_Release
790 IUnknown* create_element( xmlNodePtr element, IUnknown *pUnkOuter )
792 domelem *This;
793 HRESULT hr;
795 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
796 if ( !This )
797 return NULL;
799 This->lpVtbl = &domelem_vtbl;
800 This->ref = 1;
801 This->lpInternalUnkVtbl = &internal_unk_vtbl;
803 if(pUnkOuter)
804 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
805 else
806 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
808 This->node_unk = create_basic_node( element, (IUnknown*)&This->lpVtbl );
809 if(!This->node_unk)
811 HeapFree(GetProcessHeap(), 0, This);
812 return NULL;
815 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
816 if(FAILED(hr))
818 IUnknown_Release(This->node_unk);
819 HeapFree( GetProcessHeap(), 0, This );
820 return NULL;
822 /* The ref on This->node is actually looped back into this object, so release it */
823 IXMLDOMNode_Release(This->node);
825 return (IUnknown*) &This->lpInternalUnkVtbl;
828 #endif