2 * DOM CDATA node implementation
4 * Copyright 2007 Alistair Leslie-Hughes
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
32 #include "msxml_private.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
40 typedef struct _domcdata
42 const struct IXMLDOMCDATASectionVtbl
*lpVtbl
;
44 IUnknown
*element_unk
;
45 IXMLDOMCDATASection
*element
;
48 static inline domcdata
*impl_from_IXMLDOMCDATASection( IXMLDOMCDATASection
*iface
)
50 return (domcdata
*)((char*)iface
- FIELD_OFFSET(domcdata
, lpVtbl
));
53 static HRESULT WINAPI
domcdata_QueryInterface(
54 IXMLDOMCDATASection
*iface
,
58 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
59 TRACE("%p %s %p\n", This
, debugstr_guid(riid
), ppvObject
);
61 if ( IsEqualGUID( riid
, &IID_IXMLDOMCDATASection
) ||
62 IsEqualGUID( riid
, &IID_IDispatch
) ||
63 IsEqualGUID( riid
, &IID_IUnknown
) )
67 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) ||
68 IsEqualGUID( riid
, &IID_IXMLDOMElement
) )
70 return IUnknown_QueryInterface(This
->element_unk
, riid
, ppvObject
);
74 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
78 IXMLDOMCDATASection_AddRef( iface
);
83 static ULONG WINAPI
domcdata_AddRef(
84 IXMLDOMCDATASection
*iface
)
86 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
87 return InterlockedIncrement( &This
->ref
);
90 static ULONG WINAPI
domcdata_Release(
91 IXMLDOMCDATASection
*iface
)
93 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
96 ref
= InterlockedDecrement( &This
->ref
);
99 IUnknown_Release( This
->element_unk
);
100 HeapFree( GetProcessHeap(), 0, This
);
106 static HRESULT WINAPI
domcdata_GetTypeInfoCount(
107 IXMLDOMCDATASection
*iface
,
110 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
112 TRACE("(%p)->(%p)\n", This
, pctinfo
);
119 static HRESULT WINAPI
domcdata_GetTypeInfo(
120 IXMLDOMCDATASection
*iface
,
121 UINT iTInfo
, LCID lcid
,
122 ITypeInfo
** ppTInfo
)
124 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
127 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
129 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, ppTInfo
);
134 static HRESULT WINAPI
domcdata_GetIDsOfNames(
135 IXMLDOMCDATASection
*iface
,
136 REFIID riid
, LPOLESTR
* rgszNames
,
137 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
139 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
143 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
146 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
149 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, &typeinfo
);
152 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
153 ITypeInfo_Release(typeinfo
);
159 static HRESULT WINAPI
domcdata_Invoke(
160 IXMLDOMCDATASection
*iface
,
161 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
162 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
163 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
165 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
169 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
170 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
172 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, &typeinfo
);
175 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
176 pVarResult
, pExcepInfo
, puArgErr
);
177 ITypeInfo_Release(typeinfo
);
183 static HRESULT WINAPI
domcdata_get_nodeName(
184 IXMLDOMCDATASection
*iface
,
187 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
188 return IXMLDOMNode_get_nodeName( This
->element
, p
);
191 static HRESULT WINAPI
domcdata_get_nodeValue(
192 IXMLDOMCDATASection
*iface
,
195 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
196 return IXMLDOMNode_get_nodeValue( This
->element
, var1
);
199 static HRESULT WINAPI
domcdata_put_nodeValue(
200 IXMLDOMCDATASection
*iface
,
203 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
204 return IXMLDOMNode_put_nodeValue( This
->element
, var1
);
207 static HRESULT WINAPI
domcdata_get_nodeType(
208 IXMLDOMCDATASection
*iface
,
209 DOMNodeType
* domNodeType
)
211 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
212 return IXMLDOMNode_get_nodeType( This
->element
, domNodeType
);
215 static HRESULT WINAPI
domcdata_get_parentNode(
216 IXMLDOMCDATASection
*iface
,
217 IXMLDOMNode
** parent
)
219 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
220 return IXMLDOMNode_get_parentNode( This
->element
, parent
);
223 static HRESULT WINAPI
domcdata_get_childNodes(
224 IXMLDOMCDATASection
*iface
,
225 IXMLDOMNodeList
** outList
)
227 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
228 return IXMLDOMNode_get_childNodes( This
->element
, outList
);
231 static HRESULT WINAPI
domcdata_get_firstChild(
232 IXMLDOMCDATASection
*iface
,
233 IXMLDOMNode
** domNode
)
235 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
236 return IXMLDOMNode_get_firstChild( This
->element
, domNode
);
239 static HRESULT WINAPI
domcdata_get_lastChild(
240 IXMLDOMCDATASection
*iface
,
241 IXMLDOMNode
** domNode
)
243 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
244 return IXMLDOMNode_get_lastChild( This
->element
, domNode
);
247 static HRESULT WINAPI
domcdata_get_previousSibling(
248 IXMLDOMCDATASection
*iface
,
249 IXMLDOMNode
** domNode
)
251 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
252 return IXMLDOMNode_get_previousSibling( This
->element
, domNode
);
255 static HRESULT WINAPI
domcdata_get_nextSibling(
256 IXMLDOMCDATASection
*iface
,
257 IXMLDOMNode
** domNode
)
259 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
260 return IXMLDOMNode_get_nextSibling( This
->element
, domNode
);
263 static HRESULT WINAPI
domcdata_get_attributes(
264 IXMLDOMCDATASection
*iface
,
265 IXMLDOMNamedNodeMap
** attributeMap
)
267 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
268 return IXMLDOMNode_get_attributes( This
->element
, attributeMap
);
271 static HRESULT WINAPI
domcdata_insertBefore(
272 IXMLDOMCDATASection
*iface
,
273 IXMLDOMNode
* newNode
, VARIANT var1
,
274 IXMLDOMNode
** outOldNode
)
276 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
277 return IXMLDOMNode_insertBefore( This
->element
, newNode
, var1
, outOldNode
);
280 static HRESULT WINAPI
domcdata_replaceChild(
281 IXMLDOMCDATASection
*iface
,
282 IXMLDOMNode
* newNode
,
283 IXMLDOMNode
* oldNode
,
284 IXMLDOMNode
** outOldNode
)
286 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
287 return IXMLDOMNode_replaceChild( This
->element
, newNode
, oldNode
, outOldNode
);
290 static HRESULT WINAPI
domcdata_removeChild(
291 IXMLDOMCDATASection
*iface
,
292 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
294 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
295 return IXMLDOMNode_removeChild( This
->element
, domNode
, oldNode
);
298 static HRESULT WINAPI
domcdata_appendChild(
299 IXMLDOMCDATASection
*iface
,
300 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
302 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
303 return IXMLDOMNode_appendChild( This
->element
, newNode
, outNewNode
);
306 static HRESULT WINAPI
domcdata_hasChildNodes(
307 IXMLDOMCDATASection
*iface
,
310 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
311 return IXMLDOMNode_hasChildNodes( This
->element
, pbool
);
314 static HRESULT WINAPI
domcdata_get_ownerDocument(
315 IXMLDOMCDATASection
*iface
,
316 IXMLDOMDocument
** domDocument
)
318 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
319 return IXMLDOMNode_get_ownerDocument( This
->element
, domDocument
);
322 static HRESULT WINAPI
domcdata_cloneNode(
323 IXMLDOMCDATASection
*iface
,
324 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
326 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
327 return IXMLDOMNode_cloneNode( This
->element
, pbool
, outNode
);
330 static HRESULT WINAPI
domcdata_get_nodeTypeString(
331 IXMLDOMCDATASection
*iface
,
334 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
335 return IXMLDOMNode_get_nodeTypeString( This
->element
, p
);
338 static HRESULT WINAPI
domcdata_get_text(
339 IXMLDOMCDATASection
*iface
,
342 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
343 return IXMLDOMNode_get_text( This
->element
, p
);
346 static HRESULT WINAPI
domcdata_put_text(
347 IXMLDOMCDATASection
*iface
,
350 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
351 return IXMLDOMNode_put_text( This
->element
, p
);
354 static HRESULT WINAPI
domcdata_get_specified(
355 IXMLDOMCDATASection
*iface
,
358 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
359 return IXMLDOMNode_get_specified( This
->element
, pbool
);
362 static HRESULT WINAPI
domcdata_get_definition(
363 IXMLDOMCDATASection
*iface
,
364 IXMLDOMNode
** domNode
)
366 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
367 return IXMLDOMNode_get_definition( This
->element
, domNode
);
370 static HRESULT WINAPI
domcdata_get_nodeTypedValue(
371 IXMLDOMCDATASection
*iface
,
374 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
375 return IXMLDOMNode_get_nodeTypedValue( This
->element
, var1
);
378 static HRESULT WINAPI
domcdata_put_nodeTypedValue(
379 IXMLDOMCDATASection
*iface
,
382 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
383 return IXMLDOMNode_put_nodeTypedValue( This
->element
, var1
);
386 static HRESULT WINAPI
domcdata_get_dataType(
387 IXMLDOMCDATASection
*iface
,
390 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
391 return IXMLDOMNode_get_dataType( This
->element
, var1
);
394 static HRESULT WINAPI
domcdata_put_dataType(
395 IXMLDOMCDATASection
*iface
,
398 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
399 return IXMLDOMNode_put_dataType( This
->element
, p
);
402 static HRESULT WINAPI
domcdata_get_xml(
403 IXMLDOMCDATASection
*iface
,
406 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
407 return IXMLDOMNode_get_xml( This
->element
, p
);
410 static HRESULT WINAPI
domcdata_transformNode(
411 IXMLDOMCDATASection
*iface
,
412 IXMLDOMNode
* domNode
, BSTR
* p
)
414 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
415 return IXMLDOMNode_transformNode( This
->element
, domNode
, p
);
418 static HRESULT WINAPI
domcdata_selectNodes(
419 IXMLDOMCDATASection
*iface
,
420 BSTR p
, IXMLDOMNodeList
** outList
)
422 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
423 return IXMLDOMNode_selectNodes( This
->element
, p
, outList
);
426 static HRESULT WINAPI
domcdata_selectSingleNode(
427 IXMLDOMCDATASection
*iface
,
428 BSTR p
, IXMLDOMNode
** outNode
)
430 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
431 return IXMLDOMNode_selectSingleNode( This
->element
, p
, outNode
);
434 static HRESULT WINAPI
domcdata_get_parsed(
435 IXMLDOMCDATASection
*iface
,
438 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
439 return IXMLDOMNode_get_parsed( This
->element
, pbool
);
442 static HRESULT WINAPI
domcdata_get_namespaceURI(
443 IXMLDOMCDATASection
*iface
,
446 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
447 return IXMLDOMNode_get_namespaceURI( This
->element
, p
);
450 static HRESULT WINAPI
domcdata_get_prefix(
451 IXMLDOMCDATASection
*iface
,
454 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
455 return IXMLDOMNode_get_prefix( This
->element
, p
);
458 static HRESULT WINAPI
domcdata_get_baseName(
459 IXMLDOMCDATASection
*iface
,
462 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
463 return IXMLDOMNode_get_baseName( This
->element
, p
);
466 static HRESULT WINAPI
domcdata_transformNodeToObject(
467 IXMLDOMCDATASection
*iface
,
468 IXMLDOMNode
* domNode
, VARIANT var1
)
470 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
471 return IXMLDOMNode_transformNodeToObject( This
->element
, domNode
, var1
);
474 static HRESULT WINAPI
domcdata_get_data(
475 IXMLDOMCDATASection
*iface
,
478 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
485 hr
= IXMLDOMNode_get_nodeValue( This
->element
, &vRet
);
494 static HRESULT WINAPI
domcdata_put_data(
495 IXMLDOMCDATASection
*iface
,
498 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
502 TRACE("%p %s\n", This
, debugstr_w(data
) );
504 V_VT(&val
) = VT_BSTR
;
507 hr
= IXMLDOMNode_put_nodeValue( This
->element
, val
);
512 static HRESULT WINAPI
domcdata_get_length(
513 IXMLDOMCDATASection
*iface
,
516 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
517 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
521 TRACE("%p\n", iface
);
526 pContent
= xmlNodeGetContent(pDOMNode
->node
);
529 nLength
= xmlStrlen(pContent
);
538 static HRESULT WINAPI
domcdata_substringData(
539 IXMLDOMCDATASection
*iface
,
540 long offset
, long count
, BSTR
*p
)
542 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
543 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
546 HRESULT hr
= S_FALSE
;
548 TRACE("%p\n", iface
);
554 if(offset
< 0 || count
< 0)
560 pContent
= xmlNodeGetContent(pDOMNode
->node
);
563 nLength
= xmlStrlen(pContent
);
565 if( offset
< nLength
)
567 BSTR sContent
= bstr_from_xmlChar(pContent
);
568 if(offset
+ count
> nLength
)
569 *p
= SysAllocString(&sContent
[offset
]);
571 *p
= SysAllocStringLen(&sContent
[offset
], count
);
573 SysFreeString(sContent
);
583 static HRESULT WINAPI
domcdata_appendData(
584 IXMLDOMCDATASection
*iface
,
587 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
588 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
590 HRESULT hr
= S_FALSE
;
592 TRACE("%p\n", iface
);
594 /* Nothing to do if NULL or an Empty string passed in. */
595 if(p
== NULL
|| SysStringLen(p
) == 0)
598 pContent
= xmlChar_from_wchar( (WCHAR
*)p
);
601 if(xmlTextConcat(pDOMNode
->node
, pContent
, SysStringLen(p
) ) == 0)
612 static HRESULT WINAPI
domcdata_insertData(
613 IXMLDOMCDATASection
*iface
,
616 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
617 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
618 xmlChar
*pXmlContent
;
620 HRESULT hr
= S_FALSE
;
621 long nLength
= 0, nLengthP
= 0;
626 /* If have a NULL or empty string, don't do anything. */
627 if(SysStringLen(p
) == 0)
635 pXmlContent
= xmlNodeGetContent(pDOMNode
->node
);
638 BSTR sContent
= bstr_from_xmlChar( pXmlContent
);
639 nLength
= SysStringLen(sContent
);
640 nLengthP
= SysStringLen(p
);
644 SysFreeString(sContent
);
645 xmlFree(pXmlContent
);
650 sNewString
= SysAllocStringLen(NULL
, nLength
+ nLengthP
+ 1);
654 memcpy(sNewString
, sContent
, offset
* sizeof(WCHAR
));
656 memcpy(&sNewString
[offset
], p
, nLengthP
* sizeof(WCHAR
));
658 if(offset
+nLengthP
< nLength
)
659 memcpy(&sNewString
[offset
+nLengthP
], &sContent
[offset
], (nLength
-offset
) * sizeof(WCHAR
));
661 sNewString
[nLengthP
+ nLength
] = 0;
663 str
= xmlChar_from_wchar((WCHAR
*)sNewString
);
666 xmlNodeSetContent(pDOMNode
->node
, str
);
670 SysFreeString(sNewString
);
673 SysFreeString(sContent
);
675 xmlFree(pXmlContent
);
681 static HRESULT WINAPI
domcdata_deleteData(
682 IXMLDOMCDATASection
*iface
,
683 long offset
, long count
)
689 static HRESULT WINAPI
domcdata_replaceData(
690 IXMLDOMCDATASection
*iface
,
691 long offset
, long count
, BSTR p
)
697 static HRESULT WINAPI
domcdata_splitText(
698 IXMLDOMCDATASection
*iface
,
699 long offset
, IXMLDOMText
**txtNode
)
706 static const struct IXMLDOMCDATASectionVtbl domcdata_vtbl
=
708 domcdata_QueryInterface
,
711 domcdata_GetTypeInfoCount
,
712 domcdata_GetTypeInfo
,
713 domcdata_GetIDsOfNames
,
715 domcdata_get_nodeName
,
716 domcdata_get_nodeValue
,
717 domcdata_put_nodeValue
,
718 domcdata_get_nodeType
,
719 domcdata_get_parentNode
,
720 domcdata_get_childNodes
,
721 domcdata_get_firstChild
,
722 domcdata_get_lastChild
,
723 domcdata_get_previousSibling
,
724 domcdata_get_nextSibling
,
725 domcdata_get_attributes
,
726 domcdata_insertBefore
,
727 domcdata_replaceChild
,
728 domcdata_removeChild
,
729 domcdata_appendChild
,
730 domcdata_hasChildNodes
,
731 domcdata_get_ownerDocument
,
733 domcdata_get_nodeTypeString
,
736 domcdata_get_specified
,
737 domcdata_get_definition
,
738 domcdata_get_nodeTypedValue
,
739 domcdata_put_nodeTypedValue
,
740 domcdata_get_dataType
,
741 domcdata_put_dataType
,
743 domcdata_transformNode
,
744 domcdata_selectNodes
,
745 domcdata_selectSingleNode
,
747 domcdata_get_namespaceURI
,
749 domcdata_get_baseName
,
750 domcdata_transformNodeToObject
,
754 domcdata_substringData
,
758 domcdata_replaceData
,
762 IUnknown
* create_cdata( xmlNodePtr text
)
767 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
771 This
->lpVtbl
= &domcdata_vtbl
;
774 This
->element_unk
= create_element( text
, (IUnknown
*)&This
->lpVtbl
);
775 if(!This
->element_unk
)
777 HeapFree(GetProcessHeap(), 0, This
);
781 hr
= IUnknown_QueryInterface(This
->element_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&This
->element
);
784 IUnknown_Release(This
->element_unk
);
785 HeapFree( GetProcessHeap(), 0, This
);
788 /* The ref on This->element is actually looped back into this object, so release it */
789 IXMLDOMNode_Release(This
->element
);
791 return (IUnknown
*) &This
->lpVtbl
;