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,
99 static HRESULT WINAPI domelem_GetTypeInfo(
100 IXMLDOMElement *iface,
101 UINT iTInfo, LCID lcid,
102 ITypeInfo** ppTInfo )
108 static HRESULT WINAPI domelem_GetIDsOfNames(
109 IXMLDOMElement *iface,
110 REFIID riid, LPOLESTR* rgszNames,
111 UINT cNames, LCID lcid, DISPID* rgDispId )
117 static HRESULT WINAPI domelem_Invoke(
118 IXMLDOMElement *iface,
119 DISPID dispIdMember, REFIID riid, LCID lcid,
120 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
121 EXCEPINFO* pExcepInfo, UINT* puArgErr )
127 static HRESULT WINAPI domelem_get_nodeName(
128 IXMLDOMElement *iface,
131 domelem *This = impl_from_IXMLDOMElement( iface );
132 return IXMLDOMNode_get_nodeName( This->node, p );
135 static HRESULT WINAPI domelem_get_nodeValue(
136 IXMLDOMElement *iface,
139 domelem *This = impl_from_IXMLDOMElement( iface );
140 return IXMLDOMNode_get_nodeValue( This->node, var1 );
143 static HRESULT WINAPI domelem_put_nodeValue(
144 IXMLDOMElement *iface,
147 domelem *This = impl_from_IXMLDOMElement( iface );
148 return IXMLDOMNode_put_nodeValue( This->node, var1 );
151 static HRESULT WINAPI domelem_get_nodeType(
152 IXMLDOMElement *iface,
153 DOMNodeType* domNodeType )
155 domelem *This = impl_from_IXMLDOMElement( iface );
156 return IXMLDOMNode_get_nodeType( This->node, domNodeType );
159 static HRESULT WINAPI domelem_get_parentNode(
160 IXMLDOMElement *iface,
161 IXMLDOMNode** parent )
163 domelem *This = impl_from_IXMLDOMElement( iface );
164 return IXMLDOMNode_get_parentNode( This->node, parent );
167 static HRESULT WINAPI domelem_get_childNodes(
168 IXMLDOMElement *iface,
169 IXMLDOMNodeList** outList)
171 domelem *This = impl_from_IXMLDOMElement( iface );
172 return IXMLDOMNode_get_childNodes( This->node, outList );
175 static HRESULT WINAPI domelem_get_firstChild(
176 IXMLDOMElement *iface,
177 IXMLDOMNode** domNode)
179 domelem *This = impl_from_IXMLDOMElement( iface );
180 return IXMLDOMNode_get_firstChild( This->node, domNode );
183 static HRESULT WINAPI domelem_get_lastChild(
184 IXMLDOMElement *iface,
185 IXMLDOMNode** domNode)
187 domelem *This = impl_from_IXMLDOMElement( iface );
188 return IXMLDOMNode_get_lastChild( This->node, domNode );
191 static HRESULT WINAPI domelem_get_previousSibling(
192 IXMLDOMElement *iface,
193 IXMLDOMNode** domNode)
195 domelem *This = impl_from_IXMLDOMElement( iface );
196 return IXMLDOMNode_get_previousSibling( This->node, domNode );
199 static HRESULT WINAPI domelem_get_nextSibling(
200 IXMLDOMElement *iface,
201 IXMLDOMNode** domNode)
203 domelem *This = impl_from_IXMLDOMElement( iface );
204 return IXMLDOMNode_get_nextSibling( This->node, domNode );
207 static HRESULT WINAPI domelem_get_attributes(
208 IXMLDOMElement *iface,
209 IXMLDOMNamedNodeMap** attributeMap)
211 domelem *This = impl_from_IXMLDOMElement( iface );
212 return IXMLDOMNode_get_attributes( This->node, attributeMap );
215 static HRESULT WINAPI domelem_insertBefore(
216 IXMLDOMElement *iface,
217 IXMLDOMNode* newNode, VARIANT var1,
218 IXMLDOMNode** outOldNode)
220 domelem *This = impl_from_IXMLDOMElement( iface );
221 return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
224 static HRESULT WINAPI domelem_replaceChild(
225 IXMLDOMElement *iface,
226 IXMLDOMNode* newNode,
227 IXMLDOMNode* oldNode,
228 IXMLDOMNode** outOldNode)
230 domelem *This = impl_from_IXMLDOMElement( iface );
231 return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
234 static HRESULT WINAPI domelem_removeChild(
235 IXMLDOMElement *iface,
236 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
238 domelem *This = impl_from_IXMLDOMElement( iface );
239 return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
242 static HRESULT WINAPI domelem_appendChild(
243 IXMLDOMElement *iface,
244 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
246 domelem *This = impl_from_IXMLDOMElement( iface );
247 return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
250 static HRESULT WINAPI domelem_hasChildNodes(
251 IXMLDOMElement *iface,
254 domelem *This = impl_from_IXMLDOMElement( iface );
255 return IXMLDOMNode_hasChildNodes( This->node, pbool );
258 static HRESULT WINAPI domelem_get_ownerDocument(
259 IXMLDOMElement *iface,
260 IXMLDOMDocument** domDocument)
262 domelem *This = impl_from_IXMLDOMElement( iface );
263 return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
266 static HRESULT WINAPI domelem_cloneNode(
267 IXMLDOMElement *iface,
268 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
270 domelem *This = impl_from_IXMLDOMElement( iface );
271 return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
274 static HRESULT WINAPI domelem_get_nodeTypeString(
275 IXMLDOMElement *iface,
278 domelem *This = impl_from_IXMLDOMElement( iface );
279 return IXMLDOMNode_get_nodeTypeString( This->node, p );
282 static HRESULT WINAPI domelem_get_text(
283 IXMLDOMElement *iface,
286 domelem *This = impl_from_IXMLDOMElement( iface );
287 return IXMLDOMNode_get_text( This->node, p );
290 static HRESULT WINAPI domelem_put_text(
291 IXMLDOMElement *iface,
294 domelem *This = impl_from_IXMLDOMElement( iface );
295 return IXMLDOMNode_put_text( This->node, p );
298 static HRESULT WINAPI domelem_get_specified(
299 IXMLDOMElement *iface,
302 domelem *This = impl_from_IXMLDOMElement( iface );
303 return IXMLDOMNode_get_specified( This->node, pbool );
306 static HRESULT WINAPI domelem_get_definition(
307 IXMLDOMElement *iface,
308 IXMLDOMNode** domNode)
310 domelem *This = impl_from_IXMLDOMElement( iface );
311 return IXMLDOMNode_get_definition( This->node, domNode );
314 static HRESULT WINAPI domelem_get_nodeTypedValue(
315 IXMLDOMElement *iface,
318 domelem *This = impl_from_IXMLDOMElement( iface );
319 return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
322 static HRESULT WINAPI domelem_put_nodeTypedValue(
323 IXMLDOMElement *iface,
326 domelem *This = impl_from_IXMLDOMElement( iface );
327 return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
330 static HRESULT WINAPI domelem_get_dataType(
331 IXMLDOMElement *iface,
334 domelem *This = impl_from_IXMLDOMElement( iface );
335 return IXMLDOMNode_get_dataType( This->node, var1 );
338 static HRESULT WINAPI domelem_put_dataType(
339 IXMLDOMElement *iface,
342 domelem *This = impl_from_IXMLDOMElement( iface );
343 return IXMLDOMNode_put_dataType( This->node, p );
346 static HRESULT WINAPI domelem_get_xml(
347 IXMLDOMElement *iface,
350 domelem *This = impl_from_IXMLDOMElement( iface );
351 return IXMLDOMNode_get_xml( This->node, p );
354 static HRESULT WINAPI domelem_transformNode(
355 IXMLDOMElement *iface,
356 IXMLDOMNode* domNode, BSTR* p)
358 domelem *This = impl_from_IXMLDOMElement( iface );
359 return IXMLDOMNode_transformNode( This->node, domNode, p );
362 static HRESULT WINAPI domelem_selectNodes(
363 IXMLDOMElement *iface,
364 BSTR p, IXMLDOMNodeList** outList)
366 domelem *This = impl_from_IXMLDOMElement( iface );
367 return IXMLDOMNode_selectNodes( This->node, p, outList );
370 static HRESULT WINAPI domelem_selectSingleNode(
371 IXMLDOMElement *iface,
372 BSTR p, IXMLDOMNode** outNode)
374 domelem *This = impl_from_IXMLDOMElement( iface );
375 return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
378 static HRESULT WINAPI domelem_get_parsed(
379 IXMLDOMElement *iface,
382 domelem *This = impl_from_IXMLDOMElement( iface );
383 return IXMLDOMNode_get_parsed( This->node, pbool );
386 static HRESULT WINAPI domelem_get_namespaceURI(
387 IXMLDOMElement *iface,
390 domelem *This = impl_from_IXMLDOMElement( iface );
391 return IXMLDOMNode_get_namespaceURI( This->node, p );
394 static HRESULT WINAPI domelem_get_prefix(
395 IXMLDOMElement *iface,
398 domelem *This = impl_from_IXMLDOMElement( iface );
399 return IXMLDOMNode_get_prefix( This->node, p );
402 static HRESULT WINAPI domelem_get_baseName(
403 IXMLDOMElement *iface,
406 domelem *This = impl_from_IXMLDOMElement( iface );
407 return IXMLDOMNode_get_baseName( This->node, p );
410 static HRESULT WINAPI domelem_transformNodeToObject(
411 IXMLDOMElement *iface,
412 IXMLDOMNode* domNode, VARIANT var1)
414 domelem *This = impl_from_IXMLDOMElement( iface );
415 return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
418 static HRESULT WINAPI domelem_get_tagName(
419 IXMLDOMElement *iface,
422 domelem *This = impl_from_IXMLDOMElement( iface );
428 TRACE("%p\n", This );
433 element = get_element( This );
437 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, NULL, 0 );
439 len += MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, NULL, 0 );
440 str = (LPWSTR) HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
442 return E_OUTOFMEMORY;
445 offset = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, str, len );
446 str[offset - 1] = ':';
448 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, str + offset, len - offset );
449 *p = SysAllocString( str );
450 HeapFree( GetProcessHeap(), 0, str );
455 static HRESULT WINAPI domelem_getAttribute(
456 IXMLDOMElement *iface,
457 BSTR name, VARIANT* value)
459 domelem *This = impl_from_IXMLDOMElement( iface );
461 xmlChar *xml_name, *xml_value;
462 HRESULT hr = S_FALSE;
464 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), value);
469 element = get_element( This );
473 V_BSTR(value) = NULL;
474 V_VT(value) = VT_NULL;
476 xml_name = xmlChar_from_wchar( name );
477 xml_value = xmlGetNsProp(element, xml_name, NULL);
478 HeapFree(GetProcessHeap(), 0, xml_name);
481 V_VT(value) = VT_BSTR;
482 V_BSTR(value) = bstr_from_xmlChar( xml_value );
490 static HRESULT WINAPI domelem_setAttribute(
491 IXMLDOMElement *iface,
492 BSTR name, VARIANT value)
494 domelem *This = impl_from_IXMLDOMElement( iface );
496 xmlChar *xml_name, *xml_value;
500 TRACE("(%p)->(%s, var)\n", This, debugstr_w(name));
502 element = get_element( This );
507 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
510 FIXME("VariantChangeType failed\n");
514 xml_name = xmlChar_from_wchar( name );
515 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
517 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
520 HeapFree(GetProcessHeap(), 0, xml_value);
521 HeapFree(GetProcessHeap(), 0, xml_name);
527 static HRESULT WINAPI domelem_removeAttribute(
528 IXMLDOMElement *iface,
535 static HRESULT WINAPI domelem_getAttributeNode(
536 IXMLDOMElement *iface,
537 BSTR p, IXMLDOMAttribute** attributeNode )
543 static HRESULT WINAPI domelem_setAttributeNode(
544 IXMLDOMElement *iface,
545 IXMLDOMAttribute* domAttribute,
546 IXMLDOMAttribute** attributeNode)
552 static HRESULT WINAPI domelem_removeAttributeNode(
553 IXMLDOMElement *iface,
554 IXMLDOMAttribute* domAttribute,
555 IXMLDOMAttribute** attributeNode)
561 static HRESULT WINAPI domelem_getElementsByTagName(
562 IXMLDOMElement *iface,
563 BSTR bstrName, IXMLDOMNodeList** resultList)
565 domelem *This = impl_from_IXMLDOMElement( iface );
569 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(bstrName), resultList);
571 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(3+lstrlenW(bstrName)+1));
573 szPattern[1] = szPattern[2] = '/';
574 lstrcpyW(szPattern+3, bstrName);
575 TRACE("%s\n", debugstr_w(szPattern));
577 hr = queryresult_create(get_element(This), szPattern, resultList);
578 HeapFree(GetProcessHeap(), 0, szPattern);
583 static HRESULT WINAPI domelem_normalize(
584 IXMLDOMElement *iface )
590 static const struct IXMLDOMElementVtbl domelem_vtbl =
592 domelem_QueryInterface,
595 domelem_GetTypeInfoCount,
597 domelem_GetIDsOfNames,
599 domelem_get_nodeName,
600 domelem_get_nodeValue,
601 domelem_put_nodeValue,
602 domelem_get_nodeType,
603 domelem_get_parentNode,
604 domelem_get_childNodes,
605 domelem_get_firstChild,
606 domelem_get_lastChild,
607 domelem_get_previousSibling,
608 domelem_get_nextSibling,
609 domelem_get_attributes,
610 domelem_insertBefore,
611 domelem_replaceChild,
614 domelem_hasChildNodes,
615 domelem_get_ownerDocument,
617 domelem_get_nodeTypeString,
620 domelem_get_specified,
621 domelem_get_definition,
622 domelem_get_nodeTypedValue,
623 domelem_put_nodeTypedValue,
624 domelem_get_dataType,
625 domelem_put_dataType,
627 domelem_transformNode,
629 domelem_selectSingleNode,
631 domelem_get_namespaceURI,
633 domelem_get_baseName,
634 domelem_transformNodeToObject,
636 domelem_getAttribute,
637 domelem_setAttribute,
638 domelem_removeAttribute,
639 domelem_getAttributeNode,
640 domelem_setAttributeNode,
641 domelem_removeAttributeNode,
642 domelem_getElementsByTagName,
646 static HRESULT WINAPI Internal_QueryInterface(
651 domelem *This = impl_from_InternalUnknown( iface );
652 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
654 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
655 IsEqualGUID( riid, &IID_IUnknown ) )
657 *ppvObject = &This->lpVtbl;
659 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
660 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
662 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
666 FIXME("interface %s not implemented\n", debugstr_guid(riid));
667 return E_NOINTERFACE;
670 IUnknown_AddRef( (IUnknown*)*ppvObject );
675 static ULONG WINAPI Internal_AddRef(
678 domelem *This = impl_from_InternalUnknown( iface );
679 return InterlockedIncrement( &This->ref );
682 static ULONG WINAPI Internal_Release(
685 domelem *This = impl_from_InternalUnknown( iface );
688 ref = InterlockedDecrement( &This->ref );
691 IUnknown_Release( This->node_unk );
692 HeapFree( GetProcessHeap(), 0, This );
698 static const struct IUnknownVtbl internal_unk_vtbl =
700 Internal_QueryInterface,
705 IUnknown* create_element( xmlNodePtr element, IUnknown *pUnkOuter )
710 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
714 This->lpVtbl = &domelem_vtbl;
716 This->lpInternalUnkVtbl = &internal_unk_vtbl;
719 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
721 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
723 This->node_unk = create_basic_node( element, (IUnknown*)&This->lpVtbl );
726 HeapFree(GetProcessHeap(), 0, This);
730 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
733 IUnknown_Release(This->node_unk);
734 HeapFree( GetProcessHeap(), 0, This );
737 /* The ref on This->node is actually looped back into this object, so release it */
738 IXMLDOMNode_Release(This->node);
740 return (IUnknown*) &This->lpInternalUnkVtbl;