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 );
256 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
259 static HRESULT WINAPI domelem_get_firstChild(
260 IXMLDOMElement *iface,
261 IXMLDOMNode** domNode)
263 domelem *This = impl_from_IXMLDOMElement( iface );
264 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
267 static HRESULT WINAPI domelem_get_lastChild(
268 IXMLDOMElement *iface,
269 IXMLDOMNode** domNode)
271 domelem *This = impl_from_IXMLDOMElement( iface );
272 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
275 static HRESULT WINAPI domelem_get_previousSibling(
276 IXMLDOMElement *iface,
277 IXMLDOMNode** domNode)
279 domelem *This = impl_from_IXMLDOMElement( iface );
280 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
283 static HRESULT WINAPI domelem_get_nextSibling(
284 IXMLDOMElement *iface,
285 IXMLDOMNode** domNode)
287 domelem *This = impl_from_IXMLDOMElement( iface );
288 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
291 static HRESULT WINAPI domelem_get_attributes(
292 IXMLDOMElement *iface,
293 IXMLDOMNamedNodeMap** attributeMap)
295 domelem *This = impl_from_IXMLDOMElement( iface );
296 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
299 static HRESULT WINAPI domelem_insertBefore(
300 IXMLDOMElement *iface,
301 IXMLDOMNode* newNode, VARIANT var1,
302 IXMLDOMNode** outOldNode)
304 domelem *This = impl_from_IXMLDOMElement( iface );
305 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
308 static HRESULT WINAPI domelem_replaceChild(
309 IXMLDOMElement *iface,
310 IXMLDOMNode* newNode,
311 IXMLDOMNode* oldNode,
312 IXMLDOMNode** outOldNode)
314 domelem *This = impl_from_IXMLDOMElement( iface );
315 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
318 static HRESULT WINAPI domelem_removeChild(
319 IXMLDOMElement *iface,
320 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
322 domelem *This = impl_from_IXMLDOMElement( iface );
323 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
326 static HRESULT WINAPI domelem_appendChild(
327 IXMLDOMElement *iface,
328 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
330 domelem *This = impl_from_IXMLDOMElement( iface );
331 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
334 static HRESULT WINAPI domelem_hasChildNodes(
335 IXMLDOMElement *iface,
338 domelem *This = impl_from_IXMLDOMElement( iface );
339 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
342 static HRESULT WINAPI domelem_get_ownerDocument(
343 IXMLDOMElement *iface,
344 IXMLDOMDocument** domDocument)
346 domelem *This = impl_from_IXMLDOMElement( iface );
347 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
350 static HRESULT WINAPI domelem_cloneNode(
351 IXMLDOMElement *iface,
352 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
354 domelem *This = impl_from_IXMLDOMElement( iface );
355 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
358 static HRESULT WINAPI domelem_get_nodeTypeString(
359 IXMLDOMElement *iface,
362 domelem *This = impl_from_IXMLDOMElement( iface );
363 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
366 static HRESULT WINAPI domelem_get_text(
367 IXMLDOMElement *iface,
370 domelem *This = impl_from_IXMLDOMElement( iface );
371 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
374 static HRESULT WINAPI domelem_put_text(
375 IXMLDOMElement *iface,
378 domelem *This = impl_from_IXMLDOMElement( iface );
379 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
382 static HRESULT WINAPI domelem_get_specified(
383 IXMLDOMElement *iface,
386 domelem *This = impl_from_IXMLDOMElement( iface );
387 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
390 static HRESULT WINAPI domelem_get_definition(
391 IXMLDOMElement *iface,
392 IXMLDOMNode** domNode)
394 domelem *This = impl_from_IXMLDOMElement( iface );
395 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
398 static HRESULT WINAPI domelem_get_nodeTypedValue(
399 IXMLDOMElement *iface,
402 domelem *This = impl_from_IXMLDOMElement( iface );
403 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
406 static HRESULT WINAPI domelem_put_nodeTypedValue(
407 IXMLDOMElement *iface,
410 domelem *This = impl_from_IXMLDOMElement( iface );
411 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
414 static HRESULT WINAPI domelem_get_dataType(
415 IXMLDOMElement *iface,
418 domelem *This = impl_from_IXMLDOMElement( iface );
419 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
422 static HRESULT WINAPI domelem_put_dataType(
423 IXMLDOMElement *iface,
426 domelem *This = impl_from_IXMLDOMElement( iface );
427 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
430 static HRESULT WINAPI domelem_get_xml(
431 IXMLDOMElement *iface,
434 domelem *This = impl_from_IXMLDOMElement( iface );
435 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
438 static HRESULT WINAPI domelem_transformNode(
439 IXMLDOMElement *iface,
440 IXMLDOMNode* domNode, BSTR* p)
442 domelem *This = impl_from_IXMLDOMElement( iface );
443 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
446 static HRESULT WINAPI domelem_selectNodes(
447 IXMLDOMElement *iface,
448 BSTR p, IXMLDOMNodeList** outList)
450 domelem *This = impl_from_IXMLDOMElement( iface );
451 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
454 static HRESULT WINAPI domelem_selectSingleNode(
455 IXMLDOMElement *iface,
456 BSTR p, IXMLDOMNode** outNode)
458 domelem *This = impl_from_IXMLDOMElement( iface );
459 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
462 static HRESULT WINAPI domelem_get_parsed(
463 IXMLDOMElement *iface,
466 domelem *This = impl_from_IXMLDOMElement( iface );
467 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
470 static HRESULT WINAPI domelem_get_namespaceURI(
471 IXMLDOMElement *iface,
474 domelem *This = impl_from_IXMLDOMElement( iface );
475 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
478 static HRESULT WINAPI domelem_get_prefix(
479 IXMLDOMElement *iface,
482 domelem *This = impl_from_IXMLDOMElement( iface );
483 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
486 static HRESULT WINAPI domelem_get_baseName(
487 IXMLDOMElement *iface,
490 domelem *This = impl_from_IXMLDOMElement( iface );
491 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
494 static HRESULT WINAPI domelem_transformNodeToObject(
495 IXMLDOMElement *iface,
496 IXMLDOMNode* domNode, VARIANT var1)
498 domelem *This = impl_from_IXMLDOMElement( iface );
499 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
502 static HRESULT WINAPI domelem_get_tagName(
503 IXMLDOMElement *iface,
506 domelem *This = impl_from_IXMLDOMElement( iface );
508 const xmlChar *prefix;
511 TRACE("(%p)->(%p)\n", This, p );
513 if (!p) return E_INVALIDARG;
515 element = get_element( This );
519 prefix = element->ns ? element->ns->prefix : NULL;
520 qname = xmlBuildQName(element->name, prefix, NULL, 0);
522 *p = bstr_from_xmlChar(qname);
523 if (qname != element->name) xmlFree(qname);
525 return *p ? S_OK : E_OUTOFMEMORY;
528 static HRESULT WINAPI domelem_getAttribute(
529 IXMLDOMElement *iface,
530 BSTR name, VARIANT* value)
532 domelem *This = impl_from_IXMLDOMElement( iface );
534 xmlChar *xml_name, *xml_value = NULL;
535 HRESULT hr = S_FALSE;
537 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
542 element = get_element( This );
546 V_BSTR(value) = NULL;
547 V_VT(value) = VT_NULL;
549 xml_name = xmlChar_from_wchar( name );
551 if(!xmlValidateNameValue(xml_name))
554 xml_value = xmlGetNsProp(element, xml_name, NULL);
559 V_VT(value) = VT_BSTR;
560 V_BSTR(value) = bstr_from_xmlChar( xml_value );
568 static HRESULT WINAPI domelem_setAttribute(
569 IXMLDOMElement *iface,
570 BSTR name, VARIANT value)
572 domelem *This = impl_from_IXMLDOMElement( iface );
574 xmlChar *xml_name, *xml_value;
578 TRACE("(%p)->(%s var)\n", This, debugstr_w(name));
580 element = get_element( This );
585 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
588 FIXME("VariantChangeType failed\n");
592 xml_name = xmlChar_from_wchar( name );
593 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
595 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
598 heap_free(xml_value);
605 static HRESULT WINAPI domelem_removeAttribute(
606 IXMLDOMElement *iface,
609 domelem *This = impl_from_IXMLDOMElement( iface );
610 IXMLDOMNamedNodeMap *attr;
613 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
615 hr = IXMLDOMElement_get_attributes(iface, &attr);
616 if (hr != S_OK) return hr;
618 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
619 IXMLDOMNamedNodeMap_Release(attr);
624 static HRESULT WINAPI domelem_getAttributeNode(
625 IXMLDOMElement *iface,
626 BSTR p, IXMLDOMAttribute** attributeNode )
628 domelem *This = impl_from_IXMLDOMElement( iface );
633 HRESULT hr = S_FALSE;
635 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
640 *attributeNode = NULL;
642 element = get_element( This );
646 xml_name = xmlChar_from_wchar(p);
648 if(!xmlValidateNameValue(xml_name))
654 attr = xmlHasProp(element, xml_name);
656 unk = create_attribute((xmlNodePtr)attr);
657 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
658 IUnknown_Release(unk);
666 static HRESULT WINAPI domelem_setAttributeNode(
667 IXMLDOMElement *iface,
668 IXMLDOMAttribute* domAttribute,
669 IXMLDOMAttribute** attributeNode)
671 domelem *This = impl_from_IXMLDOMElement( iface );
673 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
675 if(!domAttribute) return E_INVALIDARG;
680 static HRESULT WINAPI domelem_removeAttributeNode(
681 IXMLDOMElement *iface,
682 IXMLDOMAttribute* domAttribute,
683 IXMLDOMAttribute** attributeNode)
685 domelem *This = impl_from_IXMLDOMElement( iface );
686 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
690 static HRESULT WINAPI domelem_getElementsByTagName(
691 IXMLDOMElement *iface,
692 BSTR tagName, IXMLDOMNodeList** resultList)
694 domelem *This = impl_from_IXMLDOMElement( iface );
698 TRACE("(%p)->(%s %p)\n", This, debugstr_w(tagName), resultList);
700 if (!tagName || !resultList) return E_INVALIDARG;
701 if (!(element = get_element(This))) return E_FAIL;
703 if (tagName[0] == '*' && tagName[1] == 0)
705 static const WCHAR formatallW[] = {'/','/','*',0};
706 hr = queryresult_create(element, formatallW, resultList);
710 static const WCHAR xpathformat[] =
711 { '/','/','*','[','l','o','c','a','l','-','n','a','m','e','(',')','=','\'' };
712 static const WCHAR closeW[] = { '\'',']',0 };
718 length = lstrlenW(tagName);
720 /* without two WCHARs from format specifier */
721 ptr = pattern = heap_alloc(sizeof(xpathformat) + length*sizeof(WCHAR) + sizeof(closeW));
723 memcpy(ptr, xpathformat, sizeof(xpathformat));
724 ptr += sizeof(xpathformat)/sizeof(WCHAR);
725 memcpy(ptr, tagName, length*sizeof(WCHAR));
727 memcpy(ptr, closeW, sizeof(closeW));
729 TRACE("%s\n", debugstr_w(pattern));
730 hr = queryresult_create(element, pattern, resultList);
737 static HRESULT WINAPI domelem_normalize(
738 IXMLDOMElement *iface )
740 domelem *This = impl_from_IXMLDOMElement( iface );
745 static const struct IXMLDOMElementVtbl domelem_vtbl =
747 domelem_QueryInterface,
750 domelem_GetTypeInfoCount,
752 domelem_GetIDsOfNames,
754 domelem_get_nodeName,
755 domelem_get_nodeValue,
756 domelem_put_nodeValue,
757 domelem_get_nodeType,
758 domelem_get_parentNode,
759 domelem_get_childNodes,
760 domelem_get_firstChild,
761 domelem_get_lastChild,
762 domelem_get_previousSibling,
763 domelem_get_nextSibling,
764 domelem_get_attributes,
765 domelem_insertBefore,
766 domelem_replaceChild,
769 domelem_hasChildNodes,
770 domelem_get_ownerDocument,
772 domelem_get_nodeTypeString,
775 domelem_get_specified,
776 domelem_get_definition,
777 domelem_get_nodeTypedValue,
778 domelem_put_nodeTypedValue,
779 domelem_get_dataType,
780 domelem_put_dataType,
782 domelem_transformNode,
784 domelem_selectSingleNode,
786 domelem_get_namespaceURI,
788 domelem_get_baseName,
789 domelem_transformNodeToObject,
791 domelem_getAttribute,
792 domelem_setAttribute,
793 domelem_removeAttribute,
794 domelem_getAttributeNode,
795 domelem_setAttributeNode,
796 domelem_removeAttributeNode,
797 domelem_getElementsByTagName,
801 static const tid_t domelem_iface_tids[] = {
806 static dispex_static_data_t domelem_dispex = {
813 IUnknown* create_element( xmlNodePtr element )
817 This = heap_alloc( sizeof *This );
821 This->lpVtbl = &domelem_vtbl;
824 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->lpVtbl, &domelem_dispex);
826 return (IUnknown*) &This->lpVtbl;