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 );
492 const xmlChar *prefix;
495 TRACE("(%p)->(%p)\n", This, p );
497 if (!p) return E_INVALIDARG;
499 element = get_element( This );
503 prefix = element->ns ? element->ns->prefix : NULL;
504 qname = xmlBuildQName(element->name, prefix, NULL, 0);
506 *p = bstr_from_xmlChar(qname);
507 if (qname != element->name) xmlFree(qname);
509 return *p ? S_OK : E_OUTOFMEMORY;
512 static HRESULT WINAPI domelem_getAttribute(
513 IXMLDOMElement *iface,
514 BSTR name, VARIANT* value)
516 domelem *This = impl_from_IXMLDOMElement( iface );
518 xmlChar *xml_name, *xml_value = NULL;
519 HRESULT hr = S_FALSE;
521 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
526 element = get_element( This );
530 V_BSTR(value) = NULL;
531 V_VT(value) = VT_NULL;
533 xml_name = xmlChar_from_wchar( name );
535 if(!xmlValidateNameValue(xml_name))
538 xml_value = xmlGetNsProp(element, xml_name, NULL);
543 V_VT(value) = VT_BSTR;
544 V_BSTR(value) = bstr_from_xmlChar( xml_value );
552 static HRESULT WINAPI domelem_setAttribute(
553 IXMLDOMElement *iface,
554 BSTR name, VARIANT value)
556 domelem *This = impl_from_IXMLDOMElement( iface );
558 xmlChar *xml_name, *xml_value;
562 TRACE("(%p)->(%s var)\n", This, debugstr_w(name));
564 element = get_element( This );
569 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
572 FIXME("VariantChangeType failed\n");
576 xml_name = xmlChar_from_wchar( name );
577 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
579 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
582 heap_free(xml_value);
589 static HRESULT WINAPI domelem_removeAttribute(
590 IXMLDOMElement *iface,
593 domelem *This = impl_from_IXMLDOMElement( iface );
594 IXMLDOMNamedNodeMap *attr;
597 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
599 hr = IXMLDOMElement_get_attributes(iface, &attr);
600 if (hr != S_OK) return hr;
602 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
603 IXMLDOMNamedNodeMap_Release(attr);
608 static HRESULT WINAPI domelem_getAttributeNode(
609 IXMLDOMElement *iface,
610 BSTR p, IXMLDOMAttribute** attributeNode )
612 domelem *This = impl_from_IXMLDOMElement( iface );
617 HRESULT hr = S_FALSE;
619 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
624 *attributeNode = NULL;
626 element = get_element( This );
630 xml_name = xmlChar_from_wchar(p);
632 if(!xmlValidateNameValue(xml_name))
638 attr = xmlHasProp(element, xml_name);
640 unk = create_attribute((xmlNodePtr)attr);
641 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
642 IUnknown_Release(unk);
650 static HRESULT WINAPI domelem_setAttributeNode(
651 IXMLDOMElement *iface,
652 IXMLDOMAttribute* domAttribute,
653 IXMLDOMAttribute** attributeNode)
655 domelem *This = impl_from_IXMLDOMElement( iface );
656 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
660 static HRESULT WINAPI domelem_removeAttributeNode(
661 IXMLDOMElement *iface,
662 IXMLDOMAttribute* domAttribute,
663 IXMLDOMAttribute** attributeNode)
665 domelem *This = impl_from_IXMLDOMElement( iface );
666 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
670 static HRESULT WINAPI domelem_getElementsByTagName(
671 IXMLDOMElement *iface,
672 BSTR bstrName, IXMLDOMNodeList** resultList)
674 static const WCHAR xpathformat[] =
675 { '.','/','/','*','[','l','o','c','a','l','-','n','a','m','e','(',')','=','\'','%','s','\'',']',0 };
676 domelem *This = impl_from_IXMLDOMElement( iface );
681 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), resultList);
683 if (bstrName[0] == '*' && bstrName[1] == 0)
685 szPattern = heap_alloc(sizeof(WCHAR)*5);
687 szPattern[1] = szPattern[2] = '/';
693 szPattern = heap_alloc(sizeof(WCHAR)*(21+lstrlenW(bstrName)+1));
694 wsprintfW(szPattern, xpathformat, bstrName);
696 TRACE("%s\n", debugstr_w(szPattern));
698 element = get_element(This);
702 hr = queryresult_create(element, szPattern, resultList);
703 heap_free(szPattern);
708 static HRESULT WINAPI domelem_normalize(
709 IXMLDOMElement *iface )
711 domelem *This = impl_from_IXMLDOMElement( iface );
716 static const struct IXMLDOMElementVtbl domelem_vtbl =
718 domelem_QueryInterface,
721 domelem_GetTypeInfoCount,
723 domelem_GetIDsOfNames,
725 domelem_get_nodeName,
726 domelem_get_nodeValue,
727 domelem_put_nodeValue,
728 domelem_get_nodeType,
729 domelem_get_parentNode,
730 domelem_get_childNodes,
731 domelem_get_firstChild,
732 domelem_get_lastChild,
733 domelem_get_previousSibling,
734 domelem_get_nextSibling,
735 domelem_get_attributes,
736 domelem_insertBefore,
737 domelem_replaceChild,
740 domelem_hasChildNodes,
741 domelem_get_ownerDocument,
743 domelem_get_nodeTypeString,
746 domelem_get_specified,
747 domelem_get_definition,
748 domelem_get_nodeTypedValue,
749 domelem_put_nodeTypedValue,
750 domelem_get_dataType,
751 domelem_put_dataType,
753 domelem_transformNode,
755 domelem_selectSingleNode,
757 domelem_get_namespaceURI,
759 domelem_get_baseName,
760 domelem_transformNodeToObject,
762 domelem_getAttribute,
763 domelem_setAttribute,
764 domelem_removeAttribute,
765 domelem_getAttributeNode,
766 domelem_setAttributeNode,
767 domelem_removeAttributeNode,
768 domelem_getElementsByTagName,
772 static const tid_t domelem_iface_tids[] = {
777 static dispex_static_data_t domelem_dispex = {
784 IUnknown* create_element( xmlNodePtr element )
788 This = heap_alloc( sizeof *This );
792 This->lpVtbl = &domelem_vtbl;
795 init_xmlnode(&This->node, element, (IUnknown*)&This->lpVtbl, &domelem_dispex);
797 return (IUnknown*) &This->lpVtbl;