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 );
233 return IXMLDOMNode_get_nodeType( IXMLDOMNode_from_impl(&This->node), domNodeType );
236 static HRESULT WINAPI domelem_get_parentNode(
237 IXMLDOMElement *iface,
238 IXMLDOMNode** parent )
240 domelem *This = impl_from_IXMLDOMElement( iface );
241 return IXMLDOMNode_get_parentNode( IXMLDOMNode_from_impl(&This->node), parent );
244 static HRESULT WINAPI domelem_get_childNodes(
245 IXMLDOMElement *iface,
246 IXMLDOMNodeList** outList)
248 domelem *This = impl_from_IXMLDOMElement( iface );
249 return IXMLDOMNode_get_childNodes( IXMLDOMNode_from_impl(&This->node), outList );
252 static HRESULT WINAPI domelem_get_firstChild(
253 IXMLDOMElement *iface,
254 IXMLDOMNode** domNode)
256 domelem *This = impl_from_IXMLDOMElement( iface );
257 return IXMLDOMNode_get_firstChild( IXMLDOMNode_from_impl(&This->node), domNode );
260 static HRESULT WINAPI domelem_get_lastChild(
261 IXMLDOMElement *iface,
262 IXMLDOMNode** domNode)
264 domelem *This = impl_from_IXMLDOMElement( iface );
265 return IXMLDOMNode_get_lastChild( IXMLDOMNode_from_impl(&This->node), domNode );
268 static HRESULT WINAPI domelem_get_previousSibling(
269 IXMLDOMElement *iface,
270 IXMLDOMNode** domNode)
272 domelem *This = impl_from_IXMLDOMElement( iface );
273 return IXMLDOMNode_get_previousSibling( IXMLDOMNode_from_impl(&This->node), domNode );
276 static HRESULT WINAPI domelem_get_nextSibling(
277 IXMLDOMElement *iface,
278 IXMLDOMNode** domNode)
280 domelem *This = impl_from_IXMLDOMElement( iface );
281 return IXMLDOMNode_get_nextSibling( IXMLDOMNode_from_impl(&This->node), domNode );
284 static HRESULT WINAPI domelem_get_attributes(
285 IXMLDOMElement *iface,
286 IXMLDOMNamedNodeMap** attributeMap)
288 domelem *This = impl_from_IXMLDOMElement( iface );
289 return IXMLDOMNode_get_attributes( IXMLDOMNode_from_impl(&This->node), attributeMap );
292 static HRESULT WINAPI domelem_insertBefore(
293 IXMLDOMElement *iface,
294 IXMLDOMNode* newNode, VARIANT var1,
295 IXMLDOMNode** outOldNode)
297 domelem *This = impl_from_IXMLDOMElement( iface );
298 return IXMLDOMNode_insertBefore( IXMLDOMNode_from_impl(&This->node), newNode, var1, outOldNode );
301 static HRESULT WINAPI domelem_replaceChild(
302 IXMLDOMElement *iface,
303 IXMLDOMNode* newNode,
304 IXMLDOMNode* oldNode,
305 IXMLDOMNode** outOldNode)
307 domelem *This = impl_from_IXMLDOMElement( iface );
308 return IXMLDOMNode_replaceChild( IXMLDOMNode_from_impl(&This->node), newNode, oldNode, outOldNode );
311 static HRESULT WINAPI domelem_removeChild(
312 IXMLDOMElement *iface,
313 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
315 domelem *This = impl_from_IXMLDOMElement( iface );
316 return IXMLDOMNode_removeChild( IXMLDOMNode_from_impl(&This->node), domNode, oldNode );
319 static HRESULT WINAPI domelem_appendChild(
320 IXMLDOMElement *iface,
321 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
323 domelem *This = impl_from_IXMLDOMElement( iface );
324 return IXMLDOMNode_appendChild( IXMLDOMNode_from_impl(&This->node), newNode, outNewNode );
327 static HRESULT WINAPI domelem_hasChildNodes(
328 IXMLDOMElement *iface,
331 domelem *This = impl_from_IXMLDOMElement( iface );
332 return IXMLDOMNode_hasChildNodes( IXMLDOMNode_from_impl(&This->node), pbool );
335 static HRESULT WINAPI domelem_get_ownerDocument(
336 IXMLDOMElement *iface,
337 IXMLDOMDocument** domDocument)
339 domelem *This = impl_from_IXMLDOMElement( iface );
340 return IXMLDOMNode_get_ownerDocument( IXMLDOMNode_from_impl(&This->node), domDocument );
343 static HRESULT WINAPI domelem_cloneNode(
344 IXMLDOMElement *iface,
345 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
347 domelem *This = impl_from_IXMLDOMElement( iface );
348 return IXMLDOMNode_cloneNode( IXMLDOMNode_from_impl(&This->node), pbool, outNode );
351 static HRESULT WINAPI domelem_get_nodeTypeString(
352 IXMLDOMElement *iface,
355 domelem *This = impl_from_IXMLDOMElement( iface );
356 return IXMLDOMNode_get_nodeTypeString( IXMLDOMNode_from_impl(&This->node), p );
359 static HRESULT WINAPI domelem_get_text(
360 IXMLDOMElement *iface,
363 domelem *This = impl_from_IXMLDOMElement( iface );
364 return IXMLDOMNode_get_text( IXMLDOMNode_from_impl(&This->node), p );
367 static HRESULT WINAPI domelem_put_text(
368 IXMLDOMElement *iface,
371 domelem *This = impl_from_IXMLDOMElement( iface );
372 return IXMLDOMNode_put_text( IXMLDOMNode_from_impl(&This->node), p );
375 static HRESULT WINAPI domelem_get_specified(
376 IXMLDOMElement *iface,
379 domelem *This = impl_from_IXMLDOMElement( iface );
380 return IXMLDOMNode_get_specified( IXMLDOMNode_from_impl(&This->node), pbool );
383 static HRESULT WINAPI domelem_get_definition(
384 IXMLDOMElement *iface,
385 IXMLDOMNode** domNode)
387 domelem *This = impl_from_IXMLDOMElement( iface );
388 return IXMLDOMNode_get_definition( IXMLDOMNode_from_impl(&This->node), domNode );
391 static HRESULT WINAPI domelem_get_nodeTypedValue(
392 IXMLDOMElement *iface,
395 domelem *This = impl_from_IXMLDOMElement( iface );
396 return IXMLDOMNode_get_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
399 static HRESULT WINAPI domelem_put_nodeTypedValue(
400 IXMLDOMElement *iface,
403 domelem *This = impl_from_IXMLDOMElement( iface );
404 return IXMLDOMNode_put_nodeTypedValue( IXMLDOMNode_from_impl(&This->node), var1 );
407 static HRESULT WINAPI domelem_get_dataType(
408 IXMLDOMElement *iface,
411 domelem *This = impl_from_IXMLDOMElement( iface );
412 return IXMLDOMNode_get_dataType( IXMLDOMNode_from_impl(&This->node), var1 );
415 static HRESULT WINAPI domelem_put_dataType(
416 IXMLDOMElement *iface,
419 domelem *This = impl_from_IXMLDOMElement( iface );
420 return IXMLDOMNode_put_dataType( IXMLDOMNode_from_impl(&This->node), p );
423 static HRESULT WINAPI domelem_get_xml(
424 IXMLDOMElement *iface,
427 domelem *This = impl_from_IXMLDOMElement( iface );
428 return IXMLDOMNode_get_xml( IXMLDOMNode_from_impl(&This->node), p );
431 static HRESULT WINAPI domelem_transformNode(
432 IXMLDOMElement *iface,
433 IXMLDOMNode* domNode, BSTR* p)
435 domelem *This = impl_from_IXMLDOMElement( iface );
436 return IXMLDOMNode_transformNode( IXMLDOMNode_from_impl(&This->node), domNode, p );
439 static HRESULT WINAPI domelem_selectNodes(
440 IXMLDOMElement *iface,
441 BSTR p, IXMLDOMNodeList** outList)
443 domelem *This = impl_from_IXMLDOMElement( iface );
444 return IXMLDOMNode_selectNodes( IXMLDOMNode_from_impl(&This->node), p, outList );
447 static HRESULT WINAPI domelem_selectSingleNode(
448 IXMLDOMElement *iface,
449 BSTR p, IXMLDOMNode** outNode)
451 domelem *This = impl_from_IXMLDOMElement( iface );
452 return IXMLDOMNode_selectSingleNode( IXMLDOMNode_from_impl(&This->node), p, outNode );
455 static HRESULT WINAPI domelem_get_parsed(
456 IXMLDOMElement *iface,
459 domelem *This = impl_from_IXMLDOMElement( iface );
460 return IXMLDOMNode_get_parsed( IXMLDOMNode_from_impl(&This->node), pbool );
463 static HRESULT WINAPI domelem_get_namespaceURI(
464 IXMLDOMElement *iface,
467 domelem *This = impl_from_IXMLDOMElement( iface );
468 return IXMLDOMNode_get_namespaceURI( IXMLDOMNode_from_impl(&This->node), p );
471 static HRESULT WINAPI domelem_get_prefix(
472 IXMLDOMElement *iface,
475 domelem *This = impl_from_IXMLDOMElement( iface );
476 return IXMLDOMNode_get_prefix( IXMLDOMNode_from_impl(&This->node), p );
479 static HRESULT WINAPI domelem_get_baseName(
480 IXMLDOMElement *iface,
483 domelem *This = impl_from_IXMLDOMElement( iface );
484 return IXMLDOMNode_get_baseName( IXMLDOMNode_from_impl(&This->node), p );
487 static HRESULT WINAPI domelem_transformNodeToObject(
488 IXMLDOMElement *iface,
489 IXMLDOMNode* domNode, VARIANT var1)
491 domelem *This = impl_from_IXMLDOMElement( iface );
492 return IXMLDOMNode_transformNodeToObject( IXMLDOMNode_from_impl(&This->node), domNode, var1 );
495 static HRESULT WINAPI domelem_get_tagName(
496 IXMLDOMElement *iface,
499 domelem *This = impl_from_IXMLDOMElement( iface );
501 const xmlChar *prefix;
504 TRACE("(%p)->(%p)\n", This, p );
506 if (!p) return E_INVALIDARG;
508 element = get_element( This );
512 prefix = element->ns ? element->ns->prefix : NULL;
513 qname = xmlBuildQName(element->name, prefix, NULL, 0);
515 *p = bstr_from_xmlChar(qname);
516 if (qname != element->name) xmlFree(qname);
518 return *p ? S_OK : E_OUTOFMEMORY;
521 static HRESULT WINAPI domelem_getAttribute(
522 IXMLDOMElement *iface,
523 BSTR name, VARIANT* value)
525 domelem *This = impl_from_IXMLDOMElement( iface );
527 xmlChar *xml_name, *xml_value = NULL;
528 HRESULT hr = S_FALSE;
530 TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
535 element = get_element( This );
539 V_BSTR(value) = NULL;
540 V_VT(value) = VT_NULL;
542 xml_name = xmlChar_from_wchar( name );
544 if(!xmlValidateNameValue(xml_name))
547 xml_value = xmlGetNsProp(element, xml_name, NULL);
552 V_VT(value) = VT_BSTR;
553 V_BSTR(value) = bstr_from_xmlChar( xml_value );
561 static HRESULT WINAPI domelem_setAttribute(
562 IXMLDOMElement *iface,
563 BSTR name, VARIANT value)
565 domelem *This = impl_from_IXMLDOMElement( iface );
567 xmlChar *xml_name, *xml_value;
571 TRACE("(%p)->(%s var)\n", This, debugstr_w(name));
573 element = get_element( This );
578 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
581 FIXME("VariantChangeType failed\n");
585 xml_name = xmlChar_from_wchar( name );
586 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
588 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
591 heap_free(xml_value);
598 static HRESULT WINAPI domelem_removeAttribute(
599 IXMLDOMElement *iface,
602 domelem *This = impl_from_IXMLDOMElement( iface );
603 IXMLDOMNamedNodeMap *attr;
606 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
608 hr = IXMLDOMElement_get_attributes(iface, &attr);
609 if (hr != S_OK) return hr;
611 hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
612 IXMLDOMNamedNodeMap_Release(attr);
617 static HRESULT WINAPI domelem_getAttributeNode(
618 IXMLDOMElement *iface,
619 BSTR p, IXMLDOMAttribute** attributeNode )
621 domelem *This = impl_from_IXMLDOMElement( iface );
626 HRESULT hr = S_FALSE;
628 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
633 *attributeNode = NULL;
635 element = get_element( This );
639 xml_name = xmlChar_from_wchar(p);
641 if(!xmlValidateNameValue(xml_name))
647 attr = xmlHasProp(element, xml_name);
649 unk = create_attribute((xmlNodePtr)attr);
650 hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
651 IUnknown_Release(unk);
659 static HRESULT WINAPI domelem_setAttributeNode(
660 IXMLDOMElement *iface,
661 IXMLDOMAttribute* domAttribute,
662 IXMLDOMAttribute** attributeNode)
664 domelem *This = impl_from_IXMLDOMElement( iface );
666 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
668 if(!domAttribute) return E_INVALIDARG;
673 static HRESULT WINAPI domelem_removeAttributeNode(
674 IXMLDOMElement *iface,
675 IXMLDOMAttribute* domAttribute,
676 IXMLDOMAttribute** attributeNode)
678 domelem *This = impl_from_IXMLDOMElement( iface );
679 FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
683 static HRESULT WINAPI domelem_getElementsByTagName(
684 IXMLDOMElement *iface,
685 BSTR tagName, IXMLDOMNodeList** resultList)
687 domelem *This = impl_from_IXMLDOMElement( iface );
691 TRACE("(%p)->(%s %p)\n", This, debugstr_w(tagName), resultList);
693 if (!tagName || !resultList) return E_INVALIDARG;
694 if (!(element = get_element(This))) return E_FAIL;
696 if (tagName[0] == '*' && tagName[1] == 0)
698 static const WCHAR formatallW[] = {'/','/','*',0};
699 hr = queryresult_create(element, formatallW, resultList);
703 static const WCHAR xpathformat[] =
704 { '/','/','*','[','l','o','c','a','l','-','n','a','m','e','(',')','=','\'' };
705 static const WCHAR closeW[] = { '\'',']',0 };
711 length = lstrlenW(tagName);
713 /* without two WCHARs from format specifier */
714 ptr = pattern = heap_alloc(sizeof(xpathformat) + length*sizeof(WCHAR) + sizeof(closeW));
716 memcpy(ptr, xpathformat, sizeof(xpathformat));
717 ptr += sizeof(xpathformat)/sizeof(WCHAR);
718 memcpy(ptr, tagName, length*sizeof(WCHAR));
720 memcpy(ptr, closeW, sizeof(closeW));
722 TRACE("%s\n", debugstr_w(pattern));
723 hr = queryresult_create(element, pattern, resultList);
730 static HRESULT WINAPI domelem_normalize(
731 IXMLDOMElement *iface )
733 domelem *This = impl_from_IXMLDOMElement( iface );
738 static const struct IXMLDOMElementVtbl domelem_vtbl =
740 domelem_QueryInterface,
743 domelem_GetTypeInfoCount,
745 domelem_GetIDsOfNames,
747 domelem_get_nodeName,
748 domelem_get_nodeValue,
749 domelem_put_nodeValue,
750 domelem_get_nodeType,
751 domelem_get_parentNode,
752 domelem_get_childNodes,
753 domelem_get_firstChild,
754 domelem_get_lastChild,
755 domelem_get_previousSibling,
756 domelem_get_nextSibling,
757 domelem_get_attributes,
758 domelem_insertBefore,
759 domelem_replaceChild,
762 domelem_hasChildNodes,
763 domelem_get_ownerDocument,
765 domelem_get_nodeTypeString,
768 domelem_get_specified,
769 domelem_get_definition,
770 domelem_get_nodeTypedValue,
771 domelem_put_nodeTypedValue,
772 domelem_get_dataType,
773 domelem_put_dataType,
775 domelem_transformNode,
777 domelem_selectSingleNode,
779 domelem_get_namespaceURI,
781 domelem_get_baseName,
782 domelem_transformNodeToObject,
784 domelem_getAttribute,
785 domelem_setAttribute,
786 domelem_removeAttribute,
787 domelem_getAttributeNode,
788 domelem_setAttributeNode,
789 domelem_removeAttributeNode,
790 domelem_getElementsByTagName,
794 static const tid_t domelem_iface_tids[] = {
799 static dispex_static_data_t domelem_dispex = {
806 IUnknown* create_element( xmlNodePtr element )
810 This = heap_alloc( sizeof *This );
814 This->lpVtbl = &domelem_vtbl;
817 init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->lpVtbl, &domelem_dispex);
819 return (IUnknown*) &This->lpVtbl;