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_IXMLDOMNode ) ||
69 IsEqualGUID( riid, &IID_IDispatch ) ||
70 IsEqualGUID( riid, &IID_IUnknown ) )
72 *ppvObject = &This->lpVtbl;
74 else if(node_query_interface(&This->node, riid, ppvObject))
76 return *ppvObject ? S_OK : E_NOINTERFACE;
80 FIXME("interface %s not implemented\n", debugstr_guid(riid));
84 IUnknown_AddRef( (IUnknown*)*ppvObject );
88 static ULONG WINAPI domelem_AddRef(
89 IXMLDOMElement *iface )
91 domelem *This = impl_from_IXMLDOMElement( iface );
92 LONG ref = InterlockedIncrement(&This->ref);
94 TRACE("(%p) ref=%d\n", This, ref);
99 static ULONG WINAPI domelem_Release(
100 IXMLDOMElement *iface )
102 domelem *This = impl_from_IXMLDOMElement( iface );
103 ULONG ref = InterlockedDecrement(&This->ref);
105 TRACE("(%p) ref=%d\n", This, ref);
108 destroy_xmlnode(&This->node);
115 static HRESULT WINAPI domelem_GetTypeInfoCount(
116 IXMLDOMElement *iface,
119 domelem *This = impl_from_IXMLDOMElement( iface );
121 TRACE("(%p)->(%p)\n", This, pctinfo);
128 static HRESULT WINAPI domelem_GetTypeInfo(
129 IXMLDOMElement *iface,
130 UINT iTInfo, LCID lcid,
131 ITypeInfo** ppTInfo )
133 domelem *This = impl_from_IXMLDOMElement( iface );
136 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
138 hr = get_typeinfo(IXMLDOMElement_tid, ppTInfo);
143 static HRESULT WINAPI domelem_GetIDsOfNames(
144 IXMLDOMElement *iface,
145 REFIID riid, LPOLESTR* rgszNames,
146 UINT cNames, LCID lcid, DISPID* rgDispId )
148 domelem *This = impl_from_IXMLDOMElement( iface );
152 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
155 if(!rgszNames || cNames == 0 || !rgDispId)
158 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
161 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
162 ITypeInfo_Release(typeinfo);
168 static HRESULT WINAPI domelem_Invoke(
169 IXMLDOMElement *iface,
170 DISPID dispIdMember, REFIID riid, LCID lcid,
171 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
172 EXCEPINFO* pExcepInfo, UINT* puArgErr )
174 domelem *This = impl_from_IXMLDOMElement( iface );
178 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
179 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
181 hr = get_typeinfo(IXMLDOMElement_tid, &typeinfo);
184 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
185 pVarResult, pExcepInfo, puArgErr);
186 ITypeInfo_Release(typeinfo);
192 static HRESULT WINAPI domelem_get_nodeName(
193 IXMLDOMElement *iface,
196 domelem *This = impl_from_IXMLDOMElement( iface );
198 TRACE("(%p)->(%p)\n", This, p);
200 return node_get_nodeName(&This->node, p);
203 static HRESULT WINAPI domelem_get_nodeValue(
204 IXMLDOMElement *iface,
207 domelem *This = impl_from_IXMLDOMElement( iface );
209 TRACE("(%p)->(%p)\n", This, value);
214 V_VT(value) = VT_NULL;
215 V_BSTR(value) = NULL; /* tests show that we should do this */
219 static HRESULT WINAPI domelem_put_nodeValue(
220 IXMLDOMElement *iface,
223 domelem *This = impl_from_IXMLDOMElement( iface );
224 return IXMLDOMNode_put_nodeValue( IXMLDOMNode_from_impl(&This->node), var1 );
227 static HRESULT WINAPI domelem_get_nodeType(
228 IXMLDOMElement *iface,
229 DOMNodeType* domNodeType )
231 domelem *This = impl_from_IXMLDOMElement( iface );
232 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
235 static HRESULT WINAPI domelem_get_parentNode(
236 IXMLDOMElement *iface,
237 IXMLDOMNode** parent )
239 domelem *This = impl_from_IXMLDOMElement( iface );
240 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
243 static HRESULT WINAPI domelem_get_childNodes(
244 IXMLDOMElement *iface,
245 IXMLDOMNodeList** outList)
247 domelem *This = impl_from_IXMLDOMElement( iface );
248 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
251 static HRESULT WINAPI domelem_get_firstChild(
252 IXMLDOMElement *iface,
253 IXMLDOMNode** domNode)
255 domelem *This = impl_from_IXMLDOMElement( iface );
256 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
259 static HRESULT WINAPI domelem_get_lastChild(
260 IXMLDOMElement *iface,
261 IXMLDOMNode** domNode)
263 domelem *This = impl_from_IXMLDOMElement( iface );
264 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
267 static HRESULT WINAPI domelem_get_previousSibling(
268 IXMLDOMElement *iface,
269 IXMLDOMNode** domNode)
271 domelem *This = impl_from_IXMLDOMElement( iface );
272 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
275 static HRESULT WINAPI domelem_get_nextSibling(
276 IXMLDOMElement *iface,
277 IXMLDOMNode** domNode)
279 domelem *This = impl_from_IXMLDOMElement( iface );
280 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
283 static HRESULT WINAPI domelem_get_attributes(
284 IXMLDOMElement *iface,
285 IXMLDOMNamedNodeMap** attributeMap)
287 domelem *This = impl_from_IXMLDOMElement( iface );
288 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
291 static HRESULT WINAPI domelem_insertBefore(
292 IXMLDOMElement *iface,
293 IXMLDOMNode* newNode, VARIANT var1,
294 IXMLDOMNode** outOldNode)
296 domelem *This = impl_from_IXMLDOMElement( iface );
297 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
300 static HRESULT WINAPI domelem_replaceChild(
301 IXMLDOMElement *iface,
302 IXMLDOMNode* newNode,
303 IXMLDOMNode* oldNode,
304 IXMLDOMNode** outOldNode)
306 domelem *This = impl_from_IXMLDOMElement( iface );
307 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
310 static HRESULT WINAPI domelem_removeChild(
311 IXMLDOMElement *iface,
312 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
314 domelem *This = impl_from_IXMLDOMElement( iface );
315 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
318 static HRESULT WINAPI domelem_appendChild(
319 IXMLDOMElement *iface,
320 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
322 domelem *This = impl_from_IXMLDOMElement( iface );
323 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
326 static HRESULT WINAPI domelem_hasChildNodes(
327 IXMLDOMElement *iface,
330 domelem *This = impl_from_IXMLDOMElement( iface );
331 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
334 static HRESULT WINAPI domelem_get_ownerDocument(
335 IXMLDOMElement *iface,
336 IXMLDOMDocument** domDocument)
338 domelem *This = impl_from_IXMLDOMElement( iface );
339 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
342 static HRESULT WINAPI domelem_cloneNode(
343 IXMLDOMElement *iface,
344 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
346 domelem *This = impl_from_IXMLDOMElement( iface );
347 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
350 static HRESULT WINAPI domelem_get_nodeTypeString(
351 IXMLDOMElement *iface,
354 domelem *This = impl_from_IXMLDOMElement( iface );
355 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
358 static HRESULT WINAPI domelem_get_text(
359 IXMLDOMElement *iface,
362 domelem *This = impl_from_IXMLDOMElement( iface );
363 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
366 static HRESULT WINAPI domelem_put_text(
367 IXMLDOMElement *iface,
370 domelem *This = impl_from_IXMLDOMElement( iface );
371 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
374 static HRESULT WINAPI domelem_get_specified(
375 IXMLDOMElement *iface,
378 domelem *This = impl_from_IXMLDOMElement( iface );
379 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
382 static HRESULT WINAPI domelem_get_definition(
383 IXMLDOMElement *iface,
384 IXMLDOMNode** domNode)
386 domelem *This = impl_from_IXMLDOMElement( iface );
387 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
390 static HRESULT WINAPI domelem_get_nodeTypedValue(
391 IXMLDOMElement *iface,
394 domelem *This = impl_from_IXMLDOMElement( iface );
395 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
398 static HRESULT WINAPI domelem_put_nodeTypedValue(
399 IXMLDOMElement *iface,
402 domelem *This = impl_from_IXMLDOMElement( iface );
403 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
406 static HRESULT WINAPI domelem_get_dataType(
407 IXMLDOMElement *iface,
410 domelem *This = impl_from_IXMLDOMElement( iface );
411 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
414 static HRESULT WINAPI domelem_put_dataType(
415 IXMLDOMElement *iface,
418 domelem *This = impl_from_IXMLDOMElement( iface );
419 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
422 static HRESULT WINAPI domelem_get_xml(
423 IXMLDOMElement *iface,
426 domelem *This = impl_from_IXMLDOMElement( iface );
427 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
430 static HRESULT WINAPI domelem_transformNode(
431 IXMLDOMElement *iface,
432 IXMLDOMNode* domNode, BSTR* p)
434 domelem *This = impl_from_IXMLDOMElement( iface );
435 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
438 static HRESULT WINAPI domelem_selectNodes(
439 IXMLDOMElement *iface,
440 BSTR p, IXMLDOMNodeList** outList)
442 domelem *This = impl_from_IXMLDOMElement( iface );
443 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
446 static HRESULT WINAPI domelem_selectSingleNode(
447 IXMLDOMElement *iface,
448 BSTR p, IXMLDOMNode** outNode)
450 domelem *This = impl_from_IXMLDOMElement( iface );
451 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
454 static HRESULT WINAPI domelem_get_parsed(
455 IXMLDOMElement *iface,
458 domelem *This = impl_from_IXMLDOMElement( iface );
459 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
462 static HRESULT WINAPI domelem_get_namespaceURI(
463 IXMLDOMElement *iface,
466 domelem *This = impl_from_IXMLDOMElement( iface );
467 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
470 static HRESULT WINAPI domelem_get_prefix(
471 IXMLDOMElement *iface,
474 domelem *This = impl_from_IXMLDOMElement( iface );
475 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
478 static HRESULT WINAPI domelem_get_baseName(
479 IXMLDOMElement *iface,
482 domelem *This = impl_from_IXMLDOMElement( iface );
483 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
486 static HRESULT WINAPI domelem_transformNodeToObject(
487 IXMLDOMElement *iface,
488 IXMLDOMNode* domNode, VARIANT var1)
490 domelem *This = impl_from_IXMLDOMElement( iface );
491 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
494 static HRESULT WINAPI domelem_get_tagName(
495 IXMLDOMElement *iface,
498 domelem *This = impl_from_IXMLDOMElement( iface );
500 const xmlChar *prefix;
503 TRACE("(%p)->(%p)\n", This, p );
505 if (!p) return E_INVALIDARG;
507 element = get_element( This );
511 prefix = element->ns ? element->ns->prefix : NULL;
512 qname = xmlBuildQName(element->name, prefix, NULL, 0);
514 *p = bstr_from_xmlChar(qname);
515 if (qname != element->name) xmlFree(qname);
517 return *p ? S_OK : E_OUTOFMEMORY;
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);
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 heap_free(xml_value);
597 static HRESULT WINAPI domelem_removeAttribute(
598 IXMLDOMElement *iface,
601 domelem *This = impl_from_IXMLDOMElement( iface );
602 IXMLDOMNamedNodeMap *attr;
605 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
607 hr = IXMLDOMElement_get_attributes(iface, &attr);
608 if (hr != S_OK) return hr;
610 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
611 IXMLDOMNamedNodeMap_Release(attr);
616 static HRESULT WINAPI domelem_getAttributeNode(
617 IXMLDOMElement *iface,
618 BSTR p, IXMLDOMAttribute** attributeNode )
620 domelem *This = impl_from_IXMLDOMElement( iface );
625 HRESULT hr = S_FALSE;
627 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
632 *attributeNode = NULL;
634 element = get_element( This );
638 xml_name = xmlChar_from_wchar(p);
640 if(!xmlValidateNameValue(xml_name))
646 attr = xmlHasProp(element, xml_name);
648 unk = create_attribute((xmlNodePtr)attr);
649 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
650 IUnknown_Release(unk);
658 static HRESULT WINAPI domelem_setAttributeNode(
659 IXMLDOMElement *iface,
660 IXMLDOMAttribute* domAttribute,
661 IXMLDOMAttribute** attributeNode)
663 domelem *This = impl_from_IXMLDOMElement( iface );
665 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
667 if(!domAttribute) return E_INVALIDARG;
672 static HRESULT WINAPI domelem_removeAttributeNode(
673 IXMLDOMElement *iface,
674 IXMLDOMAttribute* domAttribute,
675 IXMLDOMAttribute** attributeNode)
677 domelem *This = impl_from_IXMLDOMElement( iface );
678 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
682 static HRESULT WINAPI domelem_getElementsByTagName(
683 IXMLDOMElement *iface,
684 BSTR tagName, IXMLDOMNodeList** resultList)
686 domelem *This = impl_from_IXMLDOMElement( iface );
690 TRACE("(%p)->(%s %p)\n", This, debugstr_w(tagName), resultList);
692 if (!tagName || !resultList) return E_INVALIDARG;
693 if (!(element = get_element(This))) return E_FAIL;
695 if (tagName[0] == '*' && tagName[1] == 0)
697 static const WCHAR formatallW[] = {'/','/','*',0};
698 hr = queryresult_create(element, formatallW, resultList);
702 static const WCHAR xpathformat[] =
703 { '/','/','*','[','l','o','c','a','l','-','n','a','m','e','(',')','=','\'' };
704 static const WCHAR closeW[] = { '\'',']',0 };
710 length = lstrlenW(tagName);
712 /* without two WCHARs from format specifier */
713 ptr = pattern = heap_alloc(sizeof(xpathformat) + length*sizeof(WCHAR) + sizeof(closeW));
715 memcpy(ptr, xpathformat, sizeof(xpathformat));
716 ptr += sizeof(xpathformat)/sizeof(WCHAR);
717 memcpy(ptr, tagName, length*sizeof(WCHAR));
719 memcpy(ptr, closeW, sizeof(closeW));
721 TRACE("%s\n", debugstr_w(pattern));
722 hr = queryresult_create(element, pattern, resultList);
729 static HRESULT WINAPI domelem_normalize(
730 IXMLDOMElement *iface )
732 domelem *This = impl_from_IXMLDOMElement( iface );
737 static const struct IXMLDOMElementVtbl domelem_vtbl =
739 domelem_QueryInterface,
742 domelem_GetTypeInfoCount,
744 domelem_GetIDsOfNames,
746 domelem_get_nodeName,
747 domelem_get_nodeValue,
748 domelem_put_nodeValue,
749 domelem_get_nodeType,
750 domelem_get_parentNode,
751 domelem_get_childNodes,
752 domelem_get_firstChild,
753 domelem_get_lastChild,
754 domelem_get_previousSibling,
755 domelem_get_nextSibling,
756 domelem_get_attributes,
757 domelem_insertBefore,
758 domelem_replaceChild,
761 domelem_hasChildNodes,
762 domelem_get_ownerDocument,
764 domelem_get_nodeTypeString,
767 domelem_get_specified,
768 domelem_get_definition,
769 domelem_get_nodeTypedValue,
770 domelem_put_nodeTypedValue,
771 domelem_get_dataType,
772 domelem_put_dataType,
774 domelem_transformNode,
776 domelem_selectSingleNode,
778 domelem_get_namespaceURI,
780 domelem_get_baseName,
781 domelem_transformNodeToObject,
783 domelem_getAttribute,
784 domelem_setAttribute,
785 domelem_removeAttribute,
786 domelem_getAttributeNode,
787 domelem_setAttributeNode,
788 domelem_removeAttributeNode,
789 domelem_getElementsByTagName,
793 static const tid_t domelem_iface_tids[] = {
798 static dispex_static_data_t domelem_dispex = {
805 IUnknown* create_element( xmlNodePtr element )
809 This = heap_alloc( sizeof *This );
813 This->lpVtbl = &domelem_vtbl;
816 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->lpVtbl, &domelem_dispex);
818 return (IUnknown*) &This->lpVtbl;