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
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 # include <libxml/HTMLtree.h>
31 # ifdef SONAME_LIBXSLT
32 # ifdef HAVE_LIBXSLT_PATTERN_H
33 # include <libxslt/pattern.h>
35 # ifdef HAVE_LIBXSLT_TRANSFORM_H
36 # include <libxslt/transform.h>
38 # include <libxslt/xsltutils.h>
39 # include <libxslt/xsltInternals.h>
50 #include "msxml_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
59 extern void* libxslt_handle
;
60 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
61 MAKE_FUNCPTR(xsltApplyStylesheet
);
62 MAKE_FUNCPTR(xsltCleanupGlobals
);
63 MAKE_FUNCPTR(xsltFreeStylesheet
);
64 MAKE_FUNCPTR(xsltParseStylesheetDoc
);
68 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
70 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
76 This
= get_node_obj( iface
);
77 if ( !This
|| !This
->node
)
79 if ( type
&& This
->node
->type
!= type
)
84 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
86 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
87 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
92 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
95 /* common ISupportErrorInfo implementation */
97 ISupportErrorInfo ISupportErrorInfo_iface
;
103 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
105 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
108 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
110 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
111 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
115 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
117 ISupportErrorInfo_AddRef(iface
);
121 return E_NOINTERFACE
;
124 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
126 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
127 ULONG ref
= InterlockedIncrement(&This
->ref
);
128 TRACE("(%p)->(%d)\n", This
, ref
);
132 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
134 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
135 LONG ref
= InterlockedDecrement(&This
->ref
);
137 TRACE("(%p)->(%d)\n", This
, ref
);
145 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
147 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
148 enum tid_t
const *tid
;
150 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
155 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
163 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
164 SupportErrorInfo_QueryInterface
,
165 SupportErrorInfo_AddRef
,
166 SupportErrorInfo_Release
,
167 SupportErrorInfo_InterfaceSupportsErrorInfo
170 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
172 SupportErrorInfo
*This
;
174 This
= heap_alloc(sizeof(*This
));
175 if (!This
) return E_OUTOFMEMORY
;
177 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
181 *obj
= &This
->ISupportErrorInfo_iface
;
186 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
191 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
192 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
193 return SUCCEEDED(hres
) ? obj
: NULL
;
196 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
204 hr
= node_get_base_name(This
, &base
);
205 if (hr
!= S_OK
) return hr
;
207 hr
= node_get_prefix(This
, &prefix
);
210 static const WCHAR colW
= ':';
214 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
215 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
216 ptr
+= SysStringLen(prefix
);
217 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
218 memcpy(ptr
, base
, SysStringByteLen(base
));
221 SysFreeString(prefix
);
229 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
236 content
= xmlNodeGetContent(This
->node
);
237 V_VT(value
) = VT_BSTR
;
238 V_BSTR(value
) = bstr_from_xmlChar( content
);
241 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
245 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
249 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
250 str
= xmlchar_from_wchar(value
);
252 return E_OUTOFMEMORY
;
254 xmlNodeSetContent(This
->node
, str
);
259 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
261 xmlChar
*str
, *escaped
;
263 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
264 str
= xmlchar_from_wchar(value
);
266 return E_OUTOFMEMORY
;
268 escaped
= xmlEncodeSpecialChars(NULL
, str
);
272 return E_OUTOFMEMORY
;
275 xmlNodeSetContent(This
->node
, escaped
);
283 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
285 VARIANT string_value
;
288 VariantInit(&string_value
);
289 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
291 WARN("Couldn't convert to VT_BSTR\n");
295 hr
= node_set_content(This
, V_BSTR(&string_value
));
296 VariantClear(&string_value
);
301 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
303 VARIANT string_value
;
306 VariantInit(&string_value
);
307 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
309 WARN("Couldn't convert to VT_BSTR\n");
313 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
314 VariantClear(&string_value
);
319 static HRESULT
get_node(
325 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
330 /* if we don't have a doc, use our parent. */
331 if(node
&& !node
->doc
&& node
->parent
)
332 node
->doc
= node
->parent
->doc
;
334 *out
= create_node( node
);
340 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
342 return get_node( This
, "parent", This
->node
->parent
, parent
);
345 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
350 *ret
= create_children_nodelist(This
->node
);
352 return E_OUTOFMEMORY
;
357 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
359 return get_node(This
, "firstChild", This
->node
->children
, ret
);
362 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
364 return get_node(This
, "lastChild", This
->node
->last
, ret
);
367 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
369 return get_node(This
, "previous", This
->node
->prev
, ret
);
372 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
374 return get_node(This
, "next", This
->node
->next
, ret
);
377 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
380 IXMLDOMNode
*before
= NULL
;
388 node_obj
= get_node_obj(new_child
);
389 if(!node_obj
) return E_FAIL
;
391 switch(V_VT(ref_child
))
399 if (V_UNKNOWN(ref_child
))
401 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
402 if(FAILED(hr
)) return hr
;
407 FIXME("refChild var type %x\n", V_VT(ref_child
));
411 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
413 if(!node_obj
->node
->parent
)
414 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
415 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
419 xmlnode
*before_node_obj
= get_node_obj(before
);
420 IXMLDOMNode_Release(before
);
421 if(!before_node_obj
) return E_FAIL
;
423 /* unlink from current parent first */
426 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
427 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
429 doc
= node_obj
->node
->doc
;
430 xmldoc_add_ref(before_node_obj
->node
->doc
);
431 xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
433 node_obj
->parent
= This
->parent
;
437 /* unlink from current parent first */
440 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
441 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
443 doc
= node_obj
->node
->doc
;
444 xmldoc_add_ref(This
->node
->doc
);
445 /* xmlAddChild doesn't unlink node from previous parent */
446 xmlUnlinkNode(node_obj
->node
);
447 xmlAddChild(This
->node
, node_obj
->node
);
449 node_obj
->parent
= This
->iface
;
454 IXMLDOMNode_AddRef(new_child
);
462 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
465 xmlnode
*old_child
, *new_child
;
466 xmlDocPtr leaving_doc
;
467 xmlNode
*my_ancestor
;
469 /* Do not believe any documentation telling that newChild == NULL
470 means removal. It does certainly *not* apply to msxml3! */
471 if(!newChild
|| !oldChild
)
477 old_child
= get_node_obj(oldChild
);
478 if(!old_child
) return E_FAIL
;
480 if(old_child
->node
->parent
!= This
->node
)
482 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
486 new_child
= get_node_obj(newChild
);
487 if(!new_child
) return E_FAIL
;
489 my_ancestor
= This
->node
;
492 if(my_ancestor
== new_child
->node
)
494 WARN("tried to create loop\n");
497 my_ancestor
= my_ancestor
->parent
;
500 if(!new_child
->node
->parent
)
501 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
502 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
504 leaving_doc
= new_child
->node
->doc
;
505 xmldoc_add_ref(old_child
->node
->doc
);
506 xmlReplaceNode(old_child
->node
, new_child
->node
);
507 xmldoc_release(leaving_doc
);
508 new_child
->parent
= old_child
->parent
;
509 old_child
->parent
= NULL
;
511 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
515 IXMLDOMNode_AddRef(oldChild
);
522 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
526 if(!child
) return E_INVALIDARG
;
531 child_node
= get_node_obj(child
);
532 if(!child_node
) return E_FAIL
;
534 if(child_node
->node
->parent
!= This
->node
)
536 WARN("childNode %p is not a child of %p\n", child
, This
);
540 xmlUnlinkNode(child_node
->node
);
541 child_node
->parent
= NULL
;
542 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
546 IXMLDOMNode_AddRef(child
);
553 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
559 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
560 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
561 if (outChild
) *outChild
= NULL
;
566 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
569 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
571 if (!ret
) return E_INVALIDARG
;
573 if (!This
->node
->children
)
575 *ret
= VARIANT_FALSE
;
583 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
585 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
588 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
593 if(!cloneNode
) return E_INVALIDARG
;
595 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
598 clone
->doc
= This
->node
->doc
;
599 xmldoc_add_orphan(clone
->doc
, clone
);
601 node
= create_node(clone
);
604 ERR("Copy failed\n");
605 xmldoc_remove_orphan(clone
->doc
, clone
);
614 ERR("Copy failed\n");
621 static inline xmlChar
* trim_whitespace(xmlChar
* str
)
629 while (*ret
&& isspace(*ret
))
631 len
= xmlStrlen(ret
);
633 while (isspace(ret
[len
-1])) --len
;
635 ret
= xmlStrndup(ret
, len
);
640 static xmlChar
* do_get_text(xmlNodePtr node
)
644 BOOL preserving
= is_preserving_whitespace(node
);
648 str
= xmlNodeGetContent(node
);
652 xmlElementType prev_type
= XML_TEXT_NODE
;
654 str
= xmlStrdup(BAD_CAST
"");
655 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
659 case XML_ELEMENT_NODE
:
660 tmp
= do_get_text(child
);
663 case XML_CDATA_SECTION_NODE
:
664 case XML_ENTITY_REF_NODE
:
665 case XML_ENTITY_NODE
:
666 tmp
= xmlNodeGetContent(child
);
677 if (prev_type
== XML_ELEMENT_NODE
&& child
->type
== XML_ELEMENT_NODE
)
678 str
= xmlStrcat(str
, BAD_CAST
" ");
679 str
= xmlStrcat(str
, tmp
);
680 prev_type
= child
->type
;
689 case XML_ELEMENT_NODE
:
691 case XML_ENTITY_REF_NODE
:
692 case XML_ENTITY_NODE
:
693 case XML_DOCUMENT_NODE
:
694 case XML_DOCUMENT_FRAG_NODE
:
696 str
= trim_whitespace(str
);
705 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
710 if (!text
) return E_INVALIDARG
;
712 content
= do_get_text(This
->node
);
715 str
= bstr_from_xmlChar(content
);
719 /* Always return a string. */
720 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
722 TRACE("%p %s\n", This
, debugstr_w(str
) );
728 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
732 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
734 str
= xmlchar_from_wchar(text
);
736 /* Escape the string. */
737 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
740 xmlNodeSetContent(This
->node
, str2
);
746 BSTR
EnsureCorrectEOL(BSTR sInput
)
753 nLen
= SysStringLen(sInput
);
754 /* Count line endings */
755 for(i
=0; i
< nLen
; i
++)
757 if(sInput
[i
] == '\n')
761 TRACE("len=%d, num=%d\n", nLen
, nNum
);
763 /* Add linefeed as needed */
767 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
768 for(i
=0; i
< nLen
; i
++)
770 if(sInput
[i
] == '\n')
772 sNew
[i
+nPlace
] = '\r';
775 sNew
[i
+nPlace
] = sInput
[i
];
778 SysFreeString(sInput
);
785 TRACE("len %d\n", SysStringLen(sNew
));
791 * We are trying to replicate the same behaviour as msxml by converting
792 * line endings to \r\n and using indents as \t. The problem is that msxml
793 * only formats nodes that have a line ending. Using libxml we cannot
794 * reproduce behaviour exactly.
797 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
799 xmlBufferPtr xml_buf
;
808 xml_buf
= xmlBufferCreate();
810 return E_OUTOFMEMORY
;
812 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
814 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
816 const xmlChar
*buf_content
;
819 /* Attribute Nodes return a space in front of their name */
820 buf_content
= xmlBufferContent(xml_buf
);
822 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
824 content
= EnsureCorrectEOL(content
);
828 *ret
= SysAllocStringLen(NULL
, 0);
831 xmlBufferFree(xml_buf
);
832 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
833 return *ret
? S_OK
: E_OUTOFMEMORY
;
836 HRESULT
node_transform_node(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
838 #ifdef SONAME_LIBXSLT
839 xsltStylesheetPtr xsltSS
;
842 if (!libxslt_handle
) return E_NOTIMPL
;
843 if (!stylesheet
|| !p
) return E_INVALIDARG
;
847 sheet
= get_node_obj(stylesheet
);
848 if(!sheet
) return E_FAIL
;
850 xsltSS
= pxsltParseStylesheetDoc(sheet
->node
->doc
);
853 xmlDocPtr result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
856 const xmlChar
*content
;
858 if(result
->type
== XML_HTML_DOCUMENT_NODE
)
860 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(NULL
);
863 htmlDocContentDumpOutput(output
, result
->doc
, NULL
);
864 content
= xmlBufferContent(output
->buffer
);
865 *p
= bstr_from_xmlChar(content
);
866 xmlOutputBufferClose(output
);
871 xmlBufferPtr buf
= xmlBufferCreate();
874 int size
= xmlNodeDump(buf
, NULL
, (xmlNodePtr
)result
, 0, 0);
877 content
= xmlBufferContent(buf
);
878 *p
= bstr_from_xmlChar(content
);
885 /* libxslt "helpfully" frees the XML document the stylesheet was
886 generated from, too */
888 pxsltFreeStylesheet(xsltSS
);
891 if(!*p
) *p
= SysAllocStringLen(NULL
, 0);
895 FIXME("libxslt headers were not found at compile time\n");
900 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
905 if (!query
|| !nodes
) return E_INVALIDARG
;
907 str
= xmlchar_from_wchar(query
);
908 hr
= create_selection(This
->node
, str
, nodes
);
914 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
916 IXMLDOMNodeList
*list
;
919 hr
= node_select_nodes(This
, query
, &list
);
922 hr
= IXMLDOMNodeList_nextNode(list
, node
);
923 IXMLDOMNodeList_Release(list
);
928 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
930 xmlNsPtr ns
= This
->node
->ns
;
935 *namespaceURI
= NULL
;
938 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
940 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
942 return *namespaceURI
? S_OK
: S_FALSE
;
945 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
947 xmlNsPtr ns
= This
->node
->ns
;
949 if (!prefix
) return E_INVALIDARG
;
953 if (ns
&& ns
->prefix
)
954 *prefix
= bstr_from_xmlChar(ns
->prefix
);
956 TRACE("prefix: %s\n", debugstr_w(*prefix
));
958 return *prefix
? S_OK
: S_FALSE
;
961 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
963 if (!name
) return E_INVALIDARG
;
965 *name
= bstr_from_xmlChar(This
->node
->name
);
966 if (!*name
) return E_OUTOFMEMORY
;
968 TRACE("returning %s\n", debugstr_w(*name
));
973 void destroy_xmlnode(xmlnode
*This
)
976 xmldoc_release(This
->node
->doc
);
977 release_dispex(&This
->dispex
);
980 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
983 xmldoc_add_ref( node
->doc
);
986 This
->iface
= node_iface
;
989 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
994 IXMLDOMNode IXMLDOMNode_iface
;
998 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1000 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1003 static HRESULT WINAPI
unknode_QueryInterface(
1008 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1010 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1012 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1014 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1015 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1016 *ppvObject
= &This
->IXMLDOMNode_iface
;
1017 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1018 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1020 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1022 return E_NOINTERFACE
;
1025 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1029 static ULONG WINAPI
unknode_AddRef(
1030 IXMLDOMNode
*iface
)
1032 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1034 return InterlockedIncrement(&This
->ref
);
1037 static ULONG WINAPI
unknode_Release(
1038 IXMLDOMNode
*iface
)
1040 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1043 ref
= InterlockedDecrement( &This
->ref
);
1045 destroy_xmlnode(&This
->node
);
1052 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1056 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1058 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1065 static HRESULT WINAPI
unknode_GetTypeInfo(
1069 ITypeInfo
** ppTInfo
)
1071 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1074 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1076 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1081 static HRESULT WINAPI
unknode_GetIDsOfNames(
1084 LPOLESTR
* rgszNames
,
1089 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1091 ITypeInfo
*typeinfo
;
1094 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1097 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1098 return E_INVALIDARG
;
1100 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1103 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1104 ITypeInfo_Release(typeinfo
);
1110 static HRESULT WINAPI
unknode_Invoke(
1112 DISPID dispIdMember
,
1116 DISPPARAMS
* pDispParams
,
1117 VARIANT
* pVarResult
,
1118 EXCEPINFO
* pExcepInfo
,
1121 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1122 ITypeInfo
*typeinfo
;
1125 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1126 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1128 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1131 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1132 pVarResult
, pExcepInfo
, puArgErr
);
1133 ITypeInfo_Release(typeinfo
);
1139 static HRESULT WINAPI
unknode_get_nodeName(
1143 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1145 FIXME("(%p)->(%p)\n", This
, p
);
1147 return node_get_nodeName(&This
->node
, p
);
1150 static HRESULT WINAPI
unknode_get_nodeValue(
1154 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1156 FIXME("(%p)->(%p)\n", This
, value
);
1159 return E_INVALIDARG
;
1161 V_VT(value
) = VT_NULL
;
1165 static HRESULT WINAPI
unknode_put_nodeValue(
1169 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1170 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1174 static HRESULT WINAPI
unknode_get_nodeType(
1176 DOMNodeType
* domNodeType
)
1178 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1180 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1182 *domNodeType
= This
->node
.node
->type
;
1186 static HRESULT WINAPI
unknode_get_parentNode(
1188 IXMLDOMNode
** parent
)
1190 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1191 FIXME("(%p)->(%p)\n", This
, parent
);
1192 if (!parent
) return E_INVALIDARG
;
1197 static HRESULT WINAPI
unknode_get_childNodes(
1199 IXMLDOMNodeList
** outList
)
1201 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1203 TRACE("(%p)->(%p)\n", This
, outList
);
1205 return node_get_child_nodes(&This
->node
, outList
);
1208 static HRESULT WINAPI
unknode_get_firstChild(
1210 IXMLDOMNode
** domNode
)
1212 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1214 TRACE("(%p)->(%p)\n", This
, domNode
);
1216 return node_get_first_child(&This
->node
, domNode
);
1219 static HRESULT WINAPI
unknode_get_lastChild(
1221 IXMLDOMNode
** domNode
)
1223 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1225 TRACE("(%p)->(%p)\n", This
, domNode
);
1227 return node_get_last_child(&This
->node
, domNode
);
1230 static HRESULT WINAPI
unknode_get_previousSibling(
1232 IXMLDOMNode
** domNode
)
1234 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1236 TRACE("(%p)->(%p)\n", This
, domNode
);
1238 return node_get_previous_sibling(&This
->node
, domNode
);
1241 static HRESULT WINAPI
unknode_get_nextSibling(
1243 IXMLDOMNode
** domNode
)
1245 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1247 TRACE("(%p)->(%p)\n", This
, domNode
);
1249 return node_get_next_sibling(&This
->node
, domNode
);
1252 static HRESULT WINAPI
unknode_get_attributes(
1254 IXMLDOMNamedNodeMap
** attributeMap
)
1256 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1258 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1260 return return_null_ptr((void**)attributeMap
);
1263 static HRESULT WINAPI
unknode_insertBefore(
1265 IXMLDOMNode
* newNode
, VARIANT refChild
,
1266 IXMLDOMNode
** outOldNode
)
1268 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1270 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1272 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1275 static HRESULT WINAPI
unknode_replaceChild(
1277 IXMLDOMNode
* newNode
,
1278 IXMLDOMNode
* oldNode
,
1279 IXMLDOMNode
** outOldNode
)
1281 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1283 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1285 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1288 static HRESULT WINAPI
unknode_removeChild(
1290 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1292 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1293 return node_remove_child(&This
->node
, domNode
, oldNode
);
1296 static HRESULT WINAPI
unknode_appendChild(
1298 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1300 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1301 return node_append_child(&This
->node
, newNode
, outNewNode
);
1304 static HRESULT WINAPI
unknode_hasChildNodes(
1306 VARIANT_BOOL
* pbool
)
1308 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1309 return node_has_childnodes(&This
->node
, pbool
);
1312 static HRESULT WINAPI
unknode_get_ownerDocument(
1314 IXMLDOMDocument
** domDocument
)
1316 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1317 return node_get_owner_doc(&This
->node
, domDocument
);
1320 static HRESULT WINAPI
unknode_cloneNode(
1322 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1324 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1325 return node_clone(&This
->node
, pbool
, outNode
);
1328 static HRESULT WINAPI
unknode_get_nodeTypeString(
1332 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1334 FIXME("(%p)->(%p)\n", This
, p
);
1336 return node_get_nodeName(&This
->node
, p
);
1339 static HRESULT WINAPI
unknode_get_text(
1343 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1344 return node_get_text(&This
->node
, p
);
1347 static HRESULT WINAPI
unknode_put_text(
1351 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1352 return node_put_text(&This
->node
, p
);
1355 static HRESULT WINAPI
unknode_get_specified(
1357 VARIANT_BOOL
* isSpecified
)
1359 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1360 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
1361 *isSpecified
= VARIANT_TRUE
;
1365 static HRESULT WINAPI
unknode_get_definition(
1367 IXMLDOMNode
** definitionNode
)
1369 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1370 FIXME("(%p)->(%p)\n", This
, definitionNode
);
1374 static HRESULT WINAPI
unknode_get_nodeTypedValue(
1378 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1379 FIXME("(%p)->(%p)\n", This
, var1
);
1380 return return_null_var(var1
);
1383 static HRESULT WINAPI
unknode_put_nodeTypedValue(
1387 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1388 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
1392 static HRESULT WINAPI
unknode_get_dataType(
1396 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1397 TRACE("(%p)->(%p)\n", This
, var1
);
1398 return return_null_var(var1
);
1401 static HRESULT WINAPI
unknode_put_dataType(
1405 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1407 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
1410 return E_INVALIDARG
;
1415 static HRESULT WINAPI
unknode_get_xml(
1419 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1421 FIXME("(%p)->(%p)\n", This
, p
);
1423 return node_get_xml(&This
->node
, FALSE
, p
);
1426 static HRESULT WINAPI
unknode_transformNode(
1428 IXMLDOMNode
* domNode
, BSTR
* p
)
1430 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1431 return node_transform_node(&This
->node
, domNode
, p
);
1434 static HRESULT WINAPI
unknode_selectNodes(
1436 BSTR p
, IXMLDOMNodeList
** outList
)
1438 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1439 return node_select_nodes(&This
->node
, p
, outList
);
1442 static HRESULT WINAPI
unknode_selectSingleNode(
1444 BSTR p
, IXMLDOMNode
** outNode
)
1446 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1447 return node_select_singlenode(&This
->node
, p
, outNode
);
1450 static HRESULT WINAPI
unknode_get_parsed(
1452 VARIANT_BOOL
* isParsed
)
1454 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1455 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
1456 *isParsed
= VARIANT_TRUE
;
1460 static HRESULT WINAPI
unknode_get_namespaceURI(
1464 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1465 TRACE("(%p)->(%p)\n", This
, p
);
1466 return node_get_namespaceURI(&This
->node
, p
);
1469 static HRESULT WINAPI
unknode_get_prefix(
1473 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1474 return node_get_prefix(&This
->node
, p
);
1477 static HRESULT WINAPI
unknode_get_baseName(
1481 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1482 return node_get_base_name(&This
->node
, p
);
1485 static HRESULT WINAPI
unknode_transformNodeToObject(
1487 IXMLDOMNode
* domNode
, VARIANT var1
)
1489 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1490 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
1494 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
1496 unknode_QueryInterface
,
1499 unknode_GetTypeInfoCount
,
1500 unknode_GetTypeInfo
,
1501 unknode_GetIDsOfNames
,
1503 unknode_get_nodeName
,
1504 unknode_get_nodeValue
,
1505 unknode_put_nodeValue
,
1506 unknode_get_nodeType
,
1507 unknode_get_parentNode
,
1508 unknode_get_childNodes
,
1509 unknode_get_firstChild
,
1510 unknode_get_lastChild
,
1511 unknode_get_previousSibling
,
1512 unknode_get_nextSibling
,
1513 unknode_get_attributes
,
1514 unknode_insertBefore
,
1515 unknode_replaceChild
,
1516 unknode_removeChild
,
1517 unknode_appendChild
,
1518 unknode_hasChildNodes
,
1519 unknode_get_ownerDocument
,
1521 unknode_get_nodeTypeString
,
1524 unknode_get_specified
,
1525 unknode_get_definition
,
1526 unknode_get_nodeTypedValue
,
1527 unknode_put_nodeTypedValue
,
1528 unknode_get_dataType
,
1529 unknode_put_dataType
,
1531 unknode_transformNode
,
1532 unknode_selectNodes
,
1533 unknode_selectSingleNode
,
1535 unknode_get_namespaceURI
,
1537 unknode_get_baseName
,
1538 unknode_transformNodeToObject
1541 IXMLDOMNode
*create_node( xmlNodePtr node
)
1550 TRACE("type %d\n", node
->type
);
1553 case XML_ELEMENT_NODE
:
1554 pUnk
= create_element( node
);
1556 case XML_ATTRIBUTE_NODE
:
1557 pUnk
= create_attribute( node
);
1560 pUnk
= create_text( node
);
1562 case XML_CDATA_SECTION_NODE
:
1563 pUnk
= create_cdata( node
);
1565 case XML_ENTITY_REF_NODE
:
1566 pUnk
= create_doc_entity_ref( node
);
1569 pUnk
= create_pi( node
);
1571 case XML_COMMENT_NODE
:
1572 pUnk
= create_comment( node
);
1574 case XML_DOCUMENT_NODE
:
1575 pUnk
= create_domdoc( node
);
1577 case XML_DOCUMENT_FRAG_NODE
:
1578 pUnk
= create_doc_fragment( node
);
1581 pUnk
= create_doc_type( node
);
1586 FIXME("only creating basic node for type %d\n", node
->type
);
1588 new_node
= heap_alloc(sizeof(unknode
));
1592 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
1594 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
1595 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
1599 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
1600 IUnknown_Release(pUnk
);
1601 if(FAILED(hr
)) return NULL
;