d2d1/tests: Fix stroke style object leak (Valgrind).
[wine.git] / dlls / msxml3 / cdata.c
blobc255b1b18b5e16dcbeb638a55fe8e4d1deea694c
1 /*
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
21 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
26 #ifdef HAVE_LIBXML2
27 # include <libxml/parser.h>
28 # include <libxml/xmlerror.h>
29 #endif
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winuser.h"
34 #include "ole2.h"
35 #include "msxml6.h"
37 #include "msxml_private.h"
39 #include "wine/debug.h"
41 #ifdef HAVE_LIBXML2
43 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
45 typedef struct
47 xmlnode node;
48 IXMLDOMCDATASection IXMLDOMCDATASection_iface;
49 LONG ref;
50 } domcdata;
52 static const tid_t domcdata_se_tids[] = {
53 IXMLDOMNode_tid,
54 IXMLDOMCDATASection_tid,
55 NULL_tid
58 static inline domcdata *impl_from_IXMLDOMCDATASection( IXMLDOMCDATASection *iface )
60 return CONTAINING_RECORD(iface, domcdata, IXMLDOMCDATASection_iface);
63 static HRESULT WINAPI domcdata_QueryInterface(
64 IXMLDOMCDATASection *iface,
65 REFIID riid,
66 void** ppvObject )
68 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
69 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
71 if ( IsEqualGUID( riid, &IID_IXMLDOMCDATASection ) ||
72 IsEqualGUID( riid, &IID_IXMLDOMCharacterData) ||
73 IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
74 IsEqualGUID( riid, &IID_IDispatch ) ||
75 IsEqualGUID( riid, &IID_IUnknown ) )
77 *ppvObject = iface;
79 else if(node_query_interface(&This->node, riid, ppvObject))
81 return *ppvObject ? S_OK : E_NOINTERFACE;
83 else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
85 return node_create_supporterrorinfo(domcdata_se_tids, ppvObject);
87 else
89 TRACE("Unsupported interface %s\n", debugstr_guid(riid));
90 *ppvObject = NULL;
91 return E_NOINTERFACE;
94 IXMLDOMCDATASection_AddRef(iface);
95 return S_OK;
98 static ULONG WINAPI domcdata_AddRef(
99 IXMLDOMCDATASection *iface )
101 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
102 ULONG ref = InterlockedIncrement( &This->ref );
103 TRACE("(%p)->(%d)\n", This, ref);
104 return ref;
107 static ULONG WINAPI domcdata_Release(
108 IXMLDOMCDATASection *iface )
110 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
111 ULONG ref = InterlockedDecrement( &This->ref );
113 TRACE("(%p)->(%d)\n", This, ref);
114 if ( ref == 0 )
116 destroy_xmlnode(&This->node);
117 heap_free( This );
120 return ref;
123 static HRESULT WINAPI domcdata_GetTypeInfoCount(
124 IXMLDOMCDATASection *iface,
125 UINT* pctinfo )
127 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
128 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
131 static HRESULT WINAPI domcdata_GetTypeInfo(
132 IXMLDOMCDATASection *iface,
133 UINT iTInfo, LCID lcid,
134 ITypeInfo** ppTInfo )
136 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
137 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
138 iTInfo, lcid, ppTInfo);
141 static HRESULT WINAPI domcdata_GetIDsOfNames(
142 IXMLDOMCDATASection *iface,
143 REFIID riid, LPOLESTR* rgszNames,
144 UINT cNames, LCID lcid, DISPID* rgDispId )
146 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
147 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
148 riid, rgszNames, cNames, lcid, rgDispId);
151 static HRESULT WINAPI domcdata_Invoke(
152 IXMLDOMCDATASection *iface,
153 DISPID dispIdMember, REFIID riid, LCID lcid,
154 WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
155 EXCEPINFO* pExcepInfo, UINT* puArgErr )
157 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
158 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
159 dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
162 static HRESULT WINAPI domcdata_get_nodeName(
163 IXMLDOMCDATASection *iface,
164 BSTR* p )
166 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
168 static const WCHAR cdata_sectionW[] =
169 {'#','c','d','a','t','a','-','s','e','c','t','i','o','n',0};
171 TRACE("(%p)->(%p)\n", This, p);
173 return return_bstr(cdata_sectionW, p);
176 static HRESULT WINAPI domcdata_get_nodeValue(
177 IXMLDOMCDATASection *iface,
178 VARIANT* value)
180 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
182 TRACE("(%p)->(%p)\n", This, value);
184 return node_get_content(&This->node, value);
187 static HRESULT WINAPI domcdata_put_nodeValue(
188 IXMLDOMCDATASection *iface,
189 VARIANT value)
191 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
193 TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
195 return node_put_value(&This->node, &value);
198 static HRESULT WINAPI domcdata_get_nodeType(
199 IXMLDOMCDATASection *iface,
200 DOMNodeType* domNodeType )
202 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
204 TRACE("(%p)->(%p)\n", This, domNodeType);
206 *domNodeType = NODE_CDATA_SECTION;
207 return S_OK;
210 static HRESULT WINAPI domcdata_get_parentNode(
211 IXMLDOMCDATASection *iface,
212 IXMLDOMNode** parent )
214 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
216 TRACE("(%p)->(%p)\n", This, parent);
218 return node_get_parent(&This->node, parent);
221 static HRESULT WINAPI domcdata_get_childNodes(
222 IXMLDOMCDATASection *iface,
223 IXMLDOMNodeList** outList)
225 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
227 TRACE("(%p)->(%p)\n", This, outList);
229 return node_get_child_nodes(&This->node, outList);
232 static HRESULT WINAPI domcdata_get_firstChild(
233 IXMLDOMCDATASection *iface,
234 IXMLDOMNode** domNode)
236 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
238 TRACE("(%p)->(%p)\n", This, domNode);
240 return return_null_node(domNode);
243 static HRESULT WINAPI domcdata_get_lastChild(
244 IXMLDOMCDATASection *iface,
245 IXMLDOMNode** domNode)
247 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
249 TRACE("(%p)->(%p)\n", This, domNode);
251 return return_null_node(domNode);
254 static HRESULT WINAPI domcdata_get_previousSibling(
255 IXMLDOMCDATASection *iface,
256 IXMLDOMNode** domNode)
258 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
260 TRACE("(%p)->(%p)\n", This, domNode);
262 return node_get_previous_sibling(&This->node, domNode);
265 static HRESULT WINAPI domcdata_get_nextSibling(
266 IXMLDOMCDATASection *iface,
267 IXMLDOMNode** domNode)
269 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
271 TRACE("(%p)->(%p)\n", This, domNode);
273 return node_get_next_sibling(&This->node, domNode);
276 static HRESULT WINAPI domcdata_get_attributes(
277 IXMLDOMCDATASection *iface,
278 IXMLDOMNamedNodeMap** attributeMap)
280 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
282 TRACE("(%p)->(%p)\n", This, attributeMap);
284 return return_null_ptr((void**)attributeMap);
287 static HRESULT WINAPI domcdata_insertBefore(
288 IXMLDOMCDATASection *iface,
289 IXMLDOMNode* newNode, VARIANT refChild,
290 IXMLDOMNode** outOldNode)
292 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
293 TRACE("(%p)->(%p %s %p)\n", This, newNode, debugstr_variant(&refChild), outOldNode);
294 if (outOldNode) *outOldNode = NULL;
295 return E_FAIL;
298 static HRESULT WINAPI domcdata_replaceChild(
299 IXMLDOMCDATASection *iface,
300 IXMLDOMNode* newNode,
301 IXMLDOMNode* oldNode,
302 IXMLDOMNode** outOldNode)
304 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
305 TRACE("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
306 if (outOldNode) *outOldNode = NULL;
307 return E_FAIL;
310 static HRESULT WINAPI domcdata_removeChild(
311 IXMLDOMCDATASection *iface,
312 IXMLDOMNode *child, IXMLDOMNode **oldChild)
314 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
315 TRACE("(%p)->(%p %p)\n", This, child, oldChild);
316 if (oldChild) *oldChild = NULL;
317 return E_FAIL;
320 static HRESULT WINAPI domcdata_appendChild(
321 IXMLDOMCDATASection *iface,
322 IXMLDOMNode *child, IXMLDOMNode **outChild)
324 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
325 TRACE("(%p)->(%p %p)\n", This, child, outChild);
326 if (outChild) *outChild = NULL;
327 return E_FAIL;
330 static HRESULT WINAPI domcdata_hasChildNodes(
331 IXMLDOMCDATASection *iface,
332 VARIANT_BOOL *ret)
334 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
335 TRACE("(%p)->(%p)\n", This, ret);
336 return return_var_false(ret);
339 static HRESULT WINAPI domcdata_get_ownerDocument(
340 IXMLDOMCDATASection *iface,
341 IXMLDOMDocument **doc)
343 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
344 TRACE("(%p)->(%p)\n", This, doc);
345 return node_get_owner_doc(&This->node, doc);
348 static HRESULT WINAPI domcdata_cloneNode(
349 IXMLDOMCDATASection *iface,
350 VARIANT_BOOL deep, IXMLDOMNode** outNode)
352 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
353 TRACE("(%p)->(%d %p)\n", This, deep, outNode);
354 return node_clone( &This->node, deep, outNode );
357 static HRESULT WINAPI domcdata_get_nodeTypeString(
358 IXMLDOMCDATASection *iface,
359 BSTR* p)
361 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
362 static const WCHAR cdatasectionW[] = {'c','d','a','t','a','s','e','c','t','i','o','n',0};
364 TRACE("(%p)->(%p)\n", This, p);
366 return return_bstr(cdatasectionW, p);
369 static HRESULT WINAPI domcdata_get_text(
370 IXMLDOMCDATASection *iface,
371 BSTR* p)
373 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
374 TRACE("(%p)->(%p)\n", This, p);
375 return node_get_text(&This->node, p);
378 static HRESULT WINAPI domcdata_put_text(
379 IXMLDOMCDATASection *iface,
380 BSTR p)
382 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
383 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
384 return node_put_text( &This->node, p );
387 static HRESULT WINAPI domcdata_get_specified(
388 IXMLDOMCDATASection *iface,
389 VARIANT_BOOL* isSpecified)
391 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
392 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
393 *isSpecified = VARIANT_TRUE;
394 return S_OK;
397 static HRESULT WINAPI domcdata_get_definition(
398 IXMLDOMCDATASection *iface,
399 IXMLDOMNode** definitionNode)
401 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
402 FIXME("(%p)->(%p)\n", This, definitionNode);
403 return E_NOTIMPL;
406 static HRESULT WINAPI domcdata_get_nodeTypedValue(
407 IXMLDOMCDATASection *iface,
408 VARIANT* v)
410 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
411 TRACE("(%p)->(%p)\n", This, v);
412 return node_get_content(&This->node, v);
415 static HRESULT WINAPI domcdata_put_nodeTypedValue(
416 IXMLDOMCDATASection *iface,
417 VARIANT typedValue)
419 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
420 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
421 return E_NOTIMPL;
424 static HRESULT WINAPI domcdata_get_dataType(
425 IXMLDOMCDATASection *iface,
426 VARIANT* typename)
428 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
429 TRACE("(%p)->(%p)\n", This, typename);
430 return return_null_var( typename );
433 static HRESULT WINAPI domcdata_put_dataType(
434 IXMLDOMCDATASection *iface,
435 BSTR p)
437 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
439 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
441 if(!p)
442 return E_INVALIDARG;
444 return E_FAIL;
447 static HRESULT WINAPI domcdata_get_xml(
448 IXMLDOMCDATASection *iface,
449 BSTR* p)
451 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
453 TRACE("(%p)->(%p)\n", This, p);
455 return node_get_xml(&This->node, FALSE, p);
458 static HRESULT WINAPI domcdata_transformNode(
459 IXMLDOMCDATASection *iface,
460 IXMLDOMNode *node, BSTR *p)
462 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
463 TRACE("(%p)->(%p %p)\n", This, node, p);
464 return node_transform_node(&This->node, node, p);
467 static HRESULT WINAPI domcdata_selectNodes(
468 IXMLDOMCDATASection *iface,
469 BSTR p, IXMLDOMNodeList** outList)
471 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
472 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
473 return node_select_nodes(&This->node, p, outList);
476 static HRESULT WINAPI domcdata_selectSingleNode(
477 IXMLDOMCDATASection *iface,
478 BSTR p, IXMLDOMNode** outNode)
480 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
481 TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
482 return node_select_singlenode(&This->node, p, outNode);
485 static HRESULT WINAPI domcdata_get_parsed(
486 IXMLDOMCDATASection *iface,
487 VARIANT_BOOL* isParsed)
489 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
490 FIXME("(%p)->(%p) stub!\n", This, isParsed);
491 *isParsed = VARIANT_TRUE;
492 return S_OK;
495 static HRESULT WINAPI domcdata_get_namespaceURI(
496 IXMLDOMCDATASection *iface,
497 BSTR* p)
499 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
500 TRACE("(%p)->(%p)\n", This, p);
501 return node_get_namespaceURI(&This->node, p);
504 static HRESULT WINAPI domcdata_get_prefix(
505 IXMLDOMCDATASection *iface,
506 BSTR* prefix)
508 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
509 TRACE("(%p)->(%p)\n", This, prefix);
510 return return_null_bstr( prefix );
513 static HRESULT WINAPI domcdata_get_baseName(
514 IXMLDOMCDATASection *iface,
515 BSTR* name)
517 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
518 FIXME("(%p)->(%p): needs test\n", This, name);
519 return return_null_bstr( name );
522 static HRESULT WINAPI domcdata_transformNodeToObject(
523 IXMLDOMCDATASection *iface,
524 IXMLDOMNode* domNode, VARIANT var1)
526 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
527 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
528 return E_NOTIMPL;
531 static HRESULT WINAPI domcdata_get_data(
532 IXMLDOMCDATASection *iface,
533 BSTR *p)
535 HRESULT hr;
536 VARIANT vRet;
538 if(!p)
539 return E_INVALIDARG;
541 hr = IXMLDOMCDATASection_get_nodeValue( iface, &vRet );
542 if(hr == S_OK)
544 *p = V_BSTR(&vRet);
547 return hr;
550 static HRESULT WINAPI domcdata_put_data(
551 IXMLDOMCDATASection *iface,
552 BSTR data)
554 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
555 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
556 return node_set_content(&This->node, data);
559 static HRESULT WINAPI domcdata_get_length(
560 IXMLDOMCDATASection *iface,
561 LONG *len)
563 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
564 HRESULT hr;
565 BSTR data;
567 TRACE("(%p)->(%p)\n", This, len);
569 if(!len)
570 return E_INVALIDARG;
572 hr = IXMLDOMCDATASection_get_data(iface, &data);
573 if(hr == S_OK)
575 *len = SysStringLen(data);
576 SysFreeString(data);
579 return S_OK;
582 static HRESULT WINAPI domcdata_substringData(
583 IXMLDOMCDATASection *iface,
584 LONG offset, LONG count, BSTR *p)
586 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
587 HRESULT hr;
588 BSTR data;
590 TRACE("(%p)->(%d %d %p)\n", This, offset, count, p);
592 if(!p)
593 return E_INVALIDARG;
595 *p = NULL;
596 if(offset < 0 || count < 0)
597 return E_INVALIDARG;
599 if(count == 0)
600 return S_FALSE;
602 hr = IXMLDOMCDATASection_get_data(iface, &data);
603 if(hr == S_OK)
605 LONG len = SysStringLen(data);
607 if(offset < len)
609 if(offset + count > len)
610 *p = SysAllocString(&data[offset]);
611 else
612 *p = SysAllocStringLen(&data[offset], count);
614 else
615 hr = S_FALSE;
617 SysFreeString(data);
620 return hr;
623 static HRESULT WINAPI domcdata_appendData(
624 IXMLDOMCDATASection *iface,
625 BSTR p)
627 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
628 HRESULT hr;
629 BSTR data;
630 LONG p_len;
632 TRACE("(%p)->(%s)\n", This, debugstr_w(p));
634 /* Nothing to do if NULL or an Empty string passed in. */
635 if((p_len = SysStringLen(p)) == 0) return S_OK;
637 hr = IXMLDOMCDATASection_get_data(iface, &data);
638 if(hr == S_OK)
640 LONG len = SysStringLen(data);
641 BSTR str = SysAllocStringLen(NULL, p_len + len);
643 memcpy(str, data, len*sizeof(WCHAR));
644 memcpy(&str[len], p, p_len*sizeof(WCHAR));
645 str[len+p_len] = 0;
647 hr = IXMLDOMCDATASection_put_data(iface, str);
649 SysFreeString(str);
650 SysFreeString(data);
653 return hr;
656 static HRESULT WINAPI domcdata_insertData(
657 IXMLDOMCDATASection *iface,
658 LONG offset, BSTR p)
660 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
661 HRESULT hr;
662 BSTR data;
663 LONG p_len;
665 TRACE("(%p)->(%d %s)\n", This, offset, debugstr_w(p));
667 /* If have a NULL or empty string, don't do anything. */
668 if((p_len = SysStringLen(p)) == 0)
669 return S_OK;
671 if(offset < 0)
673 return E_INVALIDARG;
676 hr = IXMLDOMCDATASection_get_data(iface, &data);
677 if(hr == S_OK)
679 LONG len = SysStringLen(data);
680 BSTR str;
682 if(len < offset)
684 SysFreeString(data);
685 return E_INVALIDARG;
688 str = SysAllocStringLen(NULL, len + p_len);
689 /* start part, supplied string and end part */
690 memcpy(str, data, offset*sizeof(WCHAR));
691 memcpy(&str[offset], p, p_len*sizeof(WCHAR));
692 memcpy(&str[offset+p_len], &data[offset], (len-offset)*sizeof(WCHAR));
693 str[len+p_len] = 0;
695 hr = IXMLDOMCDATASection_put_data(iface, str);
697 SysFreeString(str);
698 SysFreeString(data);
701 return hr;
704 static HRESULT WINAPI domcdata_deleteData(
705 IXMLDOMCDATASection *iface,
706 LONG offset, LONG count)
708 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
709 HRESULT hr;
710 LONG len = -1;
711 BSTR str;
713 TRACE("(%p)->(%d %d)\n", This, offset, count);
715 hr = IXMLDOMCDATASection_get_length(iface, &len);
716 if(hr != S_OK) return hr;
718 if((offset < 0) || (offset > len) || (count < 0))
719 return E_INVALIDARG;
721 if(len == 0) return S_OK;
723 /* cutting start or end */
724 if((offset == 0) || ((count + offset) >= len))
726 if(offset == 0)
727 IXMLDOMCDATASection_substringData(iface, count, len - count, &str);
728 else
729 IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
730 hr = IXMLDOMCDATASection_put_data(iface, str);
732 else
733 /* cutting from the inside */
735 BSTR str_end;
737 IXMLDOMCDATASection_substringData(iface, 0, offset, &str);
738 IXMLDOMCDATASection_substringData(iface, offset + count, len - count, &str_end);
740 hr = IXMLDOMCDATASection_put_data(iface, str);
741 if(hr == S_OK)
742 hr = IXMLDOMCDATASection_appendData(iface, str_end);
744 SysFreeString(str_end);
747 SysFreeString(str);
749 return hr;
752 static HRESULT WINAPI domcdata_replaceData(
753 IXMLDOMCDATASection *iface,
754 LONG offset, LONG count, BSTR p)
756 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
757 HRESULT hr;
759 TRACE("(%p)->(%d %d %s)\n", This, offset, count, debugstr_w(p));
761 hr = IXMLDOMCDATASection_deleteData(iface, offset, count);
763 if (hr == S_OK)
764 hr = IXMLDOMCDATASection_insertData(iface, offset, p);
766 return hr;
769 static HRESULT WINAPI domcdata_splitText(
770 IXMLDOMCDATASection *iface,
771 LONG offset, IXMLDOMText **txtNode)
773 domcdata *This = impl_from_IXMLDOMCDATASection( iface );
774 IXMLDOMDocument *doc;
775 LONG length = 0;
776 HRESULT hr;
778 TRACE("(%p)->(%d %p)\n", This, offset, txtNode);
780 if (!txtNode || offset < 0) return E_INVALIDARG;
782 *txtNode = NULL;
784 IXMLDOMCDATASection_get_length(iface, &length);
786 if (offset > length) return E_INVALIDARG;
787 if (offset == length) return S_FALSE;
789 hr = IXMLDOMCDATASection_get_ownerDocument(iface, &doc);
790 if (hr == S_OK)
792 BSTR data;
794 hr = IXMLDOMCDATASection_substringData(iface, offset, length - offset, &data);
795 if (hr == S_OK)
797 hr = IXMLDOMDocument_createTextNode(doc, data, txtNode);
798 if (hr == S_OK)
800 IXMLDOMNode *parent;
802 hr = IXMLDOMCDATASection_get_parentNode(iface, &parent);
803 if (hr == S_OK)
805 IXMLDOMCDATASection_deleteData(iface, 0, offset);
806 hr = IXMLDOMNode_appendChild(parent, (IXMLDOMNode*)*txtNode, NULL);
807 IXMLDOMNode_Release(parent);
810 SysFreeString(data);
812 IXMLDOMDocument_Release(doc);
815 return hr;
818 static const struct IXMLDOMCDATASectionVtbl domcdata_vtbl =
820 domcdata_QueryInterface,
821 domcdata_AddRef,
822 domcdata_Release,
823 domcdata_GetTypeInfoCount,
824 domcdata_GetTypeInfo,
825 domcdata_GetIDsOfNames,
826 domcdata_Invoke,
827 domcdata_get_nodeName,
828 domcdata_get_nodeValue,
829 domcdata_put_nodeValue,
830 domcdata_get_nodeType,
831 domcdata_get_parentNode,
832 domcdata_get_childNodes,
833 domcdata_get_firstChild,
834 domcdata_get_lastChild,
835 domcdata_get_previousSibling,
836 domcdata_get_nextSibling,
837 domcdata_get_attributes,
838 domcdata_insertBefore,
839 domcdata_replaceChild,
840 domcdata_removeChild,
841 domcdata_appendChild,
842 domcdata_hasChildNodes,
843 domcdata_get_ownerDocument,
844 domcdata_cloneNode,
845 domcdata_get_nodeTypeString,
846 domcdata_get_text,
847 domcdata_put_text,
848 domcdata_get_specified,
849 domcdata_get_definition,
850 domcdata_get_nodeTypedValue,
851 domcdata_put_nodeTypedValue,
852 domcdata_get_dataType,
853 domcdata_put_dataType,
854 domcdata_get_xml,
855 domcdata_transformNode,
856 domcdata_selectNodes,
857 domcdata_selectSingleNode,
858 domcdata_get_parsed,
859 domcdata_get_namespaceURI,
860 domcdata_get_prefix,
861 domcdata_get_baseName,
862 domcdata_transformNodeToObject,
863 domcdata_get_data,
864 domcdata_put_data,
865 domcdata_get_length,
866 domcdata_substringData,
867 domcdata_appendData,
868 domcdata_insertData,
869 domcdata_deleteData,
870 domcdata_replaceData,
871 domcdata_splitText
874 static const tid_t domcdata_iface_tids[] = {
875 IXMLDOMCDATASection_tid,
879 static dispex_static_data_t domcdata_dispex = {
880 NULL,
881 IXMLDOMCDATASection_tid,
882 NULL,
883 domcdata_iface_tids
886 IUnknown* create_cdata( xmlNodePtr text )
888 domcdata *This;
890 This = heap_alloc( sizeof *This );
891 if ( !This )
892 return NULL;
894 This->IXMLDOMCDATASection_iface.lpVtbl = &domcdata_vtbl;
895 This->ref = 1;
897 init_xmlnode(&This->node, text, (IXMLDOMNode*)&This->IXMLDOMCDATASection_iface, &domcdata_dispex);
899 return (IUnknown*)&This->IXMLDOMCDATASection_iface;
902 #endif