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
44 const struct IXMLDOMElementVtbl *lpVtbl;
48 static inline domelem *impl_from_IXMLDOMElement( IXMLDOMElement *iface )
50 return (domelem *)((char*)iface - FIELD_OFFSET(domelem, lpVtbl));
53 static inline xmlNodePtr get_element( domelem *This )
55 return This->node.node;
58 static HRESULT WINAPI domelem_QueryInterface(
59 IXMLDOMElement *iface,
63 domelem *This = impl_from_IXMLDOMElement( iface );
65 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
67 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
68 IsEqualGUID( riid, &IID_IDispatch ) ||
69 IsEqualGUID( riid, &IID_IUnknown ) )
71 *ppvObject = &This->lpVtbl;
73 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
75 *ppvObject = IXMLDOMNode_from_impl(&This->node);
77 else if(dispex_query_interface(&This->node.dispex, riid, ppvObject))
79 return *ppvObject ? S_OK : E_NOINTERFACE;
83 FIXME("interface %s not implemented\n", debugstr_guid(riid));
87 IUnknown_AddRef( (IUnknown*)*ppvObject );
91 static ULONG WINAPI domelem_AddRef(
92 IXMLDOMElement *iface )
94 domelem *This = impl_from_IXMLDOMElement( iface );
95 LONG ref = InterlockedIncrement(&This->ref);
97 TRACE("(%p) ref=%d\n", This, ref);
102 static ULONG WINAPI domelem_Release(
103 IXMLDOMElement *iface )
105 domelem *This = impl_from_IXMLDOMElement( iface );
106 ULONG ref = InterlockedDecrement(&This->ref);
108 TRACE("(%p) ref=%d\n", This, ref);
111 destroy_xmlnode(&This->node);
118 static HRESULT WINAPI domelem_GetTypeInfoCount(
119 IXMLDOMElement *iface,
122 domelem *This = impl_from_IXMLDOMElement( iface );
124 TRACE("(%p)->(%p)\n", This, pctinfo);
131 static HRESULT WINAPI domelem_GetTypeInfo(
132 IXMLDOMElement *iface,
133 UINT iTInfo, LCID lcid,
134 ITypeInfo** ppTInfo )
136 domelem *This = impl_from_IXMLDOMElement( iface );
139 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
141 hr = get_typeinfo(IXMLDOMElement_tid, ppTInfo);
146 static HRESULT WINAPI domelem_GetIDsOfNames(
147 IXMLDOMElement *iface,
148 REFIID riid, LPOLESTR* rgszNames,
149 UINT cNames, LCID lcid, DISPID* rgDispId )
151 domelem *This = impl_from_IXMLDOMElement( iface );
155 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
158 if(!rgszNames || cNames == 0 || !rgDispId)
161 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
164 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
165 ITypeInfo_Release(typeinfo);
171 static HRESULT WINAPI domelem_Invoke(
172 IXMLDOMElement *iface,
173 DISPID dispIdMember, REFIID riid, LCID lcid,
174 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
175 EXCEPINFO* pExcepInfo, UINT* puArgErr )
177 domelem *This = impl_from_IXMLDOMElement( iface );
181 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
182 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
184 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
187 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
188 pVarResult, pExcepInfo, puArgErr);
189 ITypeInfo_Release(typeinfo);
195 static HRESULT WINAPI domelem_get_nodeName(
196 IXMLDOMElement *iface,
199 domelem *This = impl_from_IXMLDOMElement( iface );
200 return IXMLDOMNode_get_nodeName( IXMLDOMNode_from_impl(&This->node), p );
203 static HRESULT WINAPI domelem_get_nodeValue(
204 IXMLDOMElement *iface,
207 domelem *This = impl_from_IXMLDOMElement( iface );
208 return IXMLDOMNode_get_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
211 static HRESULT WINAPI domelem_put_nodeValue(
212 IXMLDOMElement *iface,
215 domelem *This = impl_from_IXMLDOMElement( iface );
216 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
219 static HRESULT WINAPI domelem_get_nodeType(
220 IXMLDOMElement *iface,
221 DOMNodeType* domNodeType )
223 domelem *This = impl_from_IXMLDOMElement( iface );
224 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
227 static HRESULT WINAPI domelem_get_parentNode(
228 IXMLDOMElement *iface,
229 IXMLDOMNode** parent )
231 domelem *This = impl_from_IXMLDOMElement( iface );
232 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
235 static HRESULT WINAPI domelem_get_childNodes(
236 IXMLDOMElement *iface,
237 IXMLDOMNodeList** outList)
239 domelem *This = impl_from_IXMLDOMElement( iface );
240 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
243 static HRESULT WINAPI domelem_get_firstChild(
244 IXMLDOMElement *iface,
245 IXMLDOMNode** domNode)
247 domelem *This = impl_from_IXMLDOMElement( iface );
248 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
251 static HRESULT WINAPI domelem_get_lastChild(
252 IXMLDOMElement *iface,
253 IXMLDOMNode** domNode)
255 domelem *This = impl_from_IXMLDOMElement( iface );
256 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
259 static HRESULT WINAPI domelem_get_previousSibling(
260 IXMLDOMElement *iface,
261 IXMLDOMNode** domNode)
263 domelem *This = impl_from_IXMLDOMElement( iface );
264 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
267 static HRESULT WINAPI domelem_get_nextSibling(
268 IXMLDOMElement *iface,
269 IXMLDOMNode** domNode)
271 domelem *This = impl_from_IXMLDOMElement( iface );
272 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
275 static HRESULT WINAPI domelem_get_attributes(
276 IXMLDOMElement *iface,
277 IXMLDOMNamedNodeMap** attributeMap)
279 domelem *This = impl_from_IXMLDOMElement( iface );
280 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
283 static HRESULT WINAPI domelem_insertBefore(
284 IXMLDOMElement *iface,
285 IXMLDOMNode* newNode, VARIANT var1,
286 IXMLDOMNode** outOldNode)
288 domelem *This = impl_from_IXMLDOMElement( iface );
289 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
292 static HRESULT WINAPI domelem_replaceChild(
293 IXMLDOMElement *iface,
294 IXMLDOMNode* newNode,
295 IXMLDOMNode* oldNode,
296 IXMLDOMNode** outOldNode)
298 domelem *This = impl_from_IXMLDOMElement( iface );
299 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
302 static HRESULT WINAPI domelem_removeChild(
303 IXMLDOMElement *iface,
304 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
306 domelem *This = impl_from_IXMLDOMElement( iface );
307 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
310 static HRESULT WINAPI domelem_appendChild(
311 IXMLDOMElement *iface,
312 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
314 domelem *This = impl_from_IXMLDOMElement( iface );
315 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
318 static HRESULT WINAPI domelem_hasChildNodes(
319 IXMLDOMElement *iface,
322 domelem *This = impl_from_IXMLDOMElement( iface );
323 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
326 static HRESULT WINAPI domelem_get_ownerDocument(
327 IXMLDOMElement *iface,
328 IXMLDOMDocument** domDocument)
330 domelem *This = impl_from_IXMLDOMElement( iface );
331 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
334 static HRESULT WINAPI domelem_cloneNode(
335 IXMLDOMElement *iface,
336 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
338 domelem *This = impl_from_IXMLDOMElement( iface );
339 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
342 static HRESULT WINAPI domelem_get_nodeTypeString(
343 IXMLDOMElement *iface,
346 domelem *This = impl_from_IXMLDOMElement( iface );
347 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
350 static HRESULT WINAPI domelem_get_text(
351 IXMLDOMElement *iface,
354 domelem *This = impl_from_IXMLDOMElement( iface );
355 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
358 static HRESULT WINAPI domelem_put_text(
359 IXMLDOMElement *iface,
362 domelem *This = impl_from_IXMLDOMElement( iface );
363 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
366 static HRESULT WINAPI domelem_get_specified(
367 IXMLDOMElement *iface,
370 domelem *This = impl_from_IXMLDOMElement( iface );
371 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
374 static HRESULT WINAPI domelem_get_definition(
375 IXMLDOMElement *iface,
376 IXMLDOMNode** domNode)
378 domelem *This = impl_from_IXMLDOMElement( iface );
379 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
382 static HRESULT WINAPI domelem_get_nodeTypedValue(
383 IXMLDOMElement *iface,
386 domelem *This = impl_from_IXMLDOMElement( iface );
387 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
390 static HRESULT WINAPI domelem_put_nodeTypedValue(
391 IXMLDOMElement *iface,
394 domelem *This = impl_from_IXMLDOMElement( iface );
395 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
398 static HRESULT WINAPI domelem_get_dataType(
399 IXMLDOMElement *iface,
402 domelem *This = impl_from_IXMLDOMElement( iface );
403 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
406 static HRESULT WINAPI domelem_put_dataType(
407 IXMLDOMElement *iface,
410 domelem *This = impl_from_IXMLDOMElement( iface );
411 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
414 static HRESULT WINAPI domelem_get_xml(
415 IXMLDOMElement *iface,
418 domelem *This = impl_from_IXMLDOMElement( iface );
419 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
422 static HRESULT WINAPI domelem_transformNode(
423 IXMLDOMElement *iface,
424 IXMLDOMNode* domNode, BSTR* p)
426 domelem *This = impl_from_IXMLDOMElement( iface );
427 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
430 static HRESULT WINAPI domelem_selectNodes(
431 IXMLDOMElement *iface,
432 BSTR p, IXMLDOMNodeList** outList)
434 domelem *This = impl_from_IXMLDOMElement( iface );
435 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
438 static HRESULT WINAPI domelem_selectSingleNode(
439 IXMLDOMElement *iface,
440 BSTR p, IXMLDOMNode** outNode)
442 domelem *This = impl_from_IXMLDOMElement( iface );
443 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
446 static HRESULT WINAPI domelem_get_parsed(
447 IXMLDOMElement *iface,
450 domelem *This = impl_from_IXMLDOMElement( iface );
451 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
454 static HRESULT WINAPI domelem_get_namespaceURI(
455 IXMLDOMElement *iface,
458 domelem *This = impl_from_IXMLDOMElement( iface );
459 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
462 static HRESULT WINAPI domelem_get_prefix(
463 IXMLDOMElement *iface,
466 domelem *This = impl_from_IXMLDOMElement( iface );
467 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
470 static HRESULT WINAPI domelem_get_baseName(
471 IXMLDOMElement *iface,
474 domelem *This = impl_from_IXMLDOMElement( iface );
475 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
478 static HRESULT WINAPI domelem_transformNodeToObject(
479 IXMLDOMElement *iface,
480 IXMLDOMNode* domNode, VARIANT var1)
482 domelem *This = impl_from_IXMLDOMElement( iface );
483 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
486 static HRESULT WINAPI domelem_get_tagName(
487 IXMLDOMElement *iface,
490 domelem *This = impl_from_IXMLDOMElement( iface );
496 TRACE("%p\n", This );
498 element = get_element( This );
502 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, NULL, 0 );
504 len += MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, NULL, 0 );
505 str = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
507 return E_OUTOFMEMORY;
510 offset = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->ns->prefix, -1, str, len );
511 str[offset - 1] = ':';
513 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) element->name, -1, str + offset, len - offset );
514 *p = SysAllocString( str );
515 HeapFree( GetProcessHeap(), 0, str );
520 static HRESULT WINAPI domelem_getAttribute(
521 IXMLDOMElement *iface,
522 BSTR name, VARIANT* value)
524 domelem *This = impl_from_IXMLDOMElement( iface );
526 xmlChar *xml_name, *xml_value = NULL;
527 HRESULT hr = S_FALSE;
529 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), value);
534 element = get_element( This );
538 V_BSTR(value) = NULL;
539 V_VT(value) = VT_NULL;
541 xml_name = xmlChar_from_wchar( name );
543 if(!xmlValidateNameValue(xml_name))
546 xml_value = xmlGetNsProp(element, xml_name, NULL);
548 HeapFree(GetProcessHeap(), 0, xml_name);
551 V_VT(value) = VT_BSTR;
552 V_BSTR(value) = bstr_from_xmlChar( xml_value );
560 static HRESULT WINAPI domelem_setAttribute(
561 IXMLDOMElement *iface,
562 BSTR name, VARIANT value)
564 domelem *This = impl_from_IXMLDOMElement( iface );
566 xmlChar *xml_name, *xml_value;
570 TRACE("(%p)->(%s, var)\n", This, debugstr_w(name));
572 element = get_element( This );
577 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
580 FIXME("VariantChangeType failed\n");
584 xml_name = xmlChar_from_wchar( name );
585 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
587 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
590 HeapFree(GetProcessHeap(), 0, xml_value);
591 HeapFree(GetProcessHeap(), 0, xml_name);
597 static HRESULT WINAPI domelem_removeAttribute(
598 IXMLDOMElement *iface,
605 static HRESULT WINAPI domelem_getAttributeNode(
606 IXMLDOMElement *iface,
607 BSTR p, IXMLDOMAttribute** attributeNode )
609 domelem *This = impl_from_IXMLDOMElement( iface );
614 HRESULT hr = S_FALSE;
616 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
621 *attributeNode = NULL;
623 element = get_element( This );
627 xml_name = xmlChar_from_wchar(p);
629 if(!xmlValidateNameValue(xml_name))
631 HeapFree(GetProcessHeap(), 0, xml_name);
635 attr = xmlHasProp(element, xml_name);
637 unk = create_attribute((xmlNodePtr)attr);
638 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
639 IUnknown_Release(unk);
642 HeapFree(GetProcessHeap(), 0, xml_name);
647 static HRESULT WINAPI domelem_setAttributeNode(
648 IXMLDOMElement *iface,
649 IXMLDOMAttribute* domAttribute,
650 IXMLDOMAttribute** attributeNode)
656 static HRESULT WINAPI domelem_removeAttributeNode(
657 IXMLDOMElement *iface,
658 IXMLDOMAttribute* domAttribute,
659 IXMLDOMAttribute** attributeNode)
665 static HRESULT WINAPI domelem_getElementsByTagName(
666 IXMLDOMElement *iface,
667 BSTR bstrName, IXMLDOMNodeList** resultList)
669 domelem *This = impl_from_IXMLDOMElement( iface );
674 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(bstrName), resultList);
676 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(3+lstrlenW(bstrName)+1));
678 szPattern[1] = szPattern[2] = '/';
679 lstrcpyW(szPattern+3, bstrName);
680 TRACE("%s\n", debugstr_w(szPattern));
682 element = get_element(This);
686 hr = queryresult_create(element, szPattern, resultList);
687 HeapFree(GetProcessHeap(), 0, szPattern);
692 static HRESULT WINAPI domelem_normalize(
693 IXMLDOMElement *iface )
699 static const struct IXMLDOMElementVtbl domelem_vtbl =
701 domelem_QueryInterface,
704 domelem_GetTypeInfoCount,
706 domelem_GetIDsOfNames,
708 domelem_get_nodeName,
709 domelem_get_nodeValue,
710 domelem_put_nodeValue,
711 domelem_get_nodeType,
712 domelem_get_parentNode,
713 domelem_get_childNodes,
714 domelem_get_firstChild,
715 domelem_get_lastChild,
716 domelem_get_previousSibling,
717 domelem_get_nextSibling,
718 domelem_get_attributes,
719 domelem_insertBefore,
720 domelem_replaceChild,
723 domelem_hasChildNodes,
724 domelem_get_ownerDocument,
726 domelem_get_nodeTypeString,
729 domelem_get_specified,
730 domelem_get_definition,
731 domelem_get_nodeTypedValue,
732 domelem_put_nodeTypedValue,
733 domelem_get_dataType,
734 domelem_put_dataType,
736 domelem_transformNode,
738 domelem_selectSingleNode,
740 domelem_get_namespaceURI,
742 domelem_get_baseName,
743 domelem_transformNodeToObject,
745 domelem_getAttribute,
746 domelem_setAttribute,
747 domelem_removeAttribute,
748 domelem_getAttributeNode,
749 domelem_setAttributeNode,
750 domelem_removeAttributeNode,
751 domelem_getElementsByTagName,
755 static const tid_t domelem_iface_tids[] = {
760 static dispex_static_data_t domelem_dispex = {
767 IUnknown* create_element( xmlNodePtr element )
771 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
775 This->lpVtbl = &domelem_vtbl;
778 init_xmlnode(&This->node, element, (IUnknown*)&This->lpVtbl, &domelem_dispex);
780 return (IUnknown*) &This->lpVtbl;