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
43 const struct IXMLDOMElementVtbl
*lpVtbl
;
44 const struct IUnknownVtbl
*lpInternalUnkVtbl
;
51 static inline domelem
*impl_from_IXMLDOMElement( IXMLDOMElement
*iface
)
53 return (domelem
*)((char*)iface
- FIELD_OFFSET(domelem
, lpVtbl
));
56 static inline domelem
*impl_from_InternalUnknown( IUnknown
*iface
)
58 return (domelem
*)((char*)iface
- FIELD_OFFSET(domelem
, lpInternalUnkVtbl
));
61 static inline xmlNodePtr
get_element( domelem
*This
)
63 return xmlNodePtr_from_domnode( This
->node
, XML_ELEMENT_NODE
);
66 static HRESULT WINAPI
domelem_QueryInterface(
67 IXMLDOMElement
*iface
,
71 domelem
*This
= impl_from_IXMLDOMElement( iface
);
72 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
74 return IUnknown_QueryInterface(This
->pUnkOuter
, riid
, ppvObject
);
77 static ULONG WINAPI
domelem_AddRef(
78 IXMLDOMElement
*iface
)
80 domelem
*This
= impl_from_IXMLDOMElement( iface
);
81 return IUnknown_AddRef(This
->pUnkOuter
);
84 static ULONG WINAPI
domelem_Release(
85 IXMLDOMElement
*iface
)
87 domelem
*This
= impl_from_IXMLDOMElement( iface
);
88 return IUnknown_Release(This
->pUnkOuter
);
91 static HRESULT WINAPI
domelem_GetTypeInfoCount(
92 IXMLDOMElement
*iface
,
99 static HRESULT WINAPI
domelem_GetTypeInfo(
100 IXMLDOMElement
*iface
,
101 UINT iTInfo
, LCID lcid
,
102 ITypeInfo
** ppTInfo
)
108 static HRESULT WINAPI
domelem_GetIDsOfNames(
109 IXMLDOMElement
*iface
,
110 REFIID riid
, LPOLESTR
* rgszNames
,
111 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
117 static HRESULT WINAPI
domelem_Invoke(
118 IXMLDOMElement
*iface
,
119 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
120 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
121 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
127 static HRESULT WINAPI
domelem_get_nodeName(
128 IXMLDOMElement
*iface
,
131 domelem
*This
= impl_from_IXMLDOMElement( iface
);
132 return IXMLDOMNode_get_nodeName( This
->node
, p
);
135 static HRESULT WINAPI
domelem_get_nodeValue(
136 IXMLDOMElement
*iface
,
139 domelem
*This
= impl_from_IXMLDOMElement( iface
);
140 return IXMLDOMNode_get_nodeValue( This
->node
, var1
);
143 static HRESULT WINAPI
domelem_put_nodeValue(
144 IXMLDOMElement
*iface
,
147 domelem
*This
= impl_from_IXMLDOMElement( iface
);
148 return IXMLDOMNode_put_nodeValue( This
->node
, var1
);
151 static HRESULT WINAPI
domelem_get_nodeType(
152 IXMLDOMElement
*iface
,
153 DOMNodeType
* domNodeType
)
155 domelem
*This
= impl_from_IXMLDOMElement( iface
);
156 return IXMLDOMNode_get_nodeType( This
->node
, domNodeType
);
159 static HRESULT WINAPI
domelem_get_parentNode(
160 IXMLDOMElement
*iface
,
161 IXMLDOMNode
** parent
)
163 domelem
*This
= impl_from_IXMLDOMElement( iface
);
164 return IXMLDOMNode_get_parentNode( This
->node
, parent
);
167 static HRESULT WINAPI
domelem_get_childNodes(
168 IXMLDOMElement
*iface
,
169 IXMLDOMNodeList
** outList
)
171 domelem
*This
= impl_from_IXMLDOMElement( iface
);
172 return IXMLDOMNode_get_childNodes( This
->node
, outList
);
175 static HRESULT WINAPI
domelem_get_firstChild(
176 IXMLDOMElement
*iface
,
177 IXMLDOMNode
** domNode
)
179 domelem
*This
= impl_from_IXMLDOMElement( iface
);
180 return IXMLDOMNode_get_firstChild( This
->node
, domNode
);
183 static HRESULT WINAPI
domelem_get_lastChild(
184 IXMLDOMElement
*iface
,
185 IXMLDOMNode
** domNode
)
187 domelem
*This
= impl_from_IXMLDOMElement( iface
);
188 return IXMLDOMNode_get_lastChild( This
->node
, domNode
);
191 static HRESULT WINAPI
domelem_get_previousSibling(
192 IXMLDOMElement
*iface
,
193 IXMLDOMNode
** domNode
)
195 domelem
*This
= impl_from_IXMLDOMElement( iface
);
196 return IXMLDOMNode_get_previousSibling( This
->node
, domNode
);
199 static HRESULT WINAPI
domelem_get_nextSibling(
200 IXMLDOMElement
*iface
,
201 IXMLDOMNode
** domNode
)
203 domelem
*This
= impl_from_IXMLDOMElement( iface
);
204 return IXMLDOMNode_get_nextSibling( This
->node
, domNode
);
207 static HRESULT WINAPI
domelem_get_attributes(
208 IXMLDOMElement
*iface
,
209 IXMLDOMNamedNodeMap
** attributeMap
)
211 domelem
*This
= impl_from_IXMLDOMElement( iface
);
212 return IXMLDOMNode_get_attributes( This
->node
, attributeMap
);
215 static HRESULT WINAPI
domelem_insertBefore(
216 IXMLDOMElement
*iface
,
217 IXMLDOMNode
* newNode
, VARIANT var1
,
218 IXMLDOMNode
** outOldNode
)
220 domelem
*This
= impl_from_IXMLDOMElement( iface
);
221 return IXMLDOMNode_insertBefore( This
->node
, newNode
, var1
, outOldNode
);
224 static HRESULT WINAPI
domelem_replaceChild(
225 IXMLDOMElement
*iface
,
226 IXMLDOMNode
* newNode
,
227 IXMLDOMNode
* oldNode
,
228 IXMLDOMNode
** outOldNode
)
230 domelem
*This
= impl_from_IXMLDOMElement( iface
);
231 return IXMLDOMNode_replaceChild( This
->node
, newNode
, oldNode
, outOldNode
);
234 static HRESULT WINAPI
domelem_removeChild(
235 IXMLDOMElement
*iface
,
236 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
238 domelem
*This
= impl_from_IXMLDOMElement( iface
);
239 return IXMLDOMNode_removeChild( This
->node
, domNode
, oldNode
);
242 static HRESULT WINAPI
domelem_appendChild(
243 IXMLDOMElement
*iface
,
244 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
246 domelem
*This
= impl_from_IXMLDOMElement( iface
);
247 return IXMLDOMNode_appendChild( This
->node
, newNode
, outNewNode
);
250 static HRESULT WINAPI
domelem_hasChildNodes(
251 IXMLDOMElement
*iface
,
254 domelem
*This
= impl_from_IXMLDOMElement( iface
);
255 return IXMLDOMNode_hasChildNodes( This
->node
, pbool
);
258 static HRESULT WINAPI
domelem_get_ownerDocument(
259 IXMLDOMElement
*iface
,
260 IXMLDOMDocument
** domDocument
)
262 domelem
*This
= impl_from_IXMLDOMElement( iface
);
263 return IXMLDOMNode_get_ownerDocument( This
->node
, domDocument
);
266 static HRESULT WINAPI
domelem_cloneNode(
267 IXMLDOMElement
*iface
,
268 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
270 domelem
*This
= impl_from_IXMLDOMElement( iface
);
271 return IXMLDOMNode_cloneNode( This
->node
, pbool
, outNode
);
274 static HRESULT WINAPI
domelem_get_nodeTypeString(
275 IXMLDOMElement
*iface
,
278 domelem
*This
= impl_from_IXMLDOMElement( iface
);
279 return IXMLDOMNode_get_nodeTypeString( This
->node
, p
);
282 static HRESULT WINAPI
domelem_get_text(
283 IXMLDOMElement
*iface
,
286 domelem
*This
= impl_from_IXMLDOMElement( iface
);
287 return IXMLDOMNode_get_text( This
->node
, p
);
290 static HRESULT WINAPI
domelem_put_text(
291 IXMLDOMElement
*iface
,
294 domelem
*This
= impl_from_IXMLDOMElement( iface
);
295 return IXMLDOMNode_put_text( This
->node
, p
);
298 static HRESULT WINAPI
domelem_get_specified(
299 IXMLDOMElement
*iface
,
302 domelem
*This
= impl_from_IXMLDOMElement( iface
);
303 return IXMLDOMNode_get_specified( This
->node
, pbool
);
306 static HRESULT WINAPI
domelem_get_definition(
307 IXMLDOMElement
*iface
,
308 IXMLDOMNode
** domNode
)
310 domelem
*This
= impl_from_IXMLDOMElement( iface
);
311 return IXMLDOMNode_get_definition( This
->node
, domNode
);
314 static HRESULT WINAPI
domelem_get_nodeTypedValue(
315 IXMLDOMElement
*iface
,
318 domelem
*This
= impl_from_IXMLDOMElement( iface
);
319 return IXMLDOMNode_get_nodeTypedValue( This
->node
, var1
);
322 static HRESULT WINAPI
domelem_put_nodeTypedValue(
323 IXMLDOMElement
*iface
,
326 domelem
*This
= impl_from_IXMLDOMElement( iface
);
327 return IXMLDOMNode_put_nodeTypedValue( This
->node
, var1
);
330 static HRESULT WINAPI
domelem_get_dataType(
331 IXMLDOMElement
*iface
,
334 domelem
*This
= impl_from_IXMLDOMElement( iface
);
335 return IXMLDOMNode_get_dataType( This
->node
, var1
);
338 static HRESULT WINAPI
domelem_put_dataType(
339 IXMLDOMElement
*iface
,
342 domelem
*This
= impl_from_IXMLDOMElement( iface
);
343 return IXMLDOMNode_put_dataType( This
->node
, p
);
346 static HRESULT WINAPI
domelem_get_xml(
347 IXMLDOMElement
*iface
,
350 domelem
*This
= impl_from_IXMLDOMElement( iface
);
351 return IXMLDOMNode_get_xml( This
->node
, p
);
354 static HRESULT WINAPI
domelem_transformNode(
355 IXMLDOMElement
*iface
,
356 IXMLDOMNode
* domNode
, BSTR
* p
)
358 domelem
*This
= impl_from_IXMLDOMElement( iface
);
359 return IXMLDOMNode_transformNode( This
->node
, domNode
, p
);
362 static HRESULT WINAPI
domelem_selectNodes(
363 IXMLDOMElement
*iface
,
364 BSTR p
, IXMLDOMNodeList
** outList
)
366 domelem
*This
= impl_from_IXMLDOMElement( iface
);
367 return IXMLDOMNode_selectNodes( This
->node
, p
, outList
);
370 static HRESULT WINAPI
domelem_selectSingleNode(
371 IXMLDOMElement
*iface
,
372 BSTR p
, IXMLDOMNode
** outNode
)
374 domelem
*This
= impl_from_IXMLDOMElement( iface
);
375 return IXMLDOMNode_selectSingleNode( This
->node
, p
, outNode
);
378 static HRESULT WINAPI
domelem_get_parsed(
379 IXMLDOMElement
*iface
,
382 domelem
*This
= impl_from_IXMLDOMElement( iface
);
383 return IXMLDOMNode_get_parsed( This
->node
, pbool
);
386 static HRESULT WINAPI
domelem_get_namespaceURI(
387 IXMLDOMElement
*iface
,
390 domelem
*This
= impl_from_IXMLDOMElement( iface
);
391 return IXMLDOMNode_get_namespaceURI( This
->node
, p
);
394 static HRESULT WINAPI
domelem_get_prefix(
395 IXMLDOMElement
*iface
,
398 domelem
*This
= impl_from_IXMLDOMElement( iface
);
399 return IXMLDOMNode_get_prefix( This
->node
, p
);
402 static HRESULT WINAPI
domelem_get_baseName(
403 IXMLDOMElement
*iface
,
406 domelem
*This
= impl_from_IXMLDOMElement( iface
);
407 return IXMLDOMNode_get_baseName( This
->node
, p
);
410 static HRESULT WINAPI
domelem_transformNodeToObject(
411 IXMLDOMElement
*iface
,
412 IXMLDOMNode
* domNode
, VARIANT var1
)
414 domelem
*This
= impl_from_IXMLDOMElement( iface
);
415 return IXMLDOMNode_transformNodeToObject( This
->node
, domNode
, var1
);
418 static HRESULT WINAPI
domelem_get_tagName(
419 IXMLDOMElement
*iface
,
422 domelem
*This
= impl_from_IXMLDOMElement( iface
);
428 TRACE("%p\n", This
);
433 element
= get_element( This
);
437 len
= MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) element
->name
, -1, NULL
, 0 );
439 len
+= MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) element
->ns
->prefix
, -1, NULL
, 0 );
440 str
= (LPWSTR
) HeapAlloc( GetProcessHeap(), 0, len
* sizeof (WCHAR
) );
442 return E_OUTOFMEMORY
;
445 offset
= MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) element
->ns
->prefix
, -1, str
, len
);
446 str
[offset
- 1] = ':';
448 MultiByteToWideChar( CP_UTF8
, 0, (LPCSTR
) element
->name
, -1, str
+ offset
, len
- offset
);
449 *p
= SysAllocString( str
);
450 HeapFree( GetProcessHeap(), 0, str
);
455 static HRESULT WINAPI
domelem_getAttribute(
456 IXMLDOMElement
*iface
,
457 BSTR name
, VARIANT
* value
)
459 domelem
*This
= impl_from_IXMLDOMElement( iface
);
461 xmlChar
*xml_name
, *xml_value
;
464 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(name
), value
);
466 element
= get_element( This
);
471 xml_name
= xmlChar_from_wchar( name
);
472 xml_value
= xmlGetNsProp(element
, xml_name
, NULL
);
473 HeapFree(GetProcessHeap(), 0, xml_name
);
476 V_VT(value
) = VT_BSTR
;
477 V_BSTR(value
) = bstr_from_xmlChar( xml_value
);
485 static HRESULT WINAPI
domelem_setAttribute(
486 IXMLDOMElement
*iface
,
487 BSTR name
, VARIANT value
)
489 domelem
*This
= impl_from_IXMLDOMElement( iface
);
491 xmlChar
*xml_name
, *xml_value
;
495 TRACE("(%p)->(%s, var)\n", This
, debugstr_w(name
));
497 element
= get_element( This
);
502 hr
= VariantChangeType(&var
, &value
, 0, VT_BSTR
);
505 FIXME("VariantChangeType failed\n");
509 xml_name
= xmlChar_from_wchar( name
);
510 xml_value
= xmlChar_from_wchar( V_BSTR(&var
) );
512 if(!xmlSetNsProp(element
, NULL
, xml_name
, xml_value
))
515 HeapFree(GetProcessHeap(), 0, xml_value
);
516 HeapFree(GetProcessHeap(), 0, xml_name
);
522 static HRESULT WINAPI
domelem_removeAttribute(
523 IXMLDOMElement
*iface
,
530 static HRESULT WINAPI
domelem_getAttributeNode(
531 IXMLDOMElement
*iface
,
532 BSTR p
, IXMLDOMAttribute
** attributeNode
)
538 static HRESULT WINAPI
domelem_setAttributeNode(
539 IXMLDOMElement
*iface
,
540 IXMLDOMAttribute
* domAttribute
,
541 IXMLDOMAttribute
** attributeNode
)
547 static HRESULT WINAPI
domelem_removeAttributeNode(
548 IXMLDOMElement
*iface
,
549 IXMLDOMAttribute
* domAttribute
,
550 IXMLDOMAttribute
** attributeNode
)
556 static HRESULT WINAPI
domelem_getElementsByTagName(
557 IXMLDOMElement
*iface
,
558 BSTR bstrName
, IXMLDOMNodeList
** resultList
)
560 domelem
*This
= impl_from_IXMLDOMElement( iface
);
564 TRACE("(%p)->(%s,%p)\n", This
, debugstr_w(bstrName
), resultList
);
566 szPattern
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(3+lstrlenW(bstrName
)+1));
568 szPattern
[1] = szPattern
[2] = '/';
569 lstrcpyW(szPattern
+3, bstrName
);
570 TRACE("%s\n", debugstr_w(szPattern
));
572 hr
= queryresult_create(get_element(This
), szPattern
, resultList
);
573 HeapFree(GetProcessHeap(), 0, szPattern
);
578 static HRESULT WINAPI
domelem_normalize(
579 IXMLDOMElement
*iface
)
585 static const struct IXMLDOMElementVtbl domelem_vtbl
=
587 domelem_QueryInterface
,
590 domelem_GetTypeInfoCount
,
592 domelem_GetIDsOfNames
,
594 domelem_get_nodeName
,
595 domelem_get_nodeValue
,
596 domelem_put_nodeValue
,
597 domelem_get_nodeType
,
598 domelem_get_parentNode
,
599 domelem_get_childNodes
,
600 domelem_get_firstChild
,
601 domelem_get_lastChild
,
602 domelem_get_previousSibling
,
603 domelem_get_nextSibling
,
604 domelem_get_attributes
,
605 domelem_insertBefore
,
606 domelem_replaceChild
,
609 domelem_hasChildNodes
,
610 domelem_get_ownerDocument
,
612 domelem_get_nodeTypeString
,
615 domelem_get_specified
,
616 domelem_get_definition
,
617 domelem_get_nodeTypedValue
,
618 domelem_put_nodeTypedValue
,
619 domelem_get_dataType
,
620 domelem_put_dataType
,
622 domelem_transformNode
,
624 domelem_selectSingleNode
,
626 domelem_get_namespaceURI
,
628 domelem_get_baseName
,
629 domelem_transformNodeToObject
,
631 domelem_getAttribute
,
632 domelem_setAttribute
,
633 domelem_removeAttribute
,
634 domelem_getAttributeNode
,
635 domelem_setAttributeNode
,
636 domelem_removeAttributeNode
,
637 domelem_getElementsByTagName
,
641 static HRESULT WINAPI
Internal_QueryInterface(
646 domelem
*This
= impl_from_InternalUnknown( iface
);
647 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
649 if ( IsEqualGUID( riid
, &IID_IXMLDOMElement
) ||
650 IsEqualGUID( riid
, &IID_IUnknown
) )
652 *ppvObject
= &This
->lpVtbl
;
654 else if ( IsEqualGUID( riid
, &IID_IDispatch
) ||
655 IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
657 return IUnknown_QueryInterface(This
->node_unk
, riid
, ppvObject
);
661 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
662 return E_NOINTERFACE
;
665 IUnknown_AddRef( (IUnknown
*)*ppvObject
);
670 static ULONG WINAPI
Internal_AddRef(
673 domelem
*This
= impl_from_InternalUnknown( iface
);
674 return InterlockedIncrement( &This
->ref
);
677 static ULONG WINAPI
Internal_Release(
680 domelem
*This
= impl_from_InternalUnknown( iface
);
683 ref
= InterlockedDecrement( &This
->ref
);
686 IUnknown_Release( This
->node_unk
);
687 HeapFree( GetProcessHeap(), 0, This
);
693 static const struct IUnknownVtbl internal_unk_vtbl
=
695 Internal_QueryInterface
,
700 IUnknown
* create_element( xmlNodePtr element
, IUnknown
*pUnkOuter
)
705 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
709 This
->lpVtbl
= &domelem_vtbl
;
711 This
->lpInternalUnkVtbl
= &internal_unk_vtbl
;
714 This
->pUnkOuter
= pUnkOuter
; /* Don't take a ref on outer Unknown */
716 This
->pUnkOuter
= (IUnknown
*)&This
->lpInternalUnkVtbl
;
718 This
->node_unk
= create_basic_node( element
, (IUnknown
*)&This
->lpVtbl
);
721 HeapFree(GetProcessHeap(), 0, This
);
725 hr
= IUnknown_QueryInterface(This
->node_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&This
->node
);
728 IUnknown_Release(This
->node_unk
);
729 HeapFree( GetProcessHeap(), 0, This
);
732 /* The ref on This->node is actually looped back into this object, so release it */
733 IXMLDOMNode_Release(This
->node
);
735 return (IUnknown
*) &This
->lpInternalUnkVtbl
;