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
21 #define WIN32_NO_STATUS
31 //# include <libxml/parser.h>
32 //# include <libxml/xmlerror.h>
33 # include <libxml/HTMLtree.h>
34 # ifdef SONAME_LIBXSLT
35 # ifdef HAVE_LIBXSLT_PATTERN_H
36 # include <libxslt/pattern.h>
38 # ifdef HAVE_LIBXSLT_TRANSFORM_H
39 # include <libxslt/transform.h>
41 # include <libxslt/xsltutils.h>
42 # include <libxslt/xsltInternals.h>
48 //#include "winuser.h"
53 #include "msxml_private.h"
55 #include <wine/debug.h>
57 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
62 extern void* libxslt_handle
;
63 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
64 MAKE_FUNCPTR(xsltApplyStylesheet
);
65 MAKE_FUNCPTR(xsltCleanupGlobals
);
66 MAKE_FUNCPTR(xsltFreeStylesheet
);
67 MAKE_FUNCPTR(xsltParseStylesheetDoc
);
71 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
73 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
79 This
= get_node_obj( iface
);
80 if ( !This
|| !This
->node
)
82 if ( type
&& This
->node
->type
!= type
)
87 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
89 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
90 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
95 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
98 /* common ISupportErrorInfo implementation */
100 ISupportErrorInfo ISupportErrorInfo_iface
;
106 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
108 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
111 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
113 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
114 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
118 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
120 ISupportErrorInfo_AddRef(iface
);
124 return E_NOINTERFACE
;
127 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
129 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
130 ULONG ref
= InterlockedIncrement(&This
->ref
);
131 TRACE("(%p)->(%d)\n", This
, ref
);
135 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
137 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
138 LONG ref
= InterlockedDecrement(&This
->ref
);
140 TRACE("(%p)->(%d)\n", This
, ref
);
148 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
150 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
151 enum tid_t
const *tid
;
153 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
158 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
166 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
167 SupportErrorInfo_QueryInterface
,
168 SupportErrorInfo_AddRef
,
169 SupportErrorInfo_Release
,
170 SupportErrorInfo_InterfaceSupportsErrorInfo
173 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
175 SupportErrorInfo
*This
;
177 This
= heap_alloc(sizeof(*This
));
178 if (!This
) return E_OUTOFMEMORY
;
180 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
184 *obj
= &This
->ISupportErrorInfo_iface
;
189 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
194 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
195 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
196 return SUCCEEDED(hres
) ? obj
: NULL
;
199 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
207 hr
= node_get_base_name(This
, &base
);
208 if (hr
!= S_OK
) return hr
;
210 hr
= node_get_prefix(This
, &prefix
);
213 static const WCHAR colW
= ':';
217 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
218 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
219 ptr
+= SysStringLen(prefix
);
220 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
221 memcpy(ptr
, base
, SysStringByteLen(base
));
224 SysFreeString(prefix
);
232 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
239 content
= xmlNodeGetContent(This
->node
);
240 V_VT(value
) = VT_BSTR
;
241 V_BSTR(value
) = bstr_from_xmlChar( content
);
244 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
248 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
252 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
253 str
= xmlchar_from_wchar(value
);
255 return E_OUTOFMEMORY
;
257 xmlNodeSetContent(This
->node
, str
);
262 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
264 xmlChar
*str
, *escaped
;
266 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
267 str
= xmlchar_from_wchar(value
);
269 return E_OUTOFMEMORY
;
271 escaped
= xmlEncodeSpecialChars(NULL
, str
);
275 return E_OUTOFMEMORY
;
278 xmlNodeSetContent(This
->node
, escaped
);
286 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
290 if (V_VT(value
) != VT_BSTR
)
292 VARIANT string_value
;
294 VariantInit(&string_value
);
295 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
297 WARN("Couldn't convert to VT_BSTR\n");
301 hr
= node_set_content(This
, V_BSTR(&string_value
));
302 VariantClear(&string_value
);
305 hr
= node_set_content(This
, V_BSTR(value
));
310 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
314 if (V_VT(value
) != VT_BSTR
)
316 VARIANT string_value
;
318 VariantInit(&string_value
);
319 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
321 WARN("Couldn't convert to VT_BSTR\n");
325 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
326 VariantClear(&string_value
);
329 hr
= node_set_content_escaped(This
, V_BSTR(value
));
334 static HRESULT
get_node(
340 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
345 /* if we don't have a doc, use our parent. */
346 if(node
&& !node
->doc
&& node
->parent
)
347 node
->doc
= node
->parent
->doc
;
349 *out
= create_node( node
);
355 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
357 return get_node( This
, "parent", This
->node
->parent
, parent
);
360 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
365 *ret
= create_children_nodelist(This
->node
);
367 return E_OUTOFMEMORY
;
372 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
374 return get_node(This
, "firstChild", This
->node
->children
, ret
);
377 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
379 return get_node(This
, "lastChild", This
->node
->last
, ret
);
382 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
384 return get_node(This
, "previous", This
->node
->prev
, ret
);
387 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
389 return get_node(This
, "next", This
->node
->next
, ret
);
392 static int node_get_inst_cnt(xmlNodePtr node
)
394 int ret
= *(LONG
*)&node
->_private
;
397 /* add attribute counts */
398 if (node
->type
== XML_ELEMENT_NODE
)
400 xmlAttrPtr prop
= node
->properties
;
404 ret
+= node_get_inst_cnt((xmlNodePtr
)prop
);
409 /* add children counts */
410 child
= node
->children
;
413 ret
+= node_get_inst_cnt(child
);
420 int xmlnode_get_inst_cnt(xmlnode
*node
)
422 return node_get_inst_cnt(node
->node
);
425 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
428 IXMLDOMNode
*before
= NULL
;
437 node_obj
= get_node_obj(new_child
);
438 if(!node_obj
) return E_FAIL
;
440 switch(V_VT(ref_child
))
448 if (V_UNKNOWN(ref_child
))
450 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
451 if(FAILED(hr
)) return hr
;
456 FIXME("refChild var type %x\n", V_VT(ref_child
));
460 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
462 if(!node_obj
->node
->parent
)
463 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
464 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
466 refcount
= xmlnode_get_inst_cnt(node_obj
);
470 xmlnode
*before_node_obj
= get_node_obj(before
);
471 IXMLDOMNode_Release(before
);
472 if(!before_node_obj
) return E_FAIL
;
474 /* unlink from current parent first */
477 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
478 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
481 doc
= node_obj
->node
->doc
;
483 /* refs count including subtree */
484 if (doc
!= before_node_obj
->node
->doc
)
485 refcount
= xmlnode_get_inst_cnt(node_obj
);
487 if (refcount
) xmldoc_add_refs(before_node_obj
->node
->doc
, refcount
);
488 xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
489 if (refcount
) xmldoc_release_refs(doc
, refcount
);
490 node_obj
->parent
= This
->parent
;
494 /* unlink from current parent first */
497 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
498 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
500 doc
= node_obj
->node
->doc
;
502 if (doc
!= This
->node
->doc
)
503 refcount
= xmlnode_get_inst_cnt(node_obj
);
505 if (refcount
) xmldoc_add_refs(This
->node
->doc
, refcount
);
506 /* xmlAddChild doesn't unlink node from previous parent */
507 xmlUnlinkNode(node_obj
->node
);
508 xmlAddChild(This
->node
, node_obj
->node
);
509 if (refcount
) xmldoc_release_refs(doc
, refcount
);
510 node_obj
->parent
= This
->iface
;
515 IXMLDOMNode_AddRef(new_child
);
523 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
526 xmlnode
*old_child
, *new_child
;
527 xmlDocPtr leaving_doc
;
528 xmlNode
*my_ancestor
;
531 /* Do not believe any documentation telling that newChild == NULL
532 means removal. It does certainly *not* apply to msxml3! */
533 if(!newChild
|| !oldChild
)
539 old_child
= get_node_obj(oldChild
);
540 if(!old_child
) return E_FAIL
;
542 if(old_child
->node
->parent
!= This
->node
)
544 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
548 new_child
= get_node_obj(newChild
);
549 if(!new_child
) return E_FAIL
;
551 my_ancestor
= This
->node
;
554 if(my_ancestor
== new_child
->node
)
556 WARN("tried to create loop\n");
559 my_ancestor
= my_ancestor
->parent
;
562 if(!new_child
->node
->parent
)
563 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
564 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
566 leaving_doc
= new_child
->node
->doc
;
568 if (leaving_doc
!= old_child
->node
->doc
)
569 refcount
= xmlnode_get_inst_cnt(new_child
);
571 if (refcount
) xmldoc_add_refs(old_child
->node
->doc
, refcount
);
572 xmlReplaceNode(old_child
->node
, new_child
->node
);
573 if (refcount
) xmldoc_release_refs(leaving_doc
, refcount
);
574 new_child
->parent
= old_child
->parent
;
575 old_child
->parent
= NULL
;
577 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
581 IXMLDOMNode_AddRef(oldChild
);
588 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
592 if(!child
) return E_INVALIDARG
;
597 child_node
= get_node_obj(child
);
598 if(!child_node
) return E_FAIL
;
600 if(child_node
->node
->parent
!= This
->node
)
602 WARN("childNode %p is not a child of %p\n", child
, This
);
606 xmlUnlinkNode(child_node
->node
);
607 child_node
->parent
= NULL
;
608 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
612 IXMLDOMNode_AddRef(child
);
619 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
625 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
626 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
627 if (outChild
) *outChild
= NULL
;
632 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
635 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
637 if (!ret
) return E_INVALIDARG
;
639 if (!This
->node
->children
)
641 *ret
= VARIANT_FALSE
;
649 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
651 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
654 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
659 if(!cloneNode
) return E_INVALIDARG
;
661 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
664 xmlSetTreeDoc(clone
, This
->node
->doc
);
665 xmldoc_add_orphan(clone
->doc
, clone
);
667 node
= create_node(clone
);
670 ERR("Copy failed\n");
671 xmldoc_remove_orphan(clone
->doc
, clone
);
680 ERR("Copy failed\n");
687 static inline xmlChar
* trim_whitespace(xmlChar
* str
)
695 while (*ret
&& isspace(*ret
))
697 len
= xmlStrlen(ret
);
699 while (isspace(ret
[len
-1])) --len
;
701 ret
= xmlStrndup(ret
, len
);
706 static xmlChar
* do_get_text(xmlNodePtr node
)
710 BOOL preserving
= is_preserving_whitespace(node
);
714 str
= xmlNodeGetContent(node
);
718 xmlElementType prev_type
= XML_TEXT_NODE
;
720 str
= xmlStrdup(BAD_CAST
"");
721 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
725 case XML_ELEMENT_NODE
:
726 tmp
= do_get_text(child
);
729 case XML_CDATA_SECTION_NODE
:
730 case XML_ENTITY_REF_NODE
:
731 case XML_ENTITY_NODE
:
732 tmp
= xmlNodeGetContent(child
);
743 if (prev_type
== XML_ELEMENT_NODE
&& child
->type
== XML_ELEMENT_NODE
)
744 str
= xmlStrcat(str
, BAD_CAST
" ");
745 str
= xmlStrcat(str
, tmp
);
746 prev_type
= child
->type
;
755 case XML_ELEMENT_NODE
:
757 case XML_ENTITY_REF_NODE
:
758 case XML_ENTITY_NODE
:
759 case XML_DOCUMENT_NODE
:
760 case XML_DOCUMENT_FRAG_NODE
:
762 str
= trim_whitespace(str
);
771 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
776 if (!text
) return E_INVALIDARG
;
778 content
= do_get_text(This
->node
);
781 str
= bstr_from_xmlChar(content
);
785 /* Always return a string. */
786 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
788 TRACE("%p %s\n", This
, debugstr_w(str
) );
794 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
798 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
800 str
= xmlchar_from_wchar(text
);
802 /* Escape the string. */
803 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
806 xmlNodeSetContent(This
->node
, str2
);
812 BSTR
EnsureCorrectEOL(BSTR sInput
)
819 nLen
= SysStringLen(sInput
);
820 /* Count line endings */
821 for(i
=0; i
< nLen
; i
++)
823 if(sInput
[i
] == '\n')
827 TRACE("len=%d, num=%d\n", nLen
, nNum
);
829 /* Add linefeed as needed */
833 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
834 for(i
=0; i
< nLen
; i
++)
836 if(sInput
[i
] == '\n')
838 sNew
[i
+nPlace
] = '\r';
841 sNew
[i
+nPlace
] = sInput
[i
];
844 SysFreeString(sInput
);
851 TRACE("len %d\n", SysStringLen(sNew
));
857 * We are trying to replicate the same behaviour as msxml by converting
858 * line endings to \r\n and using indents as \t. The problem is that msxml
859 * only formats nodes that have a line ending. Using libxml we cannot
860 * reproduce behaviour exactly.
863 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
865 xmlBufferPtr xml_buf
;
874 xml_buf
= xmlBufferCreate();
876 return E_OUTOFMEMORY
;
878 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
880 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
882 const xmlChar
*buf_content
;
885 /* Attribute Nodes return a space in front of their name */
886 buf_content
= xmlBufferContent(xml_buf
);
888 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
890 content
= EnsureCorrectEOL(content
);
894 *ret
= SysAllocStringLen(NULL
, 0);
897 xmlBufferFree(xml_buf
);
898 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
899 return *ret
? S_OK
: E_OUTOFMEMORY
;
902 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
904 xmlDtdPtr cur
= doc
->intSubset
;
906 xmlOutputBufferWriteString(buf
, "<!DOCTYPE ");
907 xmlOutputBufferWriteString(buf
, (const char *)cur
->name
);
910 xmlOutputBufferWriteString(buf
, " PUBLIC ");
911 xmlBufferWriteQuotedString(buf
->buffer
, cur
->ExternalID
);
914 xmlOutputBufferWriteString(buf
, " ");
915 xmlBufferWriteQuotedString(buf
->buffer
, cur
->SystemID
);
918 else if (cur
->SystemID
)
920 xmlOutputBufferWriteString(buf
, " SYSTEM ");
921 xmlBufferWriteQuotedString(buf
->buffer
, cur
->SystemID
);
923 xmlOutputBufferWriteString(buf
, ">\n");
926 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
930 /* force HTML output */
932 doc
->type
= XML_HTML_DOCUMENT_NODE
;
934 htmldtd_dumpcontent(buf
, doc
);
937 xmlNodePtr cur
= doc
->children
;
941 htmlNodeDumpFormatOutput(buf
, doc
, cur
, NULL
, 1);
949 HRESULT
node_transform_node(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
951 #ifdef SONAME_LIBXSLT
952 xsltStylesheetPtr xsltSS
;
955 if (!libxslt_handle
) return E_NOTIMPL
;
956 if (!stylesheet
|| !p
) return E_INVALIDARG
;
960 sheet
= get_node_obj(stylesheet
);
961 if(!sheet
) return E_FAIL
;
963 xsltSS
= pxsltParseStylesheetDoc(sheet
->node
->doc
);
966 xmlDocPtr result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
969 const xmlChar
*content
;
971 if(result
->type
== XML_HTML_DOCUMENT_NODE
)
973 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(NULL
);
976 htmldoc_dumpcontent(output
, result
->doc
);
977 content
= xmlBufferContent(output
->buffer
);
978 *p
= bstr_from_xmlChar(content
);
979 xmlOutputBufferClose(output
);
984 xmlBufferPtr buf
= xmlBufferCreate();
987 int size
= xmlNodeDump(buf
, NULL
, (xmlNodePtr
)result
, 0, 0);
990 content
= xmlBufferContent(buf
);
991 *p
= bstr_from_xmlChar(content
);
998 /* libxslt "helpfully" frees the XML document the stylesheet was
999 generated from, too */
1001 pxsltFreeStylesheet(xsltSS
);
1004 if(!*p
) *p
= SysAllocStringLen(NULL
, 0);
1008 FIXME("libxslt headers were not found at compile time\n");
1013 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1018 if (!query
|| !nodes
) return E_INVALIDARG
;
1020 str
= xmlchar_from_wchar(query
);
1021 hr
= create_selection(This
->node
, str
, nodes
);
1027 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1029 IXMLDOMNodeList
*list
;
1032 hr
= node_select_nodes(This
, query
, &list
);
1035 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1036 IXMLDOMNodeList_Release(list
);
1041 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1043 xmlNsPtr ns
= This
->node
->ns
;
1046 return E_INVALIDARG
;
1048 *namespaceURI
= NULL
;
1051 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1053 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1055 return *namespaceURI
? S_OK
: S_FALSE
;
1058 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1060 xmlNsPtr ns
= This
->node
->ns
;
1062 if (!prefix
) return E_INVALIDARG
;
1066 if (ns
&& ns
->prefix
)
1067 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1069 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1071 return *prefix
? S_OK
: S_FALSE
;
1074 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1076 if (!name
) return E_INVALIDARG
;
1078 *name
= bstr_from_xmlChar(This
->node
->name
);
1079 if (!*name
) return E_OUTOFMEMORY
;
1081 TRACE("returning %s\n", debugstr_w(*name
));
1086 /* _private field holds a number of COM instances spawned from this libxml2 node */
1087 static void xmlnode_add_ref(xmlNodePtr node
)
1089 if (node
->type
== XML_DOCUMENT_NODE
) return;
1090 InterlockedIncrement((LONG
*)&node
->_private
);
1093 static void xmlnode_release(xmlNodePtr node
)
1095 if (node
->type
== XML_DOCUMENT_NODE
) return;
1096 InterlockedDecrement((LONG
*)&node
->_private
);
1099 void destroy_xmlnode(xmlnode
*This
)
1103 xmlnode_release(This
->node
);
1104 xmldoc_release(This
->node
->doc
);
1106 release_dispex(&This
->dispex
);
1109 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1113 xmlnode_add_ref(node
);
1114 xmldoc_add_ref(node
->doc
);
1118 This
->iface
= node_iface
;
1119 This
->parent
= NULL
;
1121 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1126 IXMLDOMNode IXMLDOMNode_iface
;
1130 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1132 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1135 static HRESULT WINAPI
unknode_QueryInterface(
1140 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1142 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1144 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1146 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1147 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1148 *ppvObject
= &This
->IXMLDOMNode_iface
;
1149 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1150 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1152 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1154 return E_NOINTERFACE
;
1157 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1161 static ULONG WINAPI
unknode_AddRef(
1162 IXMLDOMNode
*iface
)
1164 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1166 return InterlockedIncrement(&This
->ref
);
1169 static ULONG WINAPI
unknode_Release(
1170 IXMLDOMNode
*iface
)
1172 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1175 ref
= InterlockedDecrement( &This
->ref
);
1177 destroy_xmlnode(&This
->node
);
1184 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1188 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1190 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1197 static HRESULT WINAPI
unknode_GetTypeInfo(
1201 ITypeInfo
** ppTInfo
)
1203 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1206 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1208 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1213 static HRESULT WINAPI
unknode_GetIDsOfNames(
1216 LPOLESTR
* rgszNames
,
1221 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1223 ITypeInfo
*typeinfo
;
1226 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1229 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1230 return E_INVALIDARG
;
1232 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1235 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1236 ITypeInfo_Release(typeinfo
);
1242 static HRESULT WINAPI
unknode_Invoke(
1244 DISPID dispIdMember
,
1248 DISPPARAMS
* pDispParams
,
1249 VARIANT
* pVarResult
,
1250 EXCEPINFO
* pExcepInfo
,
1253 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1254 ITypeInfo
*typeinfo
;
1257 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1258 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1260 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1263 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1264 pVarResult
, pExcepInfo
, puArgErr
);
1265 ITypeInfo_Release(typeinfo
);
1271 static HRESULT WINAPI
unknode_get_nodeName(
1275 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1277 FIXME("(%p)->(%p)\n", This
, p
);
1279 return node_get_nodeName(&This
->node
, p
);
1282 static HRESULT WINAPI
unknode_get_nodeValue(
1286 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1288 FIXME("(%p)->(%p)\n", This
, value
);
1291 return E_INVALIDARG
;
1293 V_VT(value
) = VT_NULL
;
1297 static HRESULT WINAPI
unknode_put_nodeValue(
1301 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1302 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1306 static HRESULT WINAPI
unknode_get_nodeType(
1308 DOMNodeType
* domNodeType
)
1310 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1312 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1314 *domNodeType
= This
->node
.node
->type
;
1318 static HRESULT WINAPI
unknode_get_parentNode(
1320 IXMLDOMNode
** parent
)
1322 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1323 FIXME("(%p)->(%p)\n", This
, parent
);
1324 if (!parent
) return E_INVALIDARG
;
1329 static HRESULT WINAPI
unknode_get_childNodes(
1331 IXMLDOMNodeList
** outList
)
1333 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1335 TRACE("(%p)->(%p)\n", This
, outList
);
1337 return node_get_child_nodes(&This
->node
, outList
);
1340 static HRESULT WINAPI
unknode_get_firstChild(
1342 IXMLDOMNode
** domNode
)
1344 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1346 TRACE("(%p)->(%p)\n", This
, domNode
);
1348 return node_get_first_child(&This
->node
, domNode
);
1351 static HRESULT WINAPI
unknode_get_lastChild(
1353 IXMLDOMNode
** domNode
)
1355 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1357 TRACE("(%p)->(%p)\n", This
, domNode
);
1359 return node_get_last_child(&This
->node
, domNode
);
1362 static HRESULT WINAPI
unknode_get_previousSibling(
1364 IXMLDOMNode
** domNode
)
1366 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1368 TRACE("(%p)->(%p)\n", This
, domNode
);
1370 return node_get_previous_sibling(&This
->node
, domNode
);
1373 static HRESULT WINAPI
unknode_get_nextSibling(
1375 IXMLDOMNode
** domNode
)
1377 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1379 TRACE("(%p)->(%p)\n", This
, domNode
);
1381 return node_get_next_sibling(&This
->node
, domNode
);
1384 static HRESULT WINAPI
unknode_get_attributes(
1386 IXMLDOMNamedNodeMap
** attributeMap
)
1388 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1390 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1392 return return_null_ptr((void**)attributeMap
);
1395 static HRESULT WINAPI
unknode_insertBefore(
1397 IXMLDOMNode
* newNode
, VARIANT refChild
,
1398 IXMLDOMNode
** outOldNode
)
1400 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1402 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1404 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1407 static HRESULT WINAPI
unknode_replaceChild(
1409 IXMLDOMNode
* newNode
,
1410 IXMLDOMNode
* oldNode
,
1411 IXMLDOMNode
** outOldNode
)
1413 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1415 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1417 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1420 static HRESULT WINAPI
unknode_removeChild(
1422 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1424 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1425 return node_remove_child(&This
->node
, domNode
, oldNode
);
1428 static HRESULT WINAPI
unknode_appendChild(
1430 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1432 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1433 return node_append_child(&This
->node
, newNode
, outNewNode
);
1436 static HRESULT WINAPI
unknode_hasChildNodes(
1438 VARIANT_BOOL
* pbool
)
1440 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1441 return node_has_childnodes(&This
->node
, pbool
);
1444 static HRESULT WINAPI
unknode_get_ownerDocument(
1446 IXMLDOMDocument
** domDocument
)
1448 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1449 return node_get_owner_doc(&This
->node
, domDocument
);
1452 static HRESULT WINAPI
unknode_cloneNode(
1454 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1456 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1457 return node_clone(&This
->node
, pbool
, outNode
);
1460 static HRESULT WINAPI
unknode_get_nodeTypeString(
1464 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1466 FIXME("(%p)->(%p)\n", This
, p
);
1468 return node_get_nodeName(&This
->node
, p
);
1471 static HRESULT WINAPI
unknode_get_text(
1475 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1476 return node_get_text(&This
->node
, p
);
1479 static HRESULT WINAPI
unknode_put_text(
1483 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1484 return node_put_text(&This
->node
, p
);
1487 static HRESULT WINAPI
unknode_get_specified(
1489 VARIANT_BOOL
* isSpecified
)
1491 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1492 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
1493 *isSpecified
= VARIANT_TRUE
;
1497 static HRESULT WINAPI
unknode_get_definition(
1499 IXMLDOMNode
** definitionNode
)
1501 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1502 FIXME("(%p)->(%p)\n", This
, definitionNode
);
1506 static HRESULT WINAPI
unknode_get_nodeTypedValue(
1510 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1511 FIXME("(%p)->(%p)\n", This
, var1
);
1512 return return_null_var(var1
);
1515 static HRESULT WINAPI
unknode_put_nodeTypedValue(
1519 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1520 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
1524 static HRESULT WINAPI
unknode_get_dataType(
1528 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1529 TRACE("(%p)->(%p)\n", This
, var1
);
1530 return return_null_var(var1
);
1533 static HRESULT WINAPI
unknode_put_dataType(
1537 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1539 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
1542 return E_INVALIDARG
;
1547 static HRESULT WINAPI
unknode_get_xml(
1551 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1553 FIXME("(%p)->(%p)\n", This
, p
);
1555 return node_get_xml(&This
->node
, FALSE
, p
);
1558 static HRESULT WINAPI
unknode_transformNode(
1560 IXMLDOMNode
* domNode
, BSTR
* p
)
1562 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1563 return node_transform_node(&This
->node
, domNode
, p
);
1566 static HRESULT WINAPI
unknode_selectNodes(
1568 BSTR p
, IXMLDOMNodeList
** outList
)
1570 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1571 return node_select_nodes(&This
->node
, p
, outList
);
1574 static HRESULT WINAPI
unknode_selectSingleNode(
1576 BSTR p
, IXMLDOMNode
** outNode
)
1578 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1579 return node_select_singlenode(&This
->node
, p
, outNode
);
1582 static HRESULT WINAPI
unknode_get_parsed(
1584 VARIANT_BOOL
* isParsed
)
1586 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1587 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
1588 *isParsed
= VARIANT_TRUE
;
1592 static HRESULT WINAPI
unknode_get_namespaceURI(
1596 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1597 TRACE("(%p)->(%p)\n", This
, p
);
1598 return node_get_namespaceURI(&This
->node
, p
);
1601 static HRESULT WINAPI
unknode_get_prefix(
1605 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1606 return node_get_prefix(&This
->node
, p
);
1609 static HRESULT WINAPI
unknode_get_baseName(
1613 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1614 return node_get_base_name(&This
->node
, p
);
1617 static HRESULT WINAPI
unknode_transformNodeToObject(
1619 IXMLDOMNode
* domNode
, VARIANT var1
)
1621 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1622 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
1626 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
1628 unknode_QueryInterface
,
1631 unknode_GetTypeInfoCount
,
1632 unknode_GetTypeInfo
,
1633 unknode_GetIDsOfNames
,
1635 unknode_get_nodeName
,
1636 unknode_get_nodeValue
,
1637 unknode_put_nodeValue
,
1638 unknode_get_nodeType
,
1639 unknode_get_parentNode
,
1640 unknode_get_childNodes
,
1641 unknode_get_firstChild
,
1642 unknode_get_lastChild
,
1643 unknode_get_previousSibling
,
1644 unknode_get_nextSibling
,
1645 unknode_get_attributes
,
1646 unknode_insertBefore
,
1647 unknode_replaceChild
,
1648 unknode_removeChild
,
1649 unknode_appendChild
,
1650 unknode_hasChildNodes
,
1651 unknode_get_ownerDocument
,
1653 unknode_get_nodeTypeString
,
1656 unknode_get_specified
,
1657 unknode_get_definition
,
1658 unknode_get_nodeTypedValue
,
1659 unknode_put_nodeTypedValue
,
1660 unknode_get_dataType
,
1661 unknode_put_dataType
,
1663 unknode_transformNode
,
1664 unknode_selectNodes
,
1665 unknode_selectSingleNode
,
1667 unknode_get_namespaceURI
,
1669 unknode_get_baseName
,
1670 unknode_transformNodeToObject
1673 IXMLDOMNode
*create_node( xmlNodePtr node
)
1682 TRACE("type %d\n", node
->type
);
1685 case XML_ELEMENT_NODE
:
1686 pUnk
= create_element( node
);
1688 case XML_ATTRIBUTE_NODE
:
1689 pUnk
= create_attribute( node
);
1692 pUnk
= create_text( node
);
1694 case XML_CDATA_SECTION_NODE
:
1695 pUnk
= create_cdata( node
);
1697 case XML_ENTITY_REF_NODE
:
1698 pUnk
= create_doc_entity_ref( node
);
1701 pUnk
= create_pi( node
);
1703 case XML_COMMENT_NODE
:
1704 pUnk
= create_comment( node
);
1706 case XML_DOCUMENT_NODE
:
1707 pUnk
= create_domdoc( node
);
1709 case XML_DOCUMENT_FRAG_NODE
:
1710 pUnk
= create_doc_fragment( node
);
1713 pUnk
= create_doc_type( node
);
1718 FIXME("only creating basic node for type %d\n", node
->type
);
1720 new_node
= heap_alloc(sizeof(unknode
));
1724 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
1726 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
1727 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
1731 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
1732 IUnknown_Release(pUnk
);
1733 if(FAILED(hr
)) return NULL
;