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
33 #include "msxml_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
41 typedef struct _domelem
43 const struct IXMLDOMElementVtbl *lpVtbl;
44 const struct IUnknownVtbl *lpInternalUnkVtbl;
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,
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,
95 domelem *This = impl_from_IXMLDOMElement( iface );
97 TRACE("(%p)->(%p)\n", This, pctinfo);
104 static HRESULT WINAPI domelem_GetTypeInfo(
105 IXMLDOMElement *iface,
106 UINT iTInfo, LCID lcid,
107 ITypeInfo** ppTInfo )
109 domelem *This = impl_from_IXMLDOMElement( iface );
112 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
114 hr = get_typeinfo(IXMLDOMElement_tid, ppTInfo);
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 );
128 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
131 if(!rgszNames || cNames == 0 || !rgDispId)
134 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
137 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
138 ITypeInfo_Release(typeinfo);
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 );
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);
160 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
161 pVarResult, pExcepInfo, puArgErr);
162 ITypeInfo_Release(typeinfo);
168 static HRESULT WINAPI domelem_get_nodeName(
169 IXMLDOMElement *iface,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
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,
463 domelem *This = impl_from_IXMLDOMElement( iface );
469 TRACE("%p\n", This );
474 element = get_element( This );
478 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, NULL, 0 );
480 len += MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, NULL, 0 );
481 str = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
483 return E_OUTOFMEMORY;
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 );
496 static HRESULT WINAPI domelem_getAttribute(
497 IXMLDOMElement *iface,
498 BSTR name, VARIANT* value)
500 domelem *This = impl_from_IXMLDOMElement( iface );
502 xmlChar *xml_name, *xml_value = NULL;
503 HRESULT hr = S_FALSE;
505 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), value);
510 element = get_element( This );
514 V_BSTR(value) = NULL;
515 V_VT(value) = VT_NULL;
517 xml_name = xmlChar_from_wchar( name );
519 if(!xmlValidateNameValue(xml_name))
522 xml_value = xmlGetNsProp(element, xml_name, NULL);
524 HeapFree(GetProcessHeap(), 0, xml_name);
527 V_VT(value) = VT_BSTR;
528 V_BSTR(value) = bstr_from_xmlChar( xml_value );
536 static HRESULT WINAPI domelem_setAttribute(
537 IXMLDOMElement *iface,
538 BSTR name, VARIANT value)
540 domelem *This = impl_from_IXMLDOMElement( iface );
542 xmlChar *xml_name, *xml_value;
546 TRACE("(%p)->(%s, var)\n", This, debugstr_w(name));
548 element = get_element( This );
553 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
556 FIXME("VariantChangeType failed\n");
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))
566 HeapFree(GetProcessHeap(), 0, xml_value);
567 HeapFree(GetProcessHeap(), 0, xml_name);
573 static HRESULT WINAPI domelem_removeAttribute(
574 IXMLDOMElement *iface,
581 static HRESULT WINAPI domelem_getAttributeNode(
582 IXMLDOMElement *iface,
583 BSTR p, IXMLDOMAttribute** attributeNode )
585 domelem *This = impl_from_IXMLDOMElement( iface );
590 HRESULT hr = S_FALSE;
592 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
597 *attributeNode = NULL;
599 element = get_element( This );
603 xml_name = xmlChar_from_wchar(p);
605 if(!xmlValidateNameValue(xml_name))
607 HeapFree(GetProcessHeap(), 0, xml_name);
611 attr = xmlHasProp(element, xml_name);
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);
623 static HRESULT WINAPI domelem_setAttributeNode(
624 IXMLDOMElement *iface,
625 IXMLDOMAttribute* domAttribute,
626 IXMLDOMAttribute** attributeNode)
632 static HRESULT WINAPI domelem_removeAttributeNode(
633 IXMLDOMElement *iface,
634 IXMLDOMAttribute* domAttribute,
635 IXMLDOMAttribute** attributeNode)
641 static HRESULT WINAPI domelem_getElementsByTagName(
642 IXMLDOMElement *iface,
643 BSTR bstrName, IXMLDOMNodeList** resultList)
645 domelem *This = impl_from_IXMLDOMElement( iface );
649 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(bstrName), resultList);
651 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(3+lstrlenW(bstrName)+1));
653 szPattern[1] = szPattern[2] = '/';
654 lstrcpyW(szPattern+3, bstrName);
655 TRACE("%s\n", debugstr_w(szPattern));
657 hr = queryresult_create(get_element(This), szPattern, resultList);
658 HeapFree(GetProcessHeap(), 0, szPattern);
663 static HRESULT WINAPI domelem_normalize(
664 IXMLDOMElement *iface )
670 static const struct IXMLDOMElementVtbl domelem_vtbl =
672 domelem_QueryInterface,
675 domelem_GetTypeInfoCount,
677 domelem_GetIDsOfNames,
679 domelem_get_nodeName,
680 domelem_get_nodeValue,
681 domelem_put_nodeValue,
682 domelem_get_nodeType,
683 domelem_get_parentNode,
684 domelem_get_childNodes,
685 domelem_get_firstChild,
686 domelem_get_lastChild,
687 domelem_get_previousSibling,
688 domelem_get_nextSibling,
689 domelem_get_attributes,
690 domelem_insertBefore,
691 domelem_replaceChild,
694 domelem_hasChildNodes,
695 domelem_get_ownerDocument,
697 domelem_get_nodeTypeString,
700 domelem_get_specified,
701 domelem_get_definition,
702 domelem_get_nodeTypedValue,
703 domelem_put_nodeTypedValue,
704 domelem_get_dataType,
705 domelem_put_dataType,
707 domelem_transformNode,
709 domelem_selectSingleNode,
711 domelem_get_namespaceURI,
713 domelem_get_baseName,
714 domelem_transformNodeToObject,
716 domelem_getAttribute,
717 domelem_setAttribute,
718 domelem_removeAttribute,
719 domelem_getAttributeNode,
720 domelem_setAttributeNode,
721 domelem_removeAttributeNode,
722 domelem_getElementsByTagName,
726 static HRESULT WINAPI Internal_QueryInterface(
731 domelem *This = impl_from_InternalUnknown( iface );
732 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
734 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
735 IsEqualGUID( riid, &IID_IDispatch ) ||
736 IsEqualGUID( riid, &IID_IUnknown ) )
738 *ppvObject = &This->lpVtbl;
740 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
742 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
746 FIXME("interface %s not implemented\n", debugstr_guid(riid));
747 return E_NOINTERFACE;
750 IUnknown_AddRef( (IUnknown*)*ppvObject );
755 static ULONG WINAPI Internal_AddRef(
758 domelem *This = impl_from_InternalUnknown( iface );
759 return InterlockedIncrement( &This->ref );
762 static ULONG WINAPI Internal_Release(
765 domelem *This = impl_from_InternalUnknown( iface );
768 ref = InterlockedDecrement( &This->ref );
771 IUnknown_Release( This->node_unk );
772 HeapFree( GetProcessHeap(), 0, This );
778 static const struct IUnknownVtbl internal_unk_vtbl =
780 Internal_QueryInterface,
785 IUnknown* create_element( xmlNodePtr element, IUnknown *pUnkOuter )
790 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
794 This->lpVtbl = &domelem_vtbl;
796 This->lpInternalUnkVtbl = &internal_unk_vtbl;
799 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
801 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
803 This->node_unk = create_basic_node( element, (IUnknown*)&This->lpVtbl );
806 HeapFree(GetProcessHeap(), 0, This);
810 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
813 IUnknown_Release(This->node_unk);
814 HeapFree( GetProcessHeap(), 0, This );
817 /* The ref on This->node is actually looped back into this object, so release it */
818 IXMLDOMNode_Release(This->node);
820 return (IUnknown*) &This->lpInternalUnkVtbl;