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_IXMLDOMCharacterData
) ||
63 IsEqualGUID( riid
, &IID_IDispatch
) ||
64 IsEqualGUID( riid
, &IID_IUnknown
) )
68 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) ||
69 IsEqualGUID( riid
, &IID_IXMLDOMElement
) )
71 return IUnknown_QueryInterface(This
->element_unk
, riid
, ppvObject
);
75 FIXME("Unsupported interface %s\n", debugstr_guid(riid
));
79 IXMLDOMCDATASection_AddRef( iface
);
84 static ULONG WINAPI
domcdata_AddRef(
85 IXMLDOMCDATASection
*iface
)
87 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
88 return InterlockedIncrement( &This
->ref
);
91 static ULONG WINAPI
domcdata_Release(
92 IXMLDOMCDATASection
*iface
)
94 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
97 ref
= InterlockedDecrement( &This
->ref
);
100 IUnknown_Release( This
->element_unk
);
101 HeapFree( GetProcessHeap(), 0, This
);
107 static HRESULT WINAPI
domcdata_GetTypeInfoCount(
108 IXMLDOMCDATASection
*iface
,
111 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
113 TRACE("(%p)->(%p)\n", This
, pctinfo
);
120 static HRESULT WINAPI
domcdata_GetTypeInfo(
121 IXMLDOMCDATASection
*iface
,
122 UINT iTInfo
, LCID lcid
,
123 ITypeInfo
** ppTInfo
)
125 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
128 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
130 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, ppTInfo
);
135 static HRESULT WINAPI
domcdata_GetIDsOfNames(
136 IXMLDOMCDATASection
*iface
,
137 REFIID riid
, LPOLESTR
* rgszNames
,
138 UINT cNames
, LCID lcid
, DISPID
* rgDispId
)
140 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
144 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
147 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
150 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, &typeinfo
);
153 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
154 ITypeInfo_Release(typeinfo
);
160 static HRESULT WINAPI
domcdata_Invoke(
161 IXMLDOMCDATASection
*iface
,
162 DISPID dispIdMember
, REFIID riid
, LCID lcid
,
163 WORD wFlags
, DISPPARAMS
* pDispParams
, VARIANT
* pVarResult
,
164 EXCEPINFO
* pExcepInfo
, UINT
* puArgErr
)
166 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
170 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
171 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
173 hr
= get_typeinfo(IXMLDOMCDATASection_tid
, &typeinfo
);
176 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
177 pVarResult
, pExcepInfo
, puArgErr
);
178 ITypeInfo_Release(typeinfo
);
184 static HRESULT WINAPI
domcdata_get_nodeName(
185 IXMLDOMCDATASection
*iface
,
188 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
189 return IXMLDOMNode_get_nodeName( This
->element
, p
);
192 static HRESULT WINAPI
domcdata_get_nodeValue(
193 IXMLDOMCDATASection
*iface
,
196 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
197 return IXMLDOMNode_get_nodeValue( This
->element
, var1
);
200 static HRESULT WINAPI
domcdata_put_nodeValue(
201 IXMLDOMCDATASection
*iface
,
204 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
205 return IXMLDOMNode_put_nodeValue( This
->element
, var1
);
208 static HRESULT WINAPI
domcdata_get_nodeType(
209 IXMLDOMCDATASection
*iface
,
210 DOMNodeType
* domNodeType
)
212 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
213 return IXMLDOMNode_get_nodeType( This
->element
, domNodeType
);
216 static HRESULT WINAPI
domcdata_get_parentNode(
217 IXMLDOMCDATASection
*iface
,
218 IXMLDOMNode
** parent
)
220 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
221 return IXMLDOMNode_get_parentNode( This
->element
, parent
);
224 static HRESULT WINAPI
domcdata_get_childNodes(
225 IXMLDOMCDATASection
*iface
,
226 IXMLDOMNodeList
** outList
)
228 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
229 return IXMLDOMNode_get_childNodes( This
->element
, outList
);
232 static HRESULT WINAPI
domcdata_get_firstChild(
233 IXMLDOMCDATASection
*iface
,
234 IXMLDOMNode
** domNode
)
236 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
237 return IXMLDOMNode_get_firstChild( This
->element
, domNode
);
240 static HRESULT WINAPI
domcdata_get_lastChild(
241 IXMLDOMCDATASection
*iface
,
242 IXMLDOMNode
** domNode
)
244 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
245 return IXMLDOMNode_get_lastChild( This
->element
, domNode
);
248 static HRESULT WINAPI
domcdata_get_previousSibling(
249 IXMLDOMCDATASection
*iface
,
250 IXMLDOMNode
** domNode
)
252 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
253 return IXMLDOMNode_get_previousSibling( This
->element
, domNode
);
256 static HRESULT WINAPI
domcdata_get_nextSibling(
257 IXMLDOMCDATASection
*iface
,
258 IXMLDOMNode
** domNode
)
260 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
261 return IXMLDOMNode_get_nextSibling( This
->element
, domNode
);
264 static HRESULT WINAPI
domcdata_get_attributes(
265 IXMLDOMCDATASection
*iface
,
266 IXMLDOMNamedNodeMap
** attributeMap
)
268 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
269 return IXMLDOMNode_get_attributes( This
->element
, attributeMap
);
272 static HRESULT WINAPI
domcdata_insertBefore(
273 IXMLDOMCDATASection
*iface
,
274 IXMLDOMNode
* newNode
, VARIANT var1
,
275 IXMLDOMNode
** outOldNode
)
277 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
278 return IXMLDOMNode_insertBefore( This
->element
, newNode
, var1
, outOldNode
);
281 static HRESULT WINAPI
domcdata_replaceChild(
282 IXMLDOMCDATASection
*iface
,
283 IXMLDOMNode
* newNode
,
284 IXMLDOMNode
* oldNode
,
285 IXMLDOMNode
** outOldNode
)
287 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
288 return IXMLDOMNode_replaceChild( This
->element
, newNode
, oldNode
, outOldNode
);
291 static HRESULT WINAPI
domcdata_removeChild(
292 IXMLDOMCDATASection
*iface
,
293 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
295 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
296 return IXMLDOMNode_removeChild( This
->element
, domNode
, oldNode
);
299 static HRESULT WINAPI
domcdata_appendChild(
300 IXMLDOMCDATASection
*iface
,
301 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
303 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
304 return IXMLDOMNode_appendChild( This
->element
, newNode
, outNewNode
);
307 static HRESULT WINAPI
domcdata_hasChildNodes(
308 IXMLDOMCDATASection
*iface
,
311 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
312 return IXMLDOMNode_hasChildNodes( This
->element
, pbool
);
315 static HRESULT WINAPI
domcdata_get_ownerDocument(
316 IXMLDOMCDATASection
*iface
,
317 IXMLDOMDocument
** domDocument
)
319 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
320 return IXMLDOMNode_get_ownerDocument( This
->element
, domDocument
);
323 static HRESULT WINAPI
domcdata_cloneNode(
324 IXMLDOMCDATASection
*iface
,
325 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
327 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
328 return IXMLDOMNode_cloneNode( This
->element
, pbool
, outNode
);
331 static HRESULT WINAPI
domcdata_get_nodeTypeString(
332 IXMLDOMCDATASection
*iface
,
335 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
336 return IXMLDOMNode_get_nodeTypeString( This
->element
, p
);
339 static HRESULT WINAPI
domcdata_get_text(
340 IXMLDOMCDATASection
*iface
,
343 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
344 return IXMLDOMNode_get_text( This
->element
, p
);
347 static HRESULT WINAPI
domcdata_put_text(
348 IXMLDOMCDATASection
*iface
,
351 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
352 return IXMLDOMNode_put_text( This
->element
, p
);
355 static HRESULT WINAPI
domcdata_get_specified(
356 IXMLDOMCDATASection
*iface
,
359 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
360 return IXMLDOMNode_get_specified( This
->element
, pbool
);
363 static HRESULT WINAPI
domcdata_get_definition(
364 IXMLDOMCDATASection
*iface
,
365 IXMLDOMNode
** domNode
)
367 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
368 return IXMLDOMNode_get_definition( This
->element
, domNode
);
371 static HRESULT WINAPI
domcdata_get_nodeTypedValue(
372 IXMLDOMCDATASection
*iface
,
375 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
376 return IXMLDOMNode_get_nodeTypedValue( This
->element
, var1
);
379 static HRESULT WINAPI
domcdata_put_nodeTypedValue(
380 IXMLDOMCDATASection
*iface
,
383 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
384 return IXMLDOMNode_put_nodeTypedValue( This
->element
, var1
);
387 static HRESULT WINAPI
domcdata_get_dataType(
388 IXMLDOMCDATASection
*iface
,
391 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
392 return IXMLDOMNode_get_dataType( This
->element
, var1
);
395 static HRESULT WINAPI
domcdata_put_dataType(
396 IXMLDOMCDATASection
*iface
,
399 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
400 return IXMLDOMNode_put_dataType( This
->element
, p
);
403 static HRESULT WINAPI
domcdata_get_xml(
404 IXMLDOMCDATASection
*iface
,
407 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
408 return IXMLDOMNode_get_xml( This
->element
, p
);
411 static HRESULT WINAPI
domcdata_transformNode(
412 IXMLDOMCDATASection
*iface
,
413 IXMLDOMNode
* domNode
, BSTR
* p
)
415 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
416 return IXMLDOMNode_transformNode( This
->element
, domNode
, p
);
419 static HRESULT WINAPI
domcdata_selectNodes(
420 IXMLDOMCDATASection
*iface
,
421 BSTR p
, IXMLDOMNodeList
** outList
)
423 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
424 return IXMLDOMNode_selectNodes( This
->element
, p
, outList
);
427 static HRESULT WINAPI
domcdata_selectSingleNode(
428 IXMLDOMCDATASection
*iface
,
429 BSTR p
, IXMLDOMNode
** outNode
)
431 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
432 return IXMLDOMNode_selectSingleNode( This
->element
, p
, outNode
);
435 static HRESULT WINAPI
domcdata_get_parsed(
436 IXMLDOMCDATASection
*iface
,
439 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
440 return IXMLDOMNode_get_parsed( This
->element
, pbool
);
443 static HRESULT WINAPI
domcdata_get_namespaceURI(
444 IXMLDOMCDATASection
*iface
,
447 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
448 return IXMLDOMNode_get_namespaceURI( This
->element
, p
);
451 static HRESULT WINAPI
domcdata_get_prefix(
452 IXMLDOMCDATASection
*iface
,
455 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
456 return IXMLDOMNode_get_prefix( This
->element
, p
);
459 static HRESULT WINAPI
domcdata_get_baseName(
460 IXMLDOMCDATASection
*iface
,
463 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
464 return IXMLDOMNode_get_baseName( This
->element
, p
);
467 static HRESULT WINAPI
domcdata_transformNodeToObject(
468 IXMLDOMCDATASection
*iface
,
469 IXMLDOMNode
* domNode
, VARIANT var1
)
471 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
472 return IXMLDOMNode_transformNodeToObject( This
->element
, domNode
, var1
);
475 static HRESULT WINAPI
domcdata_get_data(
476 IXMLDOMCDATASection
*iface
,
479 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
486 hr
= IXMLDOMNode_get_nodeValue( This
->element
, &vRet
);
495 static HRESULT WINAPI
domcdata_put_data(
496 IXMLDOMCDATASection
*iface
,
499 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
503 TRACE("%p %s\n", This
, debugstr_w(data
) );
505 V_VT(&val
) = VT_BSTR
;
508 hr
= IXMLDOMNode_put_nodeValue( This
->element
, val
);
513 static HRESULT WINAPI
domcdata_get_length(
514 IXMLDOMCDATASection
*iface
,
517 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
518 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
522 TRACE("%p\n", iface
);
527 pContent
= xmlNodeGetContent(pDOMNode
->node
);
530 nLength
= xmlStrlen(pContent
);
539 static HRESULT WINAPI
domcdata_substringData(
540 IXMLDOMCDATASection
*iface
,
541 long offset
, long count
, BSTR
*p
)
543 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
544 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
547 HRESULT hr
= S_FALSE
;
549 TRACE("%p\n", iface
);
555 if(offset
< 0 || count
< 0)
561 pContent
= xmlNodeGetContent(pDOMNode
->node
);
564 nLength
= xmlStrlen(pContent
);
566 if( offset
< nLength
)
568 BSTR sContent
= bstr_from_xmlChar(pContent
);
569 if(offset
+ count
> nLength
)
570 *p
= SysAllocString(&sContent
[offset
]);
572 *p
= SysAllocStringLen(&sContent
[offset
], count
);
574 SysFreeString(sContent
);
584 static HRESULT WINAPI
domcdata_appendData(
585 IXMLDOMCDATASection
*iface
,
588 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
589 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
591 HRESULT hr
= S_FALSE
;
593 TRACE("%p\n", iface
);
595 /* Nothing to do if NULL or an Empty string passed in. */
596 if(p
== NULL
|| SysStringLen(p
) == 0)
599 pContent
= xmlChar_from_wchar( (WCHAR
*)p
);
602 if(xmlTextConcat(pDOMNode
->node
, pContent
, SysStringLen(p
) ) == 0)
609 HeapFree(GetProcessHeap(), 0, pContent
);
614 static HRESULT WINAPI
domcdata_insertData(
615 IXMLDOMCDATASection
*iface
,
618 domcdata
*This
= impl_from_IXMLDOMCDATASection( iface
);
619 xmlnode
*pDOMNode
= impl_from_IXMLDOMNode( (IXMLDOMNode
*)This
->element
);
620 xmlChar
*pXmlContent
;
622 HRESULT hr
= S_FALSE
;
623 long nLength
= 0, nLengthP
= 0;
628 /* If have a NULL or empty string, don't do anything. */
629 if(SysStringLen(p
) == 0)
637 pXmlContent
= xmlNodeGetContent(pDOMNode
->node
);
640 BSTR sContent
= bstr_from_xmlChar( pXmlContent
);
641 nLength
= SysStringLen(sContent
);
642 nLengthP
= SysStringLen(p
);
646 SysFreeString(sContent
);
647 xmlFree(pXmlContent
);
652 sNewString
= SysAllocStringLen(NULL
, nLength
+ nLengthP
+ 1);
656 memcpy(sNewString
, sContent
, offset
* sizeof(WCHAR
));
658 memcpy(&sNewString
[offset
], p
, nLengthP
* sizeof(WCHAR
));
660 if(offset
+nLengthP
< nLength
)
661 memcpy(&sNewString
[offset
+nLengthP
], &sContent
[offset
], (nLength
-offset
) * sizeof(WCHAR
));
663 sNewString
[nLengthP
+ nLength
] = 0;
665 str
= xmlChar_from_wchar((WCHAR
*)sNewString
);
668 xmlNodeSetContent(pDOMNode
->node
, str
);
671 HeapFree(GetProcessHeap(), 0, str
);
673 SysFreeString(sNewString
);
676 SysFreeString(sContent
);
678 xmlFree(pXmlContent
);
684 static HRESULT WINAPI
domcdata_deleteData(
685 IXMLDOMCDATASection
*iface
,
686 long offset
, long count
)
692 static HRESULT WINAPI
domcdata_replaceData(
693 IXMLDOMCDATASection
*iface
,
694 long offset
, long count
, BSTR p
)
700 static HRESULT WINAPI
domcdata_splitText(
701 IXMLDOMCDATASection
*iface
,
702 long offset
, IXMLDOMText
**txtNode
)
709 static const struct IXMLDOMCDATASectionVtbl domcdata_vtbl
=
711 domcdata_QueryInterface
,
714 domcdata_GetTypeInfoCount
,
715 domcdata_GetTypeInfo
,
716 domcdata_GetIDsOfNames
,
718 domcdata_get_nodeName
,
719 domcdata_get_nodeValue
,
720 domcdata_put_nodeValue
,
721 domcdata_get_nodeType
,
722 domcdata_get_parentNode
,
723 domcdata_get_childNodes
,
724 domcdata_get_firstChild
,
725 domcdata_get_lastChild
,
726 domcdata_get_previousSibling
,
727 domcdata_get_nextSibling
,
728 domcdata_get_attributes
,
729 domcdata_insertBefore
,
730 domcdata_replaceChild
,
731 domcdata_removeChild
,
732 domcdata_appendChild
,
733 domcdata_hasChildNodes
,
734 domcdata_get_ownerDocument
,
736 domcdata_get_nodeTypeString
,
739 domcdata_get_specified
,
740 domcdata_get_definition
,
741 domcdata_get_nodeTypedValue
,
742 domcdata_put_nodeTypedValue
,
743 domcdata_get_dataType
,
744 domcdata_put_dataType
,
746 domcdata_transformNode
,
747 domcdata_selectNodes
,
748 domcdata_selectSingleNode
,
750 domcdata_get_namespaceURI
,
752 domcdata_get_baseName
,
753 domcdata_transformNodeToObject
,
757 domcdata_substringData
,
761 domcdata_replaceData
,
765 IUnknown
* create_cdata( xmlNodePtr text
)
770 This
= HeapAlloc( GetProcessHeap(), 0, sizeof *This
);
774 This
->lpVtbl
= &domcdata_vtbl
;
777 This
->element_unk
= create_element( text
, (IUnknown
*)&This
->lpVtbl
);
778 if(!This
->element_unk
)
780 HeapFree(GetProcessHeap(), 0, This
);
784 hr
= IUnknown_QueryInterface(This
->element_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&This
->element
);
787 IUnknown_Release(This
->element_unk
);
788 HeapFree( GetProcessHeap(), 0, This
);
791 /* The ref on This->element is actually looped back into this object, so release it */
792 IXMLDOMNode_Release(This
->element
);
794 return (IUnknown
*) &This
->lpVtbl
;