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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "msxml_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
40 typedef struct _domelem
42 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 xmlNodePtr_from_domnode( This->node, XML_ELEMENT_NODE );
58 static HRESULT WINAPI domelem_QueryInterface(
59 IXMLDOMElement *iface,
63 domelem *This = impl_from_IXMLDOMElement( iface );
64 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
66 if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
67 IsEqualGUID( riid, &IID_IUnknown ) )
71 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
72 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
74 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
78 FIXME("interface %s not implemented\n", debugstr_guid(riid));
82 IXMLDOMElement_AddRef( iface );
87 static ULONG WINAPI domelem_AddRef(
88 IXMLDOMElement *iface )
90 domelem *This = impl_from_IXMLDOMElement( iface );
91 return InterlockedIncrement( &This->ref );
94 static ULONG WINAPI domelem_Release(
95 IXMLDOMElement *iface )
97 domelem *This = impl_from_IXMLDOMElement( iface );
100 ref = InterlockedDecrement( &This->ref );
103 IUnknown_Release( This->node_unk );
104 HeapFree( GetProcessHeap(), 0, This );
110 static HRESULT WINAPI domelem_GetTypeInfoCount(
111 IXMLDOMElement *iface,
118 static HRESULT WINAPI domelem_GetTypeInfo(
119 IXMLDOMElement *iface,
120 UINT iTInfo, LCID lcid,
121 ITypeInfo** ppTInfo )
127 static HRESULT WINAPI domelem_GetIDsOfNames(
128 IXMLDOMElement *iface,
129 REFIID riid, LPOLESTR* rgszNames,
130 UINT cNames, LCID lcid, DISPID* rgDispId )
136 static HRESULT WINAPI domelem_Invoke(
137 IXMLDOMElement *iface,
138 DISPID dispIdMember, REFIID riid, LCID lcid,
139 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
140 EXCEPINFO* pExcepInfo, UINT* puArgErr )
146 static HRESULT WINAPI domelem_get_nodeName(
147 IXMLDOMElement *iface,
150 domelem *This = impl_from_IXMLDOMElement( iface );
151 return IXMLDOMNode_get_nodeName( This->node, p );
154 static HRESULT WINAPI domelem_get_nodeValue(
155 IXMLDOMElement *iface,
158 domelem *This = impl_from_IXMLDOMElement( iface );
159 return IXMLDOMNode_get_nodeValue( This->node, var1 );
162 static HRESULT WINAPI domelem_put_nodeValue(
163 IXMLDOMElement *iface,
166 domelem *This = impl_from_IXMLDOMElement( iface );
167 return IXMLDOMNode_put_nodeValue( This->node, var1 );
170 static HRESULT WINAPI domelem_get_nodeType(
171 IXMLDOMElement *iface,
172 DOMNodeType* domNodeType )
174 domelem *This = impl_from_IXMLDOMElement( iface );
175 return IXMLDOMNode_get_nodeType( This->node, domNodeType );
178 static HRESULT WINAPI domelem_get_parentNode(
179 IXMLDOMElement *iface,
180 IXMLDOMNode** parent )
182 domelem *This = impl_from_IXMLDOMElement( iface );
183 return IXMLDOMNode_get_parentNode( This->node, parent );
186 static HRESULT WINAPI domelem_get_childNodes(
187 IXMLDOMElement *iface,
188 IXMLDOMNodeList** outList)
190 domelem *This = impl_from_IXMLDOMElement( iface );
191 return IXMLDOMNode_get_childNodes( This->node, outList );
194 static HRESULT WINAPI domelem_get_firstChild(
195 IXMLDOMElement *iface,
196 IXMLDOMNode** domNode)
198 domelem *This = impl_from_IXMLDOMElement( iface );
199 return IXMLDOMNode_get_firstChild( This->node, domNode );
202 static HRESULT WINAPI domelem_get_lastChild(
203 IXMLDOMElement *iface,
204 IXMLDOMNode** domNode)
206 domelem *This = impl_from_IXMLDOMElement( iface );
207 return IXMLDOMNode_get_lastChild( This->node, domNode );
210 static HRESULT WINAPI domelem_get_previousSibling(
211 IXMLDOMElement *iface,
212 IXMLDOMNode** domNode)
214 domelem *This = impl_from_IXMLDOMElement( iface );
215 return IXMLDOMNode_get_previousSibling( This->node, domNode );
218 static HRESULT WINAPI domelem_get_nextSibling(
219 IXMLDOMElement *iface,
220 IXMLDOMNode** domNode)
222 domelem *This = impl_from_IXMLDOMElement( iface );
223 return IXMLDOMNode_get_nextSibling( This->node, domNode );
226 static HRESULT WINAPI domelem_get_attributes(
227 IXMLDOMElement *iface,
228 IXMLDOMNamedNodeMap** attributeMap)
230 domelem *This = impl_from_IXMLDOMElement( iface );
231 return IXMLDOMNode_get_attributes( This->node, attributeMap );
234 static HRESULT WINAPI domelem_insertBefore(
235 IXMLDOMElement *iface,
236 IXMLDOMNode* newNode, VARIANT var1,
237 IXMLDOMNode** outOldNode)
239 domelem *This = impl_from_IXMLDOMElement( iface );
240 return IXMLDOMNode_insertBefore( This->node, newNode, var1, outOldNode );
243 static HRESULT WINAPI domelem_replaceChild(
244 IXMLDOMElement *iface,
245 IXMLDOMNode* newNode,
246 IXMLDOMNode* oldNode,
247 IXMLDOMNode** outOldNode)
249 domelem *This = impl_from_IXMLDOMElement( iface );
250 return IXMLDOMNode_replaceChild( This->node, newNode, oldNode, outOldNode );
253 static HRESULT WINAPI domelem_removeChild(
254 IXMLDOMElement *iface,
255 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
257 domelem *This = impl_from_IXMLDOMElement( iface );
258 return IXMLDOMNode_removeChild( This->node, domNode, oldNode );
261 static HRESULT WINAPI domelem_appendChild(
262 IXMLDOMElement *iface,
263 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
265 domelem *This = impl_from_IXMLDOMElement( iface );
266 return IXMLDOMNode_appendChild( This->node, newNode, outNewNode );
269 static HRESULT WINAPI domelem_hasChildNodes(
270 IXMLDOMElement *iface,
273 domelem *This = impl_from_IXMLDOMElement( iface );
274 return IXMLDOMNode_hasChildNodes( This->node, pbool );
277 static HRESULT WINAPI domelem_get_ownerDocument(
278 IXMLDOMElement *iface,
279 IXMLDOMDocument** domDocument)
281 domelem *This = impl_from_IXMLDOMElement( iface );
282 return IXMLDOMNode_get_ownerDocument( This->node, domDocument );
285 static HRESULT WINAPI domelem_cloneNode(
286 IXMLDOMElement *iface,
287 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
289 domelem *This = impl_from_IXMLDOMElement( iface );
290 return IXMLDOMNode_cloneNode( This->node, pbool, outNode );
293 static HRESULT WINAPI domelem_get_nodeTypeString(
294 IXMLDOMElement *iface,
297 domelem *This = impl_from_IXMLDOMElement( iface );
298 return IXMLDOMNode_get_nodeTypeString( This->node, p );
301 static HRESULT WINAPI domelem_get_text(
302 IXMLDOMElement *iface,
305 domelem *This = impl_from_IXMLDOMElement( iface );
306 return IXMLDOMNode_get_text( This->node, p );
309 static HRESULT WINAPI domelem_put_text(
310 IXMLDOMElement *iface,
313 domelem *This = impl_from_IXMLDOMElement( iface );
314 return IXMLDOMNode_put_text( This->node, p );
317 static HRESULT WINAPI domelem_get_specified(
318 IXMLDOMElement *iface,
321 domelem *This = impl_from_IXMLDOMElement( iface );
322 return IXMLDOMNode_get_specified( This->node, pbool );
325 static HRESULT WINAPI domelem_get_definition(
326 IXMLDOMElement *iface,
327 IXMLDOMNode** domNode)
329 domelem *This = impl_from_IXMLDOMElement( iface );
330 return IXMLDOMNode_get_definition( This->node, domNode );
333 static HRESULT WINAPI domelem_get_nodeTypedValue(
334 IXMLDOMElement *iface,
337 domelem *This = impl_from_IXMLDOMElement( iface );
338 return IXMLDOMNode_get_nodeTypedValue( This->node, var1 );
341 static HRESULT WINAPI domelem_put_nodeTypedValue(
342 IXMLDOMElement *iface,
345 domelem *This = impl_from_IXMLDOMElement( iface );
346 return IXMLDOMNode_put_nodeTypedValue( This->node, var1 );
349 static HRESULT WINAPI domelem_get_dataType(
350 IXMLDOMElement *iface,
353 domelem *This = impl_from_IXMLDOMElement( iface );
354 return IXMLDOMNode_get_dataType( This->node, var1 );
357 static HRESULT WINAPI domelem_put_dataType(
358 IXMLDOMElement *iface,
361 domelem *This = impl_from_IXMLDOMElement( iface );
362 return IXMLDOMNode_put_dataType( This->node, p );
365 static HRESULT WINAPI domelem_get_xml(
366 IXMLDOMElement *iface,
369 domelem *This = impl_from_IXMLDOMElement( iface );
370 return IXMLDOMNode_get_xml( This->node, p );
373 static HRESULT WINAPI domelem_transformNode(
374 IXMLDOMElement *iface,
375 IXMLDOMNode* domNode, BSTR* p)
377 domelem *This = impl_from_IXMLDOMElement( iface );
378 return IXMLDOMNode_transformNode( This->node, domNode, p );
381 static HRESULT WINAPI domelem_selectNodes(
382 IXMLDOMElement *iface,
383 BSTR p, IXMLDOMNodeList** outList)
385 domelem *This = impl_from_IXMLDOMElement( iface );
386 return IXMLDOMNode_selectNodes( This->node, p, outList );
389 static HRESULT WINAPI domelem_selectSingleNode(
390 IXMLDOMElement *iface,
391 BSTR p, IXMLDOMNode** outNode)
393 domelem *This = impl_from_IXMLDOMElement( iface );
394 return IXMLDOMNode_selectSingleNode( This->node, p, outNode );
397 static HRESULT WINAPI domelem_get_parsed(
398 IXMLDOMElement *iface,
401 domelem *This = impl_from_IXMLDOMElement( iface );
402 return IXMLDOMNode_get_parsed( This->node, pbool );
405 static HRESULT WINAPI domelem_get_namespaceURI(
406 IXMLDOMElement *iface,
409 domelem *This = impl_from_IXMLDOMElement( iface );
410 return IXMLDOMNode_get_namespaceURI( This->node, p );
413 static HRESULT WINAPI domelem_get_prefix(
414 IXMLDOMElement *iface,
417 domelem *This = impl_from_IXMLDOMElement( iface );
418 return IXMLDOMNode_get_prefix( This->node, p );
421 static HRESULT WINAPI domelem_get_baseName(
422 IXMLDOMElement *iface,
425 domelem *This = impl_from_IXMLDOMElement( iface );
426 return IXMLDOMNode_get_baseName( This->node, p );
429 static HRESULT WINAPI domelem_transformNodeToObject(
430 IXMLDOMElement *iface,
431 IXMLDOMNode* domNode, VARIANT var1)
433 domelem *This = impl_from_IXMLDOMElement( iface );
434 return IXMLDOMNode_transformNodeToObject( This->node, domNode, var1 );
437 static HRESULT WINAPI domelem_get_tagName(
438 IXMLDOMElement *iface,
441 domelem *This = impl_from_IXMLDOMElement( iface );
444 TRACE("%p\n", This );
449 element = get_element( This );
453 *p = bstr_from_xmlChar( element->name );
458 static HRESULT WINAPI domelem_getAttribute(
459 IXMLDOMElement *iface,
460 BSTR name, VARIANT* value)
462 domelem *This = impl_from_IXMLDOMElement( iface );
464 xmlChar *xml_name, *xml_value;
467 TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), value);
469 element = get_element( This );
474 xml_name = xmlChar_from_wchar( name );
475 xml_value = xmlGetNsProp(element, xml_name, NULL);
476 HeapFree(GetProcessHeap(), 0, xml_name);
479 V_VT(value) = VT_BSTR;
480 V_BSTR(value) = bstr_from_xmlChar( xml_value );
488 static HRESULT WINAPI domelem_setAttribute(
489 IXMLDOMElement *iface,
490 BSTR name, VARIANT value)
492 domelem *This = impl_from_IXMLDOMElement( iface );
494 xmlChar *xml_name, *xml_value;
498 TRACE("(%p)->(%s, var)\n", This, debugstr_w(name));
500 element = get_element( This );
505 hr = VariantChangeType(&var, &value, 0, VT_BSTR);
508 FIXME("VariantChangeType failed\n");
512 xml_name = xmlChar_from_wchar( name );
513 xml_value = xmlChar_from_wchar( V_BSTR(&var) );
515 if(!xmlSetNsProp(element, NULL, xml_name, xml_value))
518 HeapFree(GetProcessHeap(), 0, xml_value);
519 HeapFree(GetProcessHeap(), 0, xml_name);
525 static HRESULT WINAPI domelem_removeAttribute(
526 IXMLDOMElement *iface,
533 static HRESULT WINAPI domelem_getAttributeNode(
534 IXMLDOMElement *iface,
535 BSTR p, IXMLDOMAttribute** attributeNode )
541 static HRESULT WINAPI domelem_setAttributeNode(
542 IXMLDOMElement *iface,
543 IXMLDOMAttribute* domAttribute,
544 IXMLDOMAttribute** attributeNode)
550 static HRESULT WINAPI domelem_removeAttributeNode(
551 IXMLDOMElement *iface,
552 IXMLDOMAttribute* domAttribute,
553 IXMLDOMAttribute** attributeNode)
559 static HRESULT WINAPI domelem_getElementsByTagName(
560 IXMLDOMElement *iface,
561 BSTR p, IXMLDOMNodeList** resultList)
567 static HRESULT WINAPI domelem_normalize(
568 IXMLDOMElement *iface )
574 static const struct IXMLDOMElementVtbl domelem_vtbl =
576 domelem_QueryInterface,
579 domelem_GetTypeInfoCount,
581 domelem_GetIDsOfNames,
583 domelem_get_nodeName,
584 domelem_get_nodeValue,
585 domelem_put_nodeValue,
586 domelem_get_nodeType,
587 domelem_get_parentNode,
588 domelem_get_childNodes,
589 domelem_get_firstChild,
590 domelem_get_lastChild,
591 domelem_get_previousSibling,
592 domelem_get_nextSibling,
593 domelem_get_attributes,
594 domelem_insertBefore,
595 domelem_replaceChild,
598 domelem_hasChildNodes,
599 domelem_get_ownerDocument,
601 domelem_get_nodeTypeString,
604 domelem_get_specified,
605 domelem_get_definition,
606 domelem_get_nodeTypedValue,
607 domelem_put_nodeTypedValue,
608 domelem_get_dataType,
609 domelem_put_dataType,
611 domelem_transformNode,
613 domelem_selectSingleNode,
615 domelem_get_namespaceURI,
617 domelem_get_baseName,
618 domelem_transformNodeToObject,
620 domelem_getAttribute,
621 domelem_setAttribute,
622 domelem_removeAttribute,
623 domelem_getAttributeNode,
624 domelem_setAttributeNode,
625 domelem_removeAttributeNode,
626 domelem_getElementsByTagName,
630 IUnknown* create_element( xmlNodePtr element )
635 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
639 This->lpVtbl = &domelem_vtbl;
642 This->node_unk = create_basic_node( element, (IUnknown*)&This->lpVtbl );
645 HeapFree(GetProcessHeap(), 0, This);
649 hr = IUnknown_QueryInterface(This->node_unk, &IID_IXMLDOMNode, (LPVOID*)&This->node);
652 IUnknown_Release(This->node_unk);
653 HeapFree( GetProcessHeap(), 0, This );
656 /* The ref on This->node is actually looped back into this object, so release it */
657 IXMLDOMNode_Release(This->node);
659 return (IUnknown*) &This->lpVtbl;