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 FIXME("(%p)->(v%d)\n", This, V_VT(&value));
228 static HRESULT WINAPI domelem_get_nodeType(
229 IXMLDOMElement *iface,
230 DOMNodeType* domNodeType )
232 domelem *This = impl_from_IXMLDOMElement( iface );
234 TRACE("(%p)->(%p)\n", This, domNodeType);
236 *domNodeType = NODE_ELEMENT;
240 static HRESULT WINAPI domelem_get_parentNode(
241 IXMLDOMElement *iface,
242 IXMLDOMNode** parent )
244 domelem *This = impl_from_IXMLDOMElement( iface );
246 TRACE("(%p)->(%p)\n", This, parent);
248 return node_get_parent(&This->node, parent);
251 static HRESULT WINAPI domelem_get_childNodes(
252 IXMLDOMElement *iface,
253 IXMLDOMNodeList** outList)
255 domelem *This = impl_from_IXMLDOMElement( iface );
257 TRACE("(%p)->(%p)\n", This, outList);
259 return node_get_child_nodes(&This->node, outList);
262 static HRESULT WINAPI domelem_get_firstChild(
263 IXMLDOMElement *iface,
264 IXMLDOMNode** domNode)
266 domelem *This = impl_from_IXMLDOMElement( iface );
268 TRACE("(%p)->(%p)\n", This, domNode);
270 return node_get_first_child(&This->node, domNode);
273 static HRESULT WINAPI domelem_get_lastChild(
274 IXMLDOMElement *iface,
275 IXMLDOMNode** domNode)
277 domelem *This = impl_from_IXMLDOMElement( iface );
279 TRACE("(%p)->(%p)\n", This, domNode);
281 return node_get_last_child(&This->node, domNode);
284 static HRESULT WINAPI domelem_get_previousSibling(
285 IXMLDOMElement *iface,
286 IXMLDOMNode** domNode)
288 domelem *This = impl_from_IXMLDOMElement( iface );
290 TRACE("(%p)->(%p)\n", This, domNode);
292 return node_get_previous_sibling(&This->node, domNode);
295 static HRESULT WINAPI domelem_get_nextSibling(
296 IXMLDOMElement *iface,
297 IXMLDOMNode** domNode)
299 domelem *This = impl_from_IXMLDOMElement( iface );
301 TRACE("(%p)->(%p)\n", This, domNode);
303 return node_get_next_sibling(&This->node, domNode);
306 static HRESULT WINAPI domelem_get_attributes(
307 IXMLDOMElement *iface,
308 IXMLDOMNamedNodeMap** attributeMap)
310 domelem *This = impl_from_IXMLDOMElement( iface );
312 TRACE("(%p)->(%p)\n", This, attributeMap);
314 *attributeMap = create_nodemap((IXMLDOMNode*)&This->lpVtbl);
318 static HRESULT WINAPI domelem_insertBefore(
319 IXMLDOMElement *iface,
320 IXMLDOMNode* newNode, VARIANT refChild,
321 IXMLDOMNode** outOldNode)
323 domelem *This = impl_from_IXMLDOMElement( iface );
325 TRACE("(%p)->(%p x%d %p)\n", This, newNode, V_VT(&refChild), outOldNode);
327 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
330 static HRESULT WINAPI domelem_replaceChild(
331 IXMLDOMElement *iface,
332 IXMLDOMNode* newNode,
333 IXMLDOMNode* oldNode,
334 IXMLDOMNode** outOldNode)
336 domelem *This = impl_from_IXMLDOMElement( iface );
337 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
340 static HRESULT WINAPI domelem_removeChild(
341 IXMLDOMElement *iface,
342 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
344 domelem *This = impl_from_IXMLDOMElement( iface );
345 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
348 static HRESULT WINAPI domelem_appendChild(
349 IXMLDOMElement *iface,
350 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
352 domelem *This = impl_from_IXMLDOMElement( iface );
353 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
356 static HRESULT WINAPI domelem_hasChildNodes(
357 IXMLDOMElement *iface,
360 domelem *This = impl_from_IXMLDOMElement( iface );
361 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
364 static HRESULT WINAPI domelem_get_ownerDocument(
365 IXMLDOMElement *iface,
366 IXMLDOMDocument** domDocument)
368 domelem *This = impl_from_IXMLDOMElement( iface );
369 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
372 static HRESULT WINAPI domelem_cloneNode(
373 IXMLDOMElement *iface,
374 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
376 domelem *This = impl_from_IXMLDOMElement( iface );
377 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
380 static HRESULT WINAPI domelem_get_nodeTypeString(
381 IXMLDOMElement *iface,
384 domelem *This = impl_from_IXMLDOMElement( iface );
385 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
388 static HRESULT WINAPI domelem_get_text(
389 IXMLDOMElement *iface,
392 domelem *This = impl_from_IXMLDOMElement( iface );
393 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
396 static HRESULT WINAPI domelem_put_text(
397 IXMLDOMElement *iface,
400 domelem *This = impl_from_IXMLDOMElement( iface );
401 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
404 static HRESULT WINAPI domelem_get_specified(
405 IXMLDOMElement *iface,
408 domelem *This = impl_from_IXMLDOMElement( iface );
409 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
412 static HRESULT WINAPI domelem_get_definition(
413 IXMLDOMElement *iface,
414 IXMLDOMNode** domNode)
416 domelem *This = impl_from_IXMLDOMElement( iface );
417 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
420 static HRESULT WINAPI domelem_get_nodeTypedValue(
421 IXMLDOMElement *iface,
424 domelem *This = impl_from_IXMLDOMElement( iface );
425 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
428 static HRESULT WINAPI domelem_put_nodeTypedValue(
429 IXMLDOMElement *iface,
432 domelem *This = impl_from_IXMLDOMElement( iface );
433 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
436 static HRESULT WINAPI domelem_get_dataType(
437 IXMLDOMElement *iface,
440 domelem *This = impl_from_IXMLDOMElement( iface );
441 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
444 static HRESULT WINAPI domelem_put_dataType(
445 IXMLDOMElement *iface,
448 domelem *This = impl_from_IXMLDOMElement( iface );
449 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
452 static HRESULT WINAPI domelem_get_xml(
453 IXMLDOMElement *iface,
456 domelem *This = impl_from_IXMLDOMElement( iface );
457 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
460 static HRESULT WINAPI domelem_transformNode(
461 IXMLDOMElement *iface,
462 IXMLDOMNode* domNode, BSTR* p)
464 domelem *This = impl_from_IXMLDOMElement( iface );
465 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
468 static HRESULT WINAPI domelem_selectNodes(
469 IXMLDOMElement *iface,
470 BSTR p, IXMLDOMNodeList** outList)
472 domelem *This = impl_from_IXMLDOMElement( iface );
473 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
476 static HRESULT WINAPI domelem_selectSingleNode(
477 IXMLDOMElement *iface,
478 BSTR p, IXMLDOMNode** outNode)
480 domelem *This = impl_from_IXMLDOMElement( iface );
481 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
484 static HRESULT WINAPI domelem_get_parsed(
485 IXMLDOMElement *iface,
488 domelem *This = impl_from_IXMLDOMElement( iface );
489 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
492 static HRESULT WINAPI domelem_get_namespaceURI(
493 IXMLDOMElement *iface,
496 domelem *This = impl_from_IXMLDOMElement( iface );
497 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
500 static HRESULT WINAPI domelem_get_prefix(
501 IXMLDOMElement *iface,
504 domelem *This = impl_from_IXMLDOMElement( iface );
505 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
508 static HRESULT WINAPI domelem_get_baseName(
509 IXMLDOMElement *iface,
512 domelem *This = impl_from_IXMLDOMElement( iface );
513 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
516 static HRESULT WINAPI domelem_transformNodeToObject(
517 IXMLDOMElement *iface,
518 IXMLDOMNode* domNode, VARIANT var1)
520 domelem *This = impl_from_IXMLDOMElement( iface );
521 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
524 static HRESULT WINAPI domelem_get_tagName(
525 IXMLDOMElement *iface,
528 domelem *This = impl_from_IXMLDOMElement( iface );
530 const xmlChar *prefix;
533 TRACE("(%p)->(%p)\n", This, p );
535 if (!p) return E_INVALIDARG;
537 element = get_element( This );
541 prefix = element->ns ? element->ns->prefix : NULL;
542 qname = xmlBuildQName(element->name, prefix, NULL, 0);
544 *p = bstr_from_xmlChar(qname);
545 if (qname != element->name) xmlFree(qname);
547 return *p ? S_OK : E_OUTOFMEMORY;
550 static HRESULT WINAPI domelem_getAttribute(
551 IXMLDOMElement *iface,
552 BSTR name, VARIANT* value)
554 domelem *This = impl_from_IXMLDOMElement( iface );
556 xmlChar *xml_name, *xml_value = NULL;
557 HRESULT hr = S_FALSE;
559 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
564 element = get_element( This );
568 V_BSTR(value) = NULL;
569 V_VT(value) = VT_NULL;
571 xml_name = xmlChar_from_wchar( name );
573 if(!xmlValidateNameValue(xml_name))
576 xml_value = xmlGetNsProp(element, xml_name, NULL);
581 V_VT(value) = VT_BSTR;
582 V_BSTR(value) = bstr_from_xmlChar( xml_value );
590 static HRESULT WINAPI domelem_setAttribute(
591 IXMLDOMElement *iface,
592 BSTR name, VARIANT value)
594 domelem *This = impl_from_IXMLDOMElement( iface );
596 xmlChar *xml_name, *xml_value;
600 TRACE("(%p)->(%s var)\n", This, debugstr_w(name));
602 element = get_element( This );
607 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
610 FIXME("VariantChangeType failed\n");
614 xml_name = xmlChar_from_wchar( name );
615 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
617 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
620 heap_free(xml_value);
627 static HRESULT WINAPI domelem_removeAttribute(
628 IXMLDOMElement *iface,
631 domelem *This = impl_from_IXMLDOMElement( iface );
632 IXMLDOMNamedNodeMap *attr;
635 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
637 hr = IXMLDOMElement_get_attributes(iface, &attr);
638 if (hr != S_OK) return hr;
640 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
641 IXMLDOMNamedNodeMap_Release(attr);
646 static HRESULT WINAPI domelem_getAttributeNode(
647 IXMLDOMElement *iface,
648 BSTR p, IXMLDOMAttribute** attributeNode )
650 domelem *This = impl_from_IXMLDOMElement( iface );
655 HRESULT hr = S_FALSE;
657 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
662 *attributeNode = NULL;
664 element = get_element( This );
668 xml_name = xmlChar_from_wchar(p);
670 if(!xmlValidateNameValue(xml_name))
676 attr = xmlHasProp(element, xml_name);
678 unk = create_attribute((xmlNodePtr)attr);
679 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
680 IUnknown_Release(unk);
688 static HRESULT WINAPI domelem_setAttributeNode(
689 IXMLDOMElement *iface,
690 IXMLDOMAttribute* domAttribute,
691 IXMLDOMAttribute** attributeNode)
693 domelem *This = impl_from_IXMLDOMElement( iface );
695 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
697 if(!domAttribute) return E_INVALIDARG;
702 static HRESULT WINAPI domelem_removeAttributeNode(
703 IXMLDOMElement *iface,
704 IXMLDOMAttribute* domAttribute,
705 IXMLDOMAttribute** attributeNode)
707 domelem *This = impl_from_IXMLDOMElement( iface );
708 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
712 static HRESULT WINAPI domelem_getElementsByTagName(
713 IXMLDOMElement *iface,
714 BSTR tagName, IXMLDOMNodeList** resultList)
716 domelem *This = impl_from_IXMLDOMElement( iface );
720 TRACE("(%p)->(%s %p)\n", This, debugstr_w(tagName), resultList);
722 if (!tagName || !resultList) return E_INVALIDARG;
723 if (!(element = get_element(This))) return E_FAIL;
725 if (tagName[0] == '*' && tagName[1] == 0)
727 static const WCHAR formatallW[] = {'/','/','*',0};
728 hr = queryresult_create(element, formatallW, resultList);
732 static const WCHAR xpathformat[] =
733 { '/','/','*','[','l','o','c','a','l','-','n','a','m','e','(',')','=','\'' };
734 static const WCHAR closeW[] = { '\'',']',0 };
740 length = lstrlenW(tagName);
742 /* without two WCHARs from format specifier */
743 ptr = pattern = heap_alloc(sizeof(xpathformat) + length*sizeof(WCHAR) + sizeof(closeW));
745 memcpy(ptr, xpathformat, sizeof(xpathformat));
746 ptr += sizeof(xpathformat)/sizeof(WCHAR);
747 memcpy(ptr, tagName, length*sizeof(WCHAR));
749 memcpy(ptr, closeW, sizeof(closeW));
751 TRACE("%s\n", debugstr_w(pattern));
752 hr = queryresult_create(element, pattern, resultList);
759 static HRESULT WINAPI domelem_normalize(
760 IXMLDOMElement *iface )
762 domelem *This = impl_from_IXMLDOMElement( iface );
767 static const struct IXMLDOMElementVtbl domelem_vtbl =
769 domelem_QueryInterface,
772 domelem_GetTypeInfoCount,
774 domelem_GetIDsOfNames,
776 domelem_get_nodeName,
777 domelem_get_nodeValue,
778 domelem_put_nodeValue,
779 domelem_get_nodeType,
780 domelem_get_parentNode,
781 domelem_get_childNodes,
782 domelem_get_firstChild,
783 domelem_get_lastChild,
784 domelem_get_previousSibling,
785 domelem_get_nextSibling,
786 domelem_get_attributes,
787 domelem_insertBefore,
788 domelem_replaceChild,
791 domelem_hasChildNodes,
792 domelem_get_ownerDocument,
794 domelem_get_nodeTypeString,
797 domelem_get_specified,
798 domelem_get_definition,
799 domelem_get_nodeTypedValue,
800 domelem_put_nodeTypedValue,
801 domelem_get_dataType,
802 domelem_put_dataType,
804 domelem_transformNode,
806 domelem_selectSingleNode,
808 domelem_get_namespaceURI,
810 domelem_get_baseName,
811 domelem_transformNodeToObject,
813 domelem_getAttribute,
814 domelem_setAttribute,
815 domelem_removeAttribute,
816 domelem_getAttributeNode,
817 domelem_setAttributeNode,
818 domelem_removeAttributeNode,
819 domelem_getElementsByTagName,
823 static const tid_t domelem_iface_tids[] = {
828 static dispex_static_data_t domelem_dispex = {
835 IUnknown* create_element( xmlNodePtr element )
839 This = heap_alloc( sizeof *This );
843 This->lpVtbl = &domelem_vtbl;
846 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->lpVtbl, &domelem_dispex);
848 return (IUnknown*) &This->lpVtbl;