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
;
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_IXMLDOMCharacterData
) ||
63 IsEqualGUID( riid
, &IID_IDispatch
) ||
64 IsEqualGUID( riid
, &IID_IUnknown
) )
68 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
70 return IUnknown_QueryInterface(This
->node_unk
, riid
, ppvObject
);
72 else if ( IsEqualGUID( riid
, &IID_IXMLDOMText
) ||
73 IsEqualGUID( riid
, &IID_IXMLDOMElement
) )
75 TRACE("Unsupported interface\n");
80 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
84 IXMLDOMCDATASection_AddRef( iface
);
89 static ULONG WINAPI
domcdata_AddRef(
90 IXMLDOMCDATASection
*iface
)
92 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
93 return InterlockedIncrement( &This
->ref
);
96 static ULONG WINAPI
domcdata_Release(
97 IXMLDOMCDATASection
*iface
)
99 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
102 ref
= InterlockedDecrement( &This
->ref
);
105 IUnknown_Release( This
->node_unk
);
106 HeapFree( GetProcessHeap(), 0, This
);
112 static HRESULT WINAPI
domcdata_GetTypeInfoCount(
113 IXMLDOMCDATASection
*iface
,
116 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
118 TRACE("(%p)->(%p)\n", This
, pctinfo
);
125 static HRESULT WINAPI
domcdata_GetTypeInfo(
126 IXMLDOMCDATASection
*iface
,
127 UINT iTInfo
, LCID lcid
,
128 ITypeInfo
** ppTInfo
)
130 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
133 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
135 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, ppTInfo
);
140 static HRESULT WINAPI
domcdata_GetIDsOfNames(
141 IXMLDOMCDATASection
*iface
,
142 REFIID riid
, LPOLESTR
* rgszNames
,
143 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
145 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
149 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
152 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
155 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, &typeinfo
);
158 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
159 ITypeInfo_Release(typeinfo
);
165 static HRESULT WINAPI
domcdata_Invoke(
166 IXMLDOMCDATASection
*iface
,
167 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
168 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
169 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
171 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
175 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
176 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
178 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, &typeinfo
);
181 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
182 pVarResult
, pExcepInfo
, puArgErr
);
183 ITypeInfo_Release(typeinfo
);
189 static HRESULT WINAPI
domcdata_get_nodeName(
190 IXMLDOMCDATASection
*iface
,
193 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
194 return IXMLDOMNode_get_nodeName( This
->node
, p
);
197 static HRESULT WINAPI
domcdata_get_nodeValue(
198 IXMLDOMCDATASection
*iface
,
201 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
202 return IXMLDOMNode_get_nodeValue( This
->node
, var1
);
205 static HRESULT WINAPI
domcdata_put_nodeValue(
206 IXMLDOMCDATASection
*iface
,
209 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
210 return IXMLDOMNode_put_nodeValue( This
->node
, var1
);
213 static HRESULT WINAPI
domcdata_get_nodeType(
214 IXMLDOMCDATASection
*iface
,
215 DOMNodeType
* domNodeType
)
217 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
218 return IXMLDOMNode_get_nodeType( This
->node
, domNodeType
);
221 static HRESULT WINAPI
domcdata_get_parentNode(
222 IXMLDOMCDATASection
*iface
,
223 IXMLDOMNode
** parent
)
225 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
226 return IXMLDOMNode_get_parentNode( This
->node
, parent
);
229 static HRESULT WINAPI
domcdata_get_childNodes(
230 IXMLDOMCDATASection
*iface
,
231 IXMLDOMNodeList
** outList
)
233 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
234 return IXMLDOMNode_get_childNodes( This
->node
, outList
);
237 static HRESULT WINAPI
domcdata_get_firstChild(
238 IXMLDOMCDATASection
*iface
,
239 IXMLDOMNode
** domNode
)
241 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
242 return IXMLDOMNode_get_firstChild( This
->node
, domNode
);
245 static HRESULT WINAPI
domcdata_get_lastChild(
246 IXMLDOMCDATASection
*iface
,
247 IXMLDOMNode
** domNode
)
249 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
250 return IXMLDOMNode_get_lastChild( This
->node
, domNode
);
253 static HRESULT WINAPI
domcdata_get_previousSibling(
254 IXMLDOMCDATASection
*iface
,
255 IXMLDOMNode
** domNode
)
257 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
258 return IXMLDOMNode_get_previousSibling( This
->node
, domNode
);
261 static HRESULT WINAPI
domcdata_get_nextSibling(
262 IXMLDOMCDATASection
*iface
,
263 IXMLDOMNode
** domNode
)
265 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
266 return IXMLDOMNode_get_nextSibling( This
->node
, domNode
);
269 static HRESULT WINAPI
domcdata_get_attributes(
270 IXMLDOMCDATASection
*iface
,
271 IXMLDOMNamedNodeMap
** attributeMap
)
273 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
274 return IXMLDOMNode_get_attributes( This
->node
, attributeMap
);
277 static HRESULT WINAPI
domcdata_insertBefore(
278 IXMLDOMCDATASection
*iface
,
279 IXMLDOMNode
* newNode
, VARIANT var1
,
280 IXMLDOMNode
** outOldNode
)
282 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
283 return IXMLDOMNode_insertBefore( This
->node
, newNode
, var1
, outOldNode
);
286 static HRESULT WINAPI
domcdata_replaceChild(
287 IXMLDOMCDATASection
*iface
,
288 IXMLDOMNode
* newNode
,
289 IXMLDOMNode
* oldNode
,
290 IXMLDOMNode
** outOldNode
)
292 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
293 return IXMLDOMNode_replaceChild( This
->node
, newNode
, oldNode
, outOldNode
);
296 static HRESULT WINAPI
domcdata_removeChild(
297 IXMLDOMCDATASection
*iface
,
298 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
300 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
301 return IXMLDOMNode_removeChild( This
->node
, domNode
, oldNode
);
304 static HRESULT WINAPI
domcdata_appendChild(
305 IXMLDOMCDATASection
*iface
,
306 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
308 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
309 return IXMLDOMNode_appendChild( This
->node
, newNode
, outNewNode
);
312 static HRESULT WINAPI
domcdata_hasChildNodes(
313 IXMLDOMCDATASection
*iface
,
316 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
317 return IXMLDOMNode_hasChildNodes( This
->node
, pbool
);
320 static HRESULT WINAPI
domcdata_get_ownerDocument(
321 IXMLDOMCDATASection
*iface
,
322 IXMLDOMDocument
** domDocument
)
324 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
325 return IXMLDOMNode_get_ownerDocument( This
->node
, domDocument
);
328 static HRESULT WINAPI
domcdata_cloneNode(
329 IXMLDOMCDATASection
*iface
,
330 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
332 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
333 return IXMLDOMNode_cloneNode( This
->node
, pbool
, outNode
);
336 static HRESULT WINAPI
domcdata_get_nodeTypeString(
337 IXMLDOMCDATASection
*iface
,
340 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
341 return IXMLDOMNode_get_nodeTypeString( This
->node
, p
);
344 static HRESULT WINAPI
domcdata_get_text(
345 IXMLDOMCDATASection
*iface
,
348 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
349 return IXMLDOMNode_get_text( This
->node
, p
);
352 static HRESULT WINAPI
domcdata_put_text(
353 IXMLDOMCDATASection
*iface
,
356 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
357 return IXMLDOMNode_put_text( This
->node
, p
);
360 static HRESULT WINAPI
domcdata_get_specified(
361 IXMLDOMCDATASection
*iface
,
364 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
365 return IXMLDOMNode_get_specified( This
->node
, pbool
);
368 static HRESULT WINAPI
domcdata_get_definition(
369 IXMLDOMCDATASection
*iface
,
370 IXMLDOMNode
** domNode
)
372 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
373 return IXMLDOMNode_get_definition( This
->node
, domNode
);
376 static HRESULT WINAPI
domcdata_get_nodeTypedValue(
377 IXMLDOMCDATASection
*iface
,
380 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
381 return IXMLDOMNode_get_nodeTypedValue( This
->node
, var1
);
384 static HRESULT WINAPI
domcdata_put_nodeTypedValue(
385 IXMLDOMCDATASection
*iface
,
388 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
389 return IXMLDOMNode_put_nodeTypedValue( This
->node
, var1
);
392 static HRESULT WINAPI
domcdata_get_dataType(
393 IXMLDOMCDATASection
*iface
,
396 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
397 return IXMLDOMNode_get_dataType( This
->node
, var1
);
400 static HRESULT WINAPI
domcdata_put_dataType(
401 IXMLDOMCDATASection
*iface
,
404 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
405 return IXMLDOMNode_put_dataType( This
->node
, p
);
408 static HRESULT WINAPI
domcdata_get_xml(
409 IXMLDOMCDATASection
*iface
,
412 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
413 return IXMLDOMNode_get_xml( This
->node
, p
);
416 static HRESULT WINAPI
domcdata_transformNode(
417 IXMLDOMCDATASection
*iface
,
418 IXMLDOMNode
* domNode
, BSTR
* p
)
420 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
421 return IXMLDOMNode_transformNode( This
->node
, domNode
, p
);
424 static HRESULT WINAPI
domcdata_selectNodes(
425 IXMLDOMCDATASection
*iface
,
426 BSTR p
, IXMLDOMNodeList
** outList
)
428 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
429 return IXMLDOMNode_selectNodes( This
->node
, p
, outList
);
432 static HRESULT WINAPI
domcdata_selectSingleNode(
433 IXMLDOMCDATASection
*iface
,
434 BSTR p
, IXMLDOMNode
** outNode
)
436 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
437 return IXMLDOMNode_selectSingleNode( This
->node
, p
, outNode
);
440 static HRESULT WINAPI
domcdata_get_parsed(
441 IXMLDOMCDATASection
*iface
,
444 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
445 return IXMLDOMNode_get_parsed( This
->node
, pbool
);
448 static HRESULT WINAPI
domcdata_get_namespaceURI(
449 IXMLDOMCDATASection
*iface
,
452 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
453 return IXMLDOMNode_get_namespaceURI( This
->node
, p
);
456 static HRESULT WINAPI
domcdata_get_prefix(
457 IXMLDOMCDATASection
*iface
,
460 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
461 return IXMLDOMNode_get_prefix( This
->node
, p
);
464 static HRESULT WINAPI
domcdata_get_baseName(
465 IXMLDOMCDATASection
*iface
,
468 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
469 return IXMLDOMNode_get_baseName( This
->node
, p
);
472 static HRESULT WINAPI
domcdata_transformNodeToObject(
473 IXMLDOMCDATASection
*iface
,
474 IXMLDOMNode
* domNode
, VARIANT var1
)
476 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
477 return IXMLDOMNode_transformNodeToObject( This
->node
, domNode
, var1
);
480 static HRESULT WINAPI
domcdata_get_data(
481 IXMLDOMCDATASection
*iface
,
484 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
491 hr
= IXMLDOMNode_get_nodeValue( This
->node
, &vRet
);
500 static HRESULT WINAPI
domcdata_put_data(
501 IXMLDOMCDATASection
*iface
,
504 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
508 TRACE("%p %s\n", This
, debugstr_w(data
) );
510 V_VT(&val
) = VT_BSTR
;
513 hr
= IXMLDOMNode_put_nodeValue( This
->node
, val
);
518 static HRESULT WINAPI
domcdata_get_length(
519 IXMLDOMCDATASection
*iface
,
522 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
523 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
527 TRACE("%p\n", iface
);
532 pContent
= xmlNodeGetContent(pDOMNode
->node
);
535 nLength
= xmlStrlen(pContent
);
544 static HRESULT WINAPI
domcdata_substringData(
545 IXMLDOMCDATASection
*iface
,
546 long offset
, long count
, BSTR
*p
)
548 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
549 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
552 HRESULT hr
= S_FALSE
;
554 TRACE("%p\n", iface
);
560 if(offset
< 0 || count
< 0)
566 pContent
= xmlNodeGetContent(pDOMNode
->node
);
569 nLength
= xmlStrlen(pContent
);
571 if( offset
< nLength
)
573 BSTR sContent
= bstr_from_xmlChar(pContent
);
574 if(offset
+ count
> nLength
)
575 *p
= SysAllocString(&sContent
[offset
]);
577 *p
= SysAllocStringLen(&sContent
[offset
], count
);
579 SysFreeString(sContent
);
589 static HRESULT WINAPI
domcdata_appendData(
590 IXMLDOMCDATASection
*iface
,
593 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
594 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
596 HRESULT hr
= S_FALSE
;
598 TRACE("%p\n", iface
);
600 /* Nothing to do if NULL or an Empty string passed in. */
601 if(p
== NULL
|| SysStringLen(p
) == 0)
604 pContent
= xmlChar_from_wchar( p
);
607 if(xmlTextConcat(pDOMNode
->node
, pContent
, SysStringLen(p
) ) == 0)
614 HeapFree(GetProcessHeap(), 0, pContent
);
619 static HRESULT WINAPI
domcdata_insertData(
620 IXMLDOMCDATASection
*iface
,
623 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
624 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( This
->node
);
625 xmlChar
*pXmlContent
;
627 HRESULT hr
= S_FALSE
;
628 long nLength
= 0, nLengthP
= 0;
633 /* If have a NULL or empty string, don't do anything. */
634 if(SysStringLen(p
) == 0)
642 pXmlContent
= xmlNodeGetContent(pDOMNode
->node
);
645 BSTR sContent
= bstr_from_xmlChar( pXmlContent
);
646 nLength
= SysStringLen(sContent
);
647 nLengthP
= SysStringLen(p
);
651 SysFreeString(sContent
);
652 xmlFree(pXmlContent
);
657 sNewString
= SysAllocStringLen(NULL
, nLength
+ nLengthP
+ 1);
661 memcpy(sNewString
, sContent
, offset
* sizeof(WCHAR
));
663 memcpy(&sNewString
[offset
], p
, nLengthP
* sizeof(WCHAR
));
665 if(offset
+nLengthP
< nLength
)
666 memcpy(&sNewString
[offset
+nLengthP
], &sContent
[offset
], (nLength
-offset
) * sizeof(WCHAR
));
668 sNewString
[nLengthP
+ nLength
] = 0;
670 str
= xmlChar_from_wchar(sNewString
);
673 xmlNodeSetContent(pDOMNode
->node
, str
);
676 HeapFree(GetProcessHeap(), 0, str
);
678 SysFreeString(sNewString
);
681 SysFreeString(sContent
);
683 xmlFree(pXmlContent
);
689 static HRESULT WINAPI
domcdata_deleteData(
690 IXMLDOMCDATASection
*iface
,
691 long offset
, long count
)
697 static HRESULT WINAPI
domcdata_replaceData(
698 IXMLDOMCDATASection
*iface
,
699 long offset
, long count
, BSTR p
)
705 static HRESULT WINAPI
domcdata_splitText(
706 IXMLDOMCDATASection
*iface
,
707 long offset
, IXMLDOMText
**txtNode
)
714 static const struct IXMLDOMCDATASectionVtbl domcdata_vtbl
=
716 domcdata_QueryInterface
,
719 domcdata_GetTypeInfoCount
,
720 domcdata_GetTypeInfo
,
721 domcdata_GetIDsOfNames
,
723 domcdata_get_nodeName
,
724 domcdata_get_nodeValue
,
725 domcdata_put_nodeValue
,
726 domcdata_get_nodeType
,
727 domcdata_get_parentNode
,
728 domcdata_get_childNodes
,
729 domcdata_get_firstChild
,
730 domcdata_get_lastChild
,
731 domcdata_get_previousSibling
,
732 domcdata_get_nextSibling
,
733 domcdata_get_attributes
,
734 domcdata_insertBefore
,
735 domcdata_replaceChild
,
736 domcdata_removeChild
,
737 domcdata_appendChild
,
738 domcdata_hasChildNodes
,
739 domcdata_get_ownerDocument
,
741 domcdata_get_nodeTypeString
,
744 domcdata_get_specified
,
745 domcdata_get_definition
,
746 domcdata_get_nodeTypedValue
,
747 domcdata_put_nodeTypedValue
,
748 domcdata_get_dataType
,
749 domcdata_put_dataType
,
751 domcdata_transformNode
,
752 domcdata_selectNodes
,
753 domcdata_selectSingleNode
,
755 domcdata_get_namespaceURI
,
757 domcdata_get_baseName
,
758 domcdata_transformNodeToObject
,
762 domcdata_substringData
,
766 domcdata_replaceData
,
770 IUnknown
* create_cdata( xmlNodePtr text
)
775 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
779 This
->lpVtbl
= &domcdata_vtbl
;
782 This
->node_unk
= create_basic_node( text
, (IUnknown
*)&This
->lpVtbl
);
785 HeapFree(GetProcessHeap(), 0, This
);
789 hr
= IUnknown_QueryInterface(This
->node_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&This
->node
);
792 IUnknown_Release(This
->node_unk
);
793 HeapFree( GetProcessHeap(), 0, This
);
796 /* The ref on This->node is actually looped back into this object, so release it */
797 IXMLDOMNode_Release(This
->node
);
799 return (IUnknown
*) &This
->lpVtbl
;