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/parserInternals.h>
30 # include <libxml/xmlerror.h>
31 # include <libxml/HTMLtree.h>
32 # ifdef SONAME_LIBXSLT
33 # ifdef HAVE_LIBXSLT_PATTERN_H
34 # include <libxslt/pattern.h>
36 # ifdef HAVE_LIBXSLT_TRANSFORM_H
37 # include <libxslt/transform.h>
39 # include <libxslt/imports.h>
40 # include <libxslt/variables.h>
41 # include <libxslt/xsltutils.h>
42 # include <libxslt/xsltInternals.h>
43 # include <libxslt/documents.h>
54 #include "msxml_private.h"
56 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
63 extern void* libxslt_handle
;
64 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
65 MAKE_FUNCPTR(xsltApplyStylesheet
);
66 MAKE_FUNCPTR(xsltApplyStylesheetUser
);
67 MAKE_FUNCPTR(xsltCleanupGlobals
);
68 MAKE_FUNCPTR(xsltFreeStylesheet
);
69 MAKE_FUNCPTR(xsltFreeTransformContext
);
70 MAKE_FUNCPTR(xsltNewTransformContext
);
71 MAKE_FUNCPTR(xsltNextImport
);
72 MAKE_FUNCPTR(xsltParseStylesheetDoc
);
73 MAKE_FUNCPTR(xsltQuoteUserParams
);
74 MAKE_FUNCPTR(xsltSaveResultTo
);
77 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
80 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
82 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
88 This
= get_node_obj( iface
);
89 if ( !This
|| !This
->node
)
91 if ( type
&& This
->node
->type
!= type
)
96 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
98 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
99 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
104 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
107 /* common ISupportErrorInfo implementation */
109 ISupportErrorInfo ISupportErrorInfo_iface
;
115 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
117 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
120 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
122 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
123 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
127 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
129 ISupportErrorInfo_AddRef(iface
);
133 return E_NOINTERFACE
;
136 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
138 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
139 ULONG ref
= InterlockedIncrement(&This
->ref
);
140 TRACE("(%p)->(%d)\n", This
, ref
);
144 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
146 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
147 LONG ref
= InterlockedDecrement(&This
->ref
);
149 TRACE("(%p)->(%d)\n", This
, ref
);
157 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
159 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
160 enum tid_t
const *tid
;
162 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
165 while (*tid
!= NULL_tid
)
167 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
175 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
176 SupportErrorInfo_QueryInterface
,
177 SupportErrorInfo_AddRef
,
178 SupportErrorInfo_Release
,
179 SupportErrorInfo_InterfaceSupportsErrorInfo
182 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
184 SupportErrorInfo
*This
;
186 This
= heap_alloc(sizeof(*This
));
187 if (!This
) return E_OUTOFMEMORY
;
189 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
193 *obj
= &This
->ISupportErrorInfo_iface
;
198 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
203 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
204 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
205 return SUCCEEDED(hres
) ? obj
: NULL
;
208 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
216 hr
= node_get_base_name(This
, &base
);
217 if (hr
!= S_OK
) return hr
;
219 hr
= node_get_prefix(This
, &prefix
);
222 static const WCHAR colW
= ':';
226 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
227 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
228 ptr
+= SysStringLen(prefix
);
229 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
230 memcpy(ptr
, base
, SysStringByteLen(base
));
233 SysFreeString(prefix
);
241 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
248 content
= xmlNodeGetContent(This
->node
);
249 V_VT(value
) = VT_BSTR
;
250 V_BSTR(value
) = bstr_from_xmlChar( content
);
253 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
257 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
261 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
262 str
= xmlchar_from_wchar(value
);
264 return E_OUTOFMEMORY
;
266 xmlNodeSetContent(This
->node
, str
);
271 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
273 xmlChar
*str
, *escaped
;
275 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
276 str
= xmlchar_from_wchar(value
);
278 return E_OUTOFMEMORY
;
280 escaped
= xmlEncodeSpecialChars(NULL
, str
);
284 return E_OUTOFMEMORY
;
287 xmlNodeSetContent(This
->node
, escaped
);
295 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
299 if (V_VT(value
) != VT_BSTR
)
301 VARIANT string_value
;
303 VariantInit(&string_value
);
304 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
306 WARN("Couldn't convert to VT_BSTR\n");
310 hr
= node_set_content(This
, V_BSTR(&string_value
));
311 VariantClear(&string_value
);
314 hr
= node_set_content(This
, V_BSTR(value
));
319 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
323 if (V_VT(value
) != VT_BSTR
)
325 VARIANT string_value
;
327 VariantInit(&string_value
);
328 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
330 WARN("Couldn't convert to VT_BSTR\n");
334 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
335 VariantClear(&string_value
);
338 hr
= node_set_content_escaped(This
, V_BSTR(value
));
343 static HRESULT
get_node(
349 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
354 /* if we don't have a doc, use our parent. */
355 if(node
&& !node
->doc
&& node
->parent
)
356 node
->doc
= node
->parent
->doc
;
358 *out
= create_node( node
);
364 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
366 return get_node( This
, "parent", This
->node
->parent
, parent
);
369 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
374 *ret
= create_children_nodelist(This
->node
);
376 return E_OUTOFMEMORY
;
381 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
383 return get_node(This
, "firstChild", This
->node
->children
, ret
);
386 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
388 return get_node(This
, "lastChild", This
->node
->last
, ret
);
391 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
393 return get_node(This
, "previous", This
->node
->prev
, ret
);
396 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
398 return get_node(This
, "next", This
->node
->next
, ret
);
401 static int node_get_inst_cnt(xmlNodePtr node
)
403 int ret
= *(LONG
*)&node
->_private
& NODE_PRIV_REFCOUNT_MASK
;
406 /* add attribute counts */
407 if (node
->type
== XML_ELEMENT_NODE
)
409 xmlAttrPtr prop
= node
->properties
;
413 ret
+= node_get_inst_cnt((xmlNodePtr
)prop
);
418 /* add children counts */
419 child
= node
->children
;
422 ret
+= node_get_inst_cnt(child
);
429 int xmlnode_get_inst_cnt(xmlnode
*node
)
431 return node_get_inst_cnt(node
->node
);
434 /* _private field holds a number of COM instances spawned from this libxml2 node
435 * most significant bits are used to store information about ignorable whitespace nodes */
436 void xmlnode_add_ref(xmlNodePtr node
)
438 if (node
->type
== XML_DOCUMENT_NODE
) return;
439 InterlockedIncrement((LONG
*)&node
->_private
);
442 void xmlnode_release(xmlNodePtr node
)
444 if (node
->type
== XML_DOCUMENT_NODE
) return;
445 InterlockedDecrement((LONG
*)&node
->_private
);
448 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
451 IXMLDOMNode
*before
= NULL
;
460 node_obj
= get_node_obj(new_child
);
461 if(!node_obj
) return E_FAIL
;
463 switch(V_VT(ref_child
))
471 if (V_UNKNOWN(ref_child
))
473 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
474 if(FAILED(hr
)) return hr
;
479 FIXME("refChild var type %x\n", V_VT(ref_child
));
483 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
485 if(!node_obj
->node
->parent
)
486 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
487 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
489 refcount
= xmlnode_get_inst_cnt(node_obj
);
493 xmlnode
*before_node_obj
= get_node_obj(before
);
494 IXMLDOMNode_Release(before
);
495 if(!before_node_obj
) return E_FAIL
;
498 /* unlink from current parent first */
501 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
502 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
504 doc
= node_obj
->node
->doc
;
509 xmlnode
*before_node_obj
= get_node_obj(before
);
511 /* refs count including subtree */
512 if (doc
!= before_node_obj
->node
->doc
)
513 refcount
= xmlnode_get_inst_cnt(node_obj
);
515 if (refcount
) xmldoc_add_refs(before_node_obj
->node
->doc
, refcount
);
516 new_node
= xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
517 if (new_node
!= node_obj
->node
)
520 FIXME("referenced xmlNode was freed, expect crashes\n");
521 xmlnode_add_ref(new_node
);
522 node_obj
->node
= new_node
;
524 if (refcount
) xmldoc_release_refs(doc
, refcount
);
525 node_obj
->parent
= This
->parent
;
531 if (doc
!= This
->node
->doc
)
532 refcount
= xmlnode_get_inst_cnt(node_obj
);
534 if (refcount
) xmldoc_add_refs(This
->node
->doc
, refcount
);
535 /* xmlAddChild doesn't unlink node from previous parent */
536 xmlUnlinkNode(node_obj
->node
);
537 new_node
= xmlAddChild(This
->node
, node_obj
->node
);
538 if (new_node
!= node_obj
->node
)
541 FIXME("referenced xmlNode was freed, expect crashes\n");
542 xmlnode_add_ref(new_node
);
543 node_obj
->node
= new_node
;
545 if (refcount
) xmldoc_release_refs(doc
, refcount
);
546 node_obj
->parent
= This
->iface
;
551 IXMLDOMNode_AddRef(new_child
);
559 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
562 xmlnode
*old_child
, *new_child
;
563 xmlDocPtr leaving_doc
;
564 xmlNode
*my_ancestor
;
567 /* Do not believe any documentation telling that newChild == NULL
568 means removal. It does certainly *not* apply to msxml3! */
569 if(!newChild
|| !oldChild
)
575 old_child
= get_node_obj(oldChild
);
576 if(!old_child
) return E_FAIL
;
578 if(old_child
->node
->parent
!= This
->node
)
580 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
584 new_child
= get_node_obj(newChild
);
585 if(!new_child
) return E_FAIL
;
587 my_ancestor
= This
->node
;
590 if(my_ancestor
== new_child
->node
)
592 WARN("tried to create loop\n");
595 my_ancestor
= my_ancestor
->parent
;
598 if(!new_child
->node
->parent
)
599 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
600 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
602 leaving_doc
= new_child
->node
->doc
;
604 if (leaving_doc
!= old_child
->node
->doc
)
605 refcount
= xmlnode_get_inst_cnt(new_child
);
607 if (refcount
) xmldoc_add_refs(old_child
->node
->doc
, refcount
);
608 xmlReplaceNode(old_child
->node
, new_child
->node
);
609 if (refcount
) xmldoc_release_refs(leaving_doc
, refcount
);
610 new_child
->parent
= old_child
->parent
;
611 old_child
->parent
= NULL
;
613 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
617 IXMLDOMNode_AddRef(oldChild
);
624 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
628 if(!child
) return E_INVALIDARG
;
633 child_node
= get_node_obj(child
);
634 if(!child_node
) return E_FAIL
;
636 if(child_node
->node
->parent
!= This
->node
)
638 WARN("childNode %p is not a child of %p\n", child
, This
);
642 xmlUnlinkNode(child_node
->node
);
643 child_node
->parent
= NULL
;
644 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
648 IXMLDOMNode_AddRef(child
);
655 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
664 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
665 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
666 if (outChild
) *outChild
= NULL
;
671 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
674 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
676 if (!ret
) return E_INVALIDARG
;
678 if (!This
->node
->children
)
680 *ret
= VARIANT_FALSE
;
688 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
692 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
695 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
700 if(!cloneNode
) return E_INVALIDARG
;
702 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
705 xmlSetTreeDoc(clone
, This
->node
->doc
);
706 xmldoc_add_orphan(clone
->doc
, clone
);
708 node
= create_node(clone
);
711 ERR("Copy failed\n");
712 xmldoc_remove_orphan(clone
->doc
, clone
);
721 ERR("Copy failed\n");
728 static xmlChar
* do_get_text(xmlNodePtr node
, BOOL trim
, DWORD
*first
, DWORD
*last
, BOOL
*trail_ig_ws
)
732 BOOL preserving
= is_preserving_whitespace(node
);
739 str
= xmlNodeGetContent(node
);
740 *trail_ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
747 str
= xmlStrdup(BAD_CAST
"");
749 if (node
->type
!= XML_DOCUMENT_NODE
)
750 ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
751 *trail_ig_ws
= FALSE
;
753 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
757 case XML_ELEMENT_NODE
: {
758 DWORD node_first
, node_last
;
760 tmp
= do_get_text(child
, FALSE
, &node_first
, &node_last
, trail_ig_ws
);
762 if (node_first
!=-1 && pos
+node_first
<*first
)
763 *first
= pos
+node_first
;
764 if (node_last
&& pos
+node_last
>*last
)
765 *last
= pos
+node_last
;
769 tmp
= xmlNodeGetContent(child
);
770 if (!preserving
&& tmp
[0])
774 for (beg
= tmp
; *beg
; beg
++)
775 if (!isspace(*beg
)) break;
785 case XML_CDATA_SECTION_NODE
:
786 case XML_ENTITY_REF_NODE
:
787 case XML_ENTITY_NODE
:
788 tmp
= xmlNodeGetContent(child
);
795 if ((tmp
&& *tmp
) || child
->type
==XML_CDATA_SECTION_NODE
)
799 str
= xmlStrcat(str
, BAD_CAST
" ");
802 if (tmp
&& *tmp
) str
= xmlStrcat(str
, tmp
);
803 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
<*first
)
805 if (tmp
&& *tmp
) pos
+= xmlStrlen(tmp
);
806 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
>*last
)
810 if (tmp
) xmlFree(tmp
);
814 ig_ws
= *(DWORD
*)&child
->_private
& NODE_PRIV_TRAILING_IGNORABLE_WS
;
817 ig_ws
= *trail_ig_ws
;
818 *trail_ig_ws
= FALSE
;
821 *trail_ig_ws
= ig_ws
;
826 case XML_ELEMENT_NODE
:
828 case XML_ENTITY_REF_NODE
:
829 case XML_ENTITY_NODE
:
830 case XML_DOCUMENT_NODE
:
831 case XML_DOCUMENT_FRAG_NODE
:
832 if (trim
&& !preserving
)
840 for (ret
= str
; *ret
&& isspace(*ret
) && (*first
)--; ret
++)
841 if (*last
) (*last
)--;
842 for (len
= xmlStrlen(ret
)-1; len
>= 0 && len
>= *last
; len
--)
843 if(!isspace(ret
[len
])) break;
845 ret
= xmlStrndup(ret
, len
+1);
858 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
865 if (!text
) return E_INVALIDARG
;
867 content
= do_get_text(This
->node
, TRUE
, &first
, &last
, &tmp
);
870 str
= bstr_from_xmlChar(content
);
874 /* Always return a string. */
875 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
877 TRACE("%p %s\n", This
, debugstr_w(str
) );
883 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
887 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
889 str
= xmlchar_from_wchar(text
);
891 /* Escape the string. */
892 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
895 xmlNodeSetContent(This
->node
, str2
);
901 BSTR
EnsureCorrectEOL(BSTR sInput
)
908 nLen
= SysStringLen(sInput
);
909 /* Count line endings */
910 for(i
=0; i
< nLen
; i
++)
912 if(sInput
[i
] == '\n')
916 TRACE("len=%d, num=%d\n", nLen
, nNum
);
918 /* Add linefeed as needed */
922 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
923 for(i
=0; i
< nLen
; i
++)
925 if(sInput
[i
] == '\n')
927 sNew
[i
+nPlace
] = '\r';
930 sNew
[i
+nPlace
] = sInput
[i
];
933 SysFreeString(sInput
);
940 TRACE("len %d\n", SysStringLen(sNew
));
946 * We are trying to replicate the same behaviour as msxml by converting
947 * line endings to \r\n and using indents as \t. The problem is that msxml
948 * only formats nodes that have a line ending. Using libxml we cannot
949 * reproduce behaviour exactly.
952 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
954 xmlBufferPtr xml_buf
;
963 xml_buf
= xmlBufferCreate();
965 return E_OUTOFMEMORY
;
967 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
969 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
971 const xmlChar
*buf_content
;
974 /* Attribute Nodes return a space in front of their name */
975 buf_content
= xmlBufferContent(xml_buf
);
977 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
979 content
= EnsureCorrectEOL(content
);
983 *ret
= SysAllocStringLen(NULL
, 0);
986 xmlBufferFree(xml_buf
);
987 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
988 return *ret
? S_OK
: E_OUTOFMEMORY
;
991 #ifdef SONAME_LIBXSLT
993 /* duplicates xmlBufferWriteQuotedString() logic */
994 static void xml_write_quotedstring(xmlOutputBufferPtr buf
, const xmlChar
*string
)
996 const xmlChar
*cur
, *base
;
998 if (xmlStrchr(string
, '\"'))
1000 if (xmlStrchr(string
, '\''))
1002 xmlOutputBufferWrite(buf
, 1, "\"");
1003 base
= cur
= string
;
1010 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
1011 xmlOutputBufferWrite(buf
, 6, """);
1019 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
1020 xmlOutputBufferWrite(buf
, 1, "\"");
1024 xmlOutputBufferWrite(buf
, 1, "\'");
1025 xmlOutputBufferWriteString(buf
, (const char*)string
);
1026 xmlOutputBufferWrite(buf
, 1, "\'");
1031 xmlOutputBufferWrite(buf
, 1, "\"");
1032 xmlOutputBufferWriteString(buf
, (const char*)string
);
1033 xmlOutputBufferWrite(buf
, 1, "\"");
1037 static int XMLCALL
transform_to_stream_write(void *context
, const char *buffer
, int len
)
1040 HRESULT hr
= ISequentialStream_Write((ISequentialStream
*)context
, buffer
, len
, &written
);
1041 return hr
== S_OK
? written
: -1;
1044 /* Output for method "text" */
1045 static void transform_write_text(xmlDocPtr result
, xsltStylesheetPtr style
, xmlOutputBufferPtr output
)
1047 xmlNodePtr cur
= result
->children
;
1050 if (cur
->type
== XML_TEXT_NODE
)
1051 xmlOutputBufferWriteString(output
, (const char*)cur
->content
);
1053 /* skip to next node */
1056 if ((cur
->children
->type
!= XML_ENTITY_DECL
) &&
1057 (cur
->children
->type
!= XML_ENTITY_REF_NODE
) &&
1058 (cur
->children
->type
!= XML_ENTITY_NODE
))
1060 cur
= cur
->children
;
1075 if (cur
== (xmlNodePtr
) style
->doc
) {
1087 #undef XSLT_GET_IMPORT_PTR
1088 #define XSLT_GET_IMPORT_PTR(res, style, name) { \
1089 xsltStylesheetPtr st = style; \
1091 while (st != NULL) { \
1092 if (st->name != NULL) { res = st->name; break; } \
1093 st = pxsltNextImport(st); \
1096 #undef XSLT_GET_IMPORT_INT
1097 #define XSLT_GET_IMPORT_INT(res, style, name) { \
1098 xsltStylesheetPtr st = style; \
1100 while (st != NULL) { \
1101 if (st->name != -1) { res = st->name; break; } \
1102 st = pxsltNextImport(st); \
1105 static void transform_write_xmldecl(xmlDocPtr result
, xsltStylesheetPtr style
, BOOL omit_encoding
, xmlOutputBufferPtr output
)
1107 int omit_xmldecl
, standalone
;
1109 XSLT_GET_IMPORT_INT(omit_xmldecl
, style
, omitXmlDeclaration
);
1110 if (omit_xmldecl
== 1) return;
1112 XSLT_GET_IMPORT_INT(standalone
, style
, standalone
);
1114 xmlOutputBufferWriteString(output
, "<?xml version=");
1115 if (result
->version
)
1117 xmlOutputBufferWriteString(output
, "\"");
1118 xmlOutputBufferWriteString(output
, (const char *)result
->version
);
1119 xmlOutputBufferWriteString(output
, "\"");
1122 xmlOutputBufferWriteString(output
, "\"1.0\"");
1126 const xmlChar
*encoding
;
1128 /* default encoding is UTF-16 */
1129 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1130 xmlOutputBufferWriteString(output
, " encoding=");
1131 xmlOutputBufferWriteString(output
, "\"");
1132 xmlOutputBufferWriteString(output
, encoding
? (const char *)encoding
: "UTF-16");
1133 xmlOutputBufferWriteString(output
, "\"");
1136 /* standalone attribute */
1137 if (standalone
!= -1)
1138 xmlOutputBufferWriteString(output
, standalone
== 0 ? " standalone=\"no\"" : " standalone=\"yes\"");
1140 xmlOutputBufferWriteString(output
, "?>");
1143 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
1145 xmlDtdPtr cur
= doc
->intSubset
;
1147 xmlOutputBufferWriteString(buf
, "<!DOCTYPE ");
1148 xmlOutputBufferWriteString(buf
, (const char *)cur
->name
);
1149 if (cur
->ExternalID
)
1151 xmlOutputBufferWriteString(buf
, " PUBLIC ");
1152 xml_write_quotedstring(buf
, cur
->ExternalID
);
1155 xmlOutputBufferWriteString(buf
, " ");
1156 xml_write_quotedstring(buf
, cur
->SystemID
);
1159 else if (cur
->SystemID
)
1161 xmlOutputBufferWriteString(buf
, " SYSTEM ");
1162 xml_write_quotedstring(buf
, cur
->SystemID
);
1164 xmlOutputBufferWriteString(buf
, ">\n");
1167 /* Duplicates htmlDocContentDumpFormatOutput() the way we need it - doesn't add trailing newline. */
1168 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
, const char *encoding
, int format
)
1170 xmlElementType type
;
1172 /* force HTML output */
1174 doc
->type
= XML_HTML_DOCUMENT_NODE
;
1176 htmldtd_dumpcontent(buf
, doc
);
1177 if (doc
->children
) {
1178 xmlNodePtr cur
= doc
->children
;
1180 htmlNodeDumpFormatOutput(buf
, doc
, cur
, encoding
, format
);
1187 static inline BOOL
transform_is_empty_resultdoc(xmlDocPtr result
)
1189 return !result
->children
|| ((result
->children
->type
== XML_DTD_NODE
) && !result
->children
->next
);
1192 static inline BOOL
transform_is_valid_method(xsltStylesheetPtr style
)
1194 return !style
->methodURI
|| !(style
->method
&& xmlStrEqual(style
->method
, (const xmlChar
*)"xhtml"));
1197 /* Helper to write transformation result to specified output buffer. */
1198 static HRESULT
node_transform_write(xsltStylesheetPtr style
, xmlDocPtr result
, BOOL omit_encoding
, const char *encoding
, xmlOutputBufferPtr output
)
1200 const xmlChar
*method
;
1203 if (!transform_is_valid_method(style
))
1205 ERR("unknown output method\n");
1209 XSLT_GET_IMPORT_PTR(method
, style
, method
)
1210 XSLT_GET_IMPORT_INT(indent
, style
, indent
);
1212 if (!method
&& (result
->type
== XML_HTML_DOCUMENT_NODE
))
1213 method
= (const xmlChar
*) "html";
1215 if (method
&& xmlStrEqual(method
, (const xmlChar
*)"html"))
1217 htmlSetMetaEncoding(result
, (const xmlChar
*)encoding
);
1220 htmldoc_dumpcontent(output
, result
, encoding
, indent
);
1222 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"xhtml"))
1224 htmlSetMetaEncoding(result
, (const xmlChar
*) encoding
);
1225 htmlDocContentDumpOutput(output
, result
, encoding
);
1227 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"text"))
1228 transform_write_text(result
, style
, output
);
1231 transform_write_xmldecl(result
, style
, omit_encoding
, output
);
1233 if (result
->children
)
1235 xmlNodePtr child
= result
->children
;
1239 xmlNodeDumpOutput(output
, result
, child
, 0, indent
== 1, encoding
);
1240 if (indent
&& ((child
->type
== XML_DTD_NODE
) || ((child
->type
== XML_COMMENT_NODE
) && child
->next
)))
1241 xmlOutputBufferWriteString(output
, "\r\n");
1242 child
= child
->next
;
1247 xmlOutputBufferFlush(output
);
1251 /* For BSTR output is always UTF-16, without 'encoding' attribute */
1252 static HRESULT
node_transform_write_to_bstr(xsltStylesheetPtr style
, xmlDocPtr result
, BSTR
*str
)
1256 if (transform_is_empty_resultdoc(result
))
1257 *str
= SysAllocStringLen(NULL
, 0);
1260 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(xmlFindCharEncodingHandler("UTF-16"));
1261 const xmlChar
*content
;
1266 return E_OUTOFMEMORY
;
1268 hr
= node_transform_write(style
, result
, TRUE
, "UTF-16", output
);
1269 #ifdef LIBXML2_NEW_BUFFER
1270 content
= xmlBufContent(output
->conv
);
1271 len
= xmlBufUse(output
->conv
);
1273 content
= xmlBufferContent(output
->conv
);
1274 len
= xmlBufferLength(output
->conv
);
1276 /* UTF-16 encoder places UTF-16 bom, we don't need it for BSTR */
1277 content
+= sizeof(WCHAR
);
1278 *str
= SysAllocStringLen((WCHAR
*)content
, len
/sizeof(WCHAR
) - 1);
1279 xmlOutputBufferClose(output
);
1282 return *str
? hr
: E_OUTOFMEMORY
;
1285 static HRESULT
node_transform_write_to_stream(xsltStylesheetPtr style
, xmlDocPtr result
, ISequentialStream
*stream
)
1287 static const xmlChar
*utf16
= (const xmlChar
*)"UTF-16";
1288 xmlOutputBufferPtr output
;
1289 const xmlChar
*encoding
;
1292 if (transform_is_empty_resultdoc(result
))
1294 WARN("empty result document\n");
1298 if (style
->methodURI
&& (!style
->method
|| !xmlStrEqual(style
->method
, (const xmlChar
*) "xhtml")))
1300 ERR("unknown output method\n");
1304 /* default encoding is UTF-16 */
1305 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1309 output
= xmlOutputBufferCreateIO(transform_to_stream_write
, NULL
, stream
, xmlFindCharEncodingHandler((const char*)encoding
));
1311 return E_OUTOFMEMORY
;
1313 hr
= node_transform_write(style
, result
, FALSE
, (const char*)encoding
, output
);
1314 xmlOutputBufferClose(output
);
1318 struct import_buffer
1325 static int XMLCALL
import_loader_io_read(void *context
, char *out
, int len
)
1327 struct import_buffer
*buffer
= (struct import_buffer
*)context
;
1329 TRACE("%p, %p, %d\n", context
, out
, len
);
1331 if (buffer
->cur
== buffer
->len
)
1334 len
= min(len
, buffer
->len
- buffer
->cur
);
1335 memcpy(out
, &buffer
->data
[buffer
->cur
], len
);
1338 TRACE("read %d\n", len
);
1343 static int XMLCALL
import_loader_io_close(void * context
)
1345 struct import_buffer
*buffer
= (struct import_buffer
*)context
;
1347 TRACE("%p\n", context
);
1349 heap_free(buffer
->data
);
1354 static HRESULT
import_loader_onDataAvailable(void *ctxt
, char *ptr
, DWORD len
)
1356 xmlParserInputPtr
*input
= (xmlParserInputPtr
*)ctxt
;
1357 xmlParserInputBufferPtr inputbuffer
;
1358 struct import_buffer
*buffer
;
1360 buffer
= heap_alloc(sizeof(*buffer
));
1362 buffer
->data
= heap_alloc(len
);
1363 memcpy(buffer
->data
, ptr
, len
);
1367 inputbuffer
= xmlParserInputBufferCreateIO(import_loader_io_read
, import_loader_io_close
, buffer
,
1368 XML_CHAR_ENCODING_NONE
);
1369 *input
= xmlNewIOInputStream(ctxt
, inputbuffer
, XML_CHAR_ENCODING_NONE
);
1371 xmlFreeParserInputBuffer(inputbuffer
);
1373 return *input
? S_OK
: E_FAIL
;
1376 static HRESULT
xslt_doc_get_uri(const xmlChar
*uri
, void *_ctxt
, xsltLoadType type
, IUri
**doc_uri
)
1378 xsltStylesheetPtr style
= (xsltStylesheetPtr
)_ctxt
;
1385 uriW
= bstr_from_xmlChar(uri
);
1386 hr
= CreateUri(uriW
, Uri_CREATE_ALLOW_RELATIVE
| Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &href_uri
);
1387 SysFreeString(uriW
);
1390 WARN("Failed to create href uri, %#x.\n", hr
);
1394 if (type
== XSLT_LOAD_STYLESHEET
&& style
->doc
&& style
->doc
->name
)
1399 baseuriW
= bstr_from_xmlChar((xmlChar
*)style
->doc
->name
);
1400 hr
= CreateUri(baseuriW
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &base_uri
);
1401 SysFreeString(baseuriW
);
1404 WARN("Failed to create base uri, %#x.\n", hr
);
1408 hr
= CoInternetCombineIUri(base_uri
, href_uri
, 0, doc_uri
, 0);
1409 IUri_Release(base_uri
);
1411 WARN("Failed to combine uris, %#x.\n", hr
);
1415 *doc_uri
= href_uri
;
1416 IUri_AddRef(*doc_uri
);
1419 IUri_Release(href_uri
);
1424 xmlDocPtr
xslt_doc_default_loader(const xmlChar
*uri
, xmlDictPtr dict
, int options
,
1425 void *_ctxt
, xsltLoadType type
)
1427 IUri
*import_uri
= NULL
;
1428 xmlParserInputPtr input
;
1429 xmlParserCtxtPtr pctxt
;
1430 xmlDocPtr doc
= NULL
;
1436 TRACE("%s, %p, %#x, %p, %d\n", debugstr_a((const char *)uri
), dict
, options
, _ctxt
, type
);
1438 pctxt
= xmlNewParserCtxt();
1442 if (dict
&& pctxt
->dict
)
1444 xmlDictFree(pctxt
->dict
);
1451 xmlDictReference(pctxt
->dict
);
1454 xmlCtxtUseOptions(pctxt
, options
);
1456 hr
= xslt_doc_get_uri(uri
, _ctxt
, type
, &import_uri
);
1460 hr
= CreateURLMonikerEx2(NULL
, import_uri
, &moniker
, 0);
1464 hr
= bind_url(moniker
, import_loader_onDataAvailable
, &input
, &bsc
);
1465 IMoniker_Release(moniker
);
1469 if (FAILED(detach_bsc(bsc
)))
1475 inputPush(pctxt
, input
);
1476 xmlParseDocument(pctxt
);
1478 if (pctxt
->wellFormed
)
1481 /* Set imported uri, to give nested imports a chance. */
1482 if (IUri_GetPropertyBSTR(import_uri
, Uri_PROPERTY_ABSOLUTE_URI
, &uriW
, 0) == S_OK
)
1484 doc
->name
= (char *)xmlchar_from_wcharn(uriW
, SysStringLen(uriW
), TRUE
);
1485 SysFreeString(uriW
);
1491 xmlFreeDoc(pctxt
->myDoc
);
1492 pctxt
->myDoc
= NULL
;
1496 xmlFreeParserCtxt(pctxt
);
1498 IUri_Release(import_uri
);
1503 #endif /* SONAME_LIBXSLT */
1505 HRESULT
node_transform_node_params(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
,
1506 ISequentialStream
*stream
, const struct xslprocessor_params
*params
)
1508 #ifdef SONAME_LIBXSLT
1509 xsltStylesheetPtr xsltSS
;
1510 xmlDocPtr sheet_doc
;
1514 if (!libxslt_handle
) return E_NOTIMPL
;
1515 if (!stylesheet
|| (!p
&& !stream
)) return E_INVALIDARG
;
1519 sheet
= get_node_obj(stylesheet
);
1520 if(!sheet
) return E_FAIL
;
1522 sheet_doc
= xmlCopyDoc(sheet
->node
->doc
, 1);
1523 xsltSS
= pxsltParseStylesheetDoc(sheet_doc
);
1526 const char **xslparams
= NULL
;
1530 /* convert our parameter list to libxml2 format */
1531 if (params
&& params
->count
)
1533 struct xslprocessor_par
*par
;
1536 xslparams
= heap_alloc((params
->count
*2 + 1)*sizeof(char*));
1537 LIST_FOR_EACH_ENTRY(par
, ¶ms
->list
, struct xslprocessor_par
, entry
)
1539 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->name
);
1540 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->value
);
1542 xslparams
[i
] = NULL
;
1547 xsltTransformContextPtr ctxt
= pxsltNewTransformContext(xsltSS
, This
->node
->doc
);
1549 /* push parameters to user context */
1550 pxsltQuoteUserParams(ctxt
, xslparams
);
1551 result
= pxsltApplyStylesheetUser(xsltSS
, This
->node
->doc
, NULL
, NULL
, NULL
, ctxt
);
1552 pxsltFreeTransformContext(ctxt
);
1554 for (i
= 0; i
< params
->count
*2; i
++)
1555 heap_free((char*)xslparams
[i
]);
1556 heap_free(xslparams
);
1559 result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1564 hr
= node_transform_write_to_stream(xsltSS
, result
, stream
);
1566 hr
= node_transform_write_to_bstr(xsltSS
, result
, p
);
1570 pxsltFreeStylesheet(xsltSS
);
1573 xmlFreeDoc(sheet_doc
);
1575 if (p
&& !*p
) *p
= SysAllocStringLen(NULL
, 0);
1579 ERR_(winediag
)("libxslt headers were not found at compile time. Expect problems.\n");
1585 HRESULT
node_transform_node(const xmlnode
*node
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
1587 return node_transform_node_params(node
, stylesheet
, p
, NULL
, NULL
);
1590 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1595 if (!query
|| !nodes
) return E_INVALIDARG
;
1597 str
= xmlchar_from_wchar(query
);
1598 hr
= create_selection(This
->node
, str
, nodes
);
1604 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1606 IXMLDOMNodeList
*list
;
1609 hr
= node_select_nodes(This
, query
, &list
);
1612 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1613 IXMLDOMNodeList_Release(list
);
1618 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1620 xmlNsPtr ns
= This
->node
->ns
;
1623 return E_INVALIDARG
;
1625 *namespaceURI
= NULL
;
1628 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1630 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1632 return *namespaceURI
? S_OK
: S_FALSE
;
1635 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1637 xmlNsPtr ns
= This
->node
->ns
;
1639 if (!prefix
) return E_INVALIDARG
;
1643 if (ns
&& ns
->prefix
)
1644 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1646 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1648 return *prefix
? S_OK
: S_FALSE
;
1651 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1653 if (!name
) return E_INVALIDARG
;
1655 *name
= bstr_from_xmlChar(This
->node
->name
);
1656 if (!*name
) return E_OUTOFMEMORY
;
1658 TRACE("returning %s\n", debugstr_w(*name
));
1663 void destroy_xmlnode(xmlnode
*This
)
1667 xmlnode_release(This
->node
);
1668 xmldoc_release(This
->node
->doc
);
1672 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1676 xmlnode_add_ref(node
);
1677 xmldoc_add_ref(node
->doc
);
1681 This
->iface
= node_iface
;
1682 This
->parent
= NULL
;
1684 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1689 IXMLDOMNode IXMLDOMNode_iface
;
1693 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1695 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1698 static HRESULT WINAPI
unknode_QueryInterface(
1703 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1705 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1707 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1709 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1710 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1711 *ppvObject
= &This
->IXMLDOMNode_iface
;
1712 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1713 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1715 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1717 return E_NOINTERFACE
;
1720 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1724 static ULONG WINAPI
unknode_AddRef(
1725 IXMLDOMNode
*iface
)
1727 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1729 return InterlockedIncrement(&This
->ref
);
1732 static ULONG WINAPI
unknode_Release(
1733 IXMLDOMNode
*iface
)
1735 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1738 ref
= InterlockedDecrement( &This
->ref
);
1740 destroy_xmlnode(&This
->node
);
1747 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1751 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1753 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1760 static HRESULT WINAPI
unknode_GetTypeInfo(
1764 ITypeInfo
** ppTInfo
)
1766 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1769 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1771 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1776 static HRESULT WINAPI
unknode_GetIDsOfNames(
1779 LPOLESTR
* rgszNames
,
1784 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1786 ITypeInfo
*typeinfo
;
1789 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1792 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1793 return E_INVALIDARG
;
1795 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1798 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1799 ITypeInfo_Release(typeinfo
);
1805 static HRESULT WINAPI
unknode_Invoke(
1807 DISPID dispIdMember
,
1811 DISPPARAMS
* pDispParams
,
1812 VARIANT
* pVarResult
,
1813 EXCEPINFO
* pExcepInfo
,
1816 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1817 ITypeInfo
*typeinfo
;
1820 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1821 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1823 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1826 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1827 pVarResult
, pExcepInfo
, puArgErr
);
1828 ITypeInfo_Release(typeinfo
);
1834 static HRESULT WINAPI
unknode_get_nodeName(
1838 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1840 FIXME("(%p)->(%p)\n", This
, p
);
1842 return node_get_nodeName(&This
->node
, p
);
1845 static HRESULT WINAPI
unknode_get_nodeValue(
1849 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1851 FIXME("(%p)->(%p)\n", This
, value
);
1854 return E_INVALIDARG
;
1856 V_VT(value
) = VT_NULL
;
1860 static HRESULT WINAPI
unknode_put_nodeValue(
1864 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1865 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1869 static HRESULT WINAPI
unknode_get_nodeType(
1871 DOMNodeType
* domNodeType
)
1873 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1875 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1877 switch (This
->node
.node
->type
)
1879 case XML_ELEMENT_NODE
:
1880 case XML_ATTRIBUTE_NODE
:
1882 case XML_CDATA_SECTION_NODE
:
1883 case XML_ENTITY_REF_NODE
:
1884 case XML_ENTITY_NODE
:
1886 case XML_COMMENT_NODE
:
1887 case XML_DOCUMENT_NODE
:
1888 case XML_DOCUMENT_TYPE_NODE
:
1889 case XML_DOCUMENT_FRAG_NODE
:
1890 case XML_NOTATION_NODE
:
1891 /* we only care about this set of types, libxml2 type values are
1892 exactly what we need */
1893 *domNodeType
= (DOMNodeType
)This
->node
.node
->type
;
1896 *domNodeType
= NODE_INVALID
;
1903 static HRESULT WINAPI
unknode_get_parentNode(
1905 IXMLDOMNode
** parent
)
1907 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1908 FIXME("(%p)->(%p)\n", This
, parent
);
1909 if (!parent
) return E_INVALIDARG
;
1914 static HRESULT WINAPI
unknode_get_childNodes(
1916 IXMLDOMNodeList
** outList
)
1918 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1920 TRACE("(%p)->(%p)\n", This
, outList
);
1922 return node_get_child_nodes(&This
->node
, outList
);
1925 static HRESULT WINAPI
unknode_get_firstChild(
1927 IXMLDOMNode
** domNode
)
1929 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1931 TRACE("(%p)->(%p)\n", This
, domNode
);
1933 return node_get_first_child(&This
->node
, domNode
);
1936 static HRESULT WINAPI
unknode_get_lastChild(
1938 IXMLDOMNode
** domNode
)
1940 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1942 TRACE("(%p)->(%p)\n", This
, domNode
);
1944 return node_get_last_child(&This
->node
, domNode
);
1947 static HRESULT WINAPI
unknode_get_previousSibling(
1949 IXMLDOMNode
** domNode
)
1951 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1953 TRACE("(%p)->(%p)\n", This
, domNode
);
1955 return node_get_previous_sibling(&This
->node
, domNode
);
1958 static HRESULT WINAPI
unknode_get_nextSibling(
1960 IXMLDOMNode
** domNode
)
1962 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1964 TRACE("(%p)->(%p)\n", This
, domNode
);
1966 return node_get_next_sibling(&This
->node
, domNode
);
1969 static HRESULT WINAPI
unknode_get_attributes(
1971 IXMLDOMNamedNodeMap
** attributeMap
)
1973 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1975 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1977 return return_null_ptr((void**)attributeMap
);
1980 static HRESULT WINAPI
unknode_insertBefore(
1982 IXMLDOMNode
* newNode
, VARIANT refChild
,
1983 IXMLDOMNode
** outOldNode
)
1985 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1987 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1989 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1992 static HRESULT WINAPI
unknode_replaceChild(
1994 IXMLDOMNode
* newNode
,
1995 IXMLDOMNode
* oldNode
,
1996 IXMLDOMNode
** outOldNode
)
1998 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2000 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
2002 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
2005 static HRESULT WINAPI
unknode_removeChild(
2007 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
2009 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2010 return node_remove_child(&This
->node
, domNode
, oldNode
);
2013 static HRESULT WINAPI
unknode_appendChild(
2015 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
2017 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2018 return node_append_child(&This
->node
, newNode
, outNewNode
);
2021 static HRESULT WINAPI
unknode_hasChildNodes(
2023 VARIANT_BOOL
* pbool
)
2025 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2026 return node_has_childnodes(&This
->node
, pbool
);
2029 static HRESULT WINAPI
unknode_get_ownerDocument(
2031 IXMLDOMDocument
** domDocument
)
2033 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2034 return node_get_owner_doc(&This
->node
, domDocument
);
2037 static HRESULT WINAPI
unknode_cloneNode(
2039 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
2041 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2042 return node_clone(&This
->node
, pbool
, outNode
);
2045 static HRESULT WINAPI
unknode_get_nodeTypeString(
2049 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2051 FIXME("(%p)->(%p)\n", This
, p
);
2053 return node_get_nodeName(&This
->node
, p
);
2056 static HRESULT WINAPI
unknode_get_text(
2060 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2061 return node_get_text(&This
->node
, p
);
2064 static HRESULT WINAPI
unknode_put_text(
2068 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2069 return node_put_text(&This
->node
, p
);
2072 static HRESULT WINAPI
unknode_get_specified(
2074 VARIANT_BOOL
* isSpecified
)
2076 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2077 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
2078 *isSpecified
= VARIANT_TRUE
;
2082 static HRESULT WINAPI
unknode_get_definition(
2084 IXMLDOMNode
** definitionNode
)
2086 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2087 FIXME("(%p)->(%p)\n", This
, definitionNode
);
2091 static HRESULT WINAPI
unknode_get_nodeTypedValue(
2095 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2096 FIXME("(%p)->(%p)\n", This
, var1
);
2097 return return_null_var(var1
);
2100 static HRESULT WINAPI
unknode_put_nodeTypedValue(
2104 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2105 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
2109 static HRESULT WINAPI
unknode_get_dataType(
2113 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2114 TRACE("(%p)->(%p)\n", This
, var1
);
2115 return return_null_var(var1
);
2118 static HRESULT WINAPI
unknode_put_dataType(
2122 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2124 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
2127 return E_INVALIDARG
;
2132 static HRESULT WINAPI
unknode_get_xml(
2136 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2138 FIXME("(%p)->(%p)\n", This
, p
);
2140 return node_get_xml(&This
->node
, FALSE
, p
);
2143 static HRESULT WINAPI
unknode_transformNode(
2145 IXMLDOMNode
* domNode
, BSTR
* p
)
2147 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2148 return node_transform_node(&This
->node
, domNode
, p
);
2151 static HRESULT WINAPI
unknode_selectNodes(
2153 BSTR p
, IXMLDOMNodeList
** outList
)
2155 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2156 return node_select_nodes(&This
->node
, p
, outList
);
2159 static HRESULT WINAPI
unknode_selectSingleNode(
2161 BSTR p
, IXMLDOMNode
** outNode
)
2163 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2164 return node_select_singlenode(&This
->node
, p
, outNode
);
2167 static HRESULT WINAPI
unknode_get_parsed(
2169 VARIANT_BOOL
* isParsed
)
2171 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2172 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
2173 *isParsed
= VARIANT_TRUE
;
2177 static HRESULT WINAPI
unknode_get_namespaceURI(
2181 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2182 TRACE("(%p)->(%p)\n", This
, p
);
2183 return node_get_namespaceURI(&This
->node
, p
);
2186 static HRESULT WINAPI
unknode_get_prefix(
2190 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2191 return node_get_prefix(&This
->node
, p
);
2194 static HRESULT WINAPI
unknode_get_baseName(
2198 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2199 return node_get_base_name(&This
->node
, p
);
2202 static HRESULT WINAPI
unknode_transformNodeToObject(
2204 IXMLDOMNode
* domNode
, VARIANT var1
)
2206 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2207 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
2211 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
2213 unknode_QueryInterface
,
2216 unknode_GetTypeInfoCount
,
2217 unknode_GetTypeInfo
,
2218 unknode_GetIDsOfNames
,
2220 unknode_get_nodeName
,
2221 unknode_get_nodeValue
,
2222 unknode_put_nodeValue
,
2223 unknode_get_nodeType
,
2224 unknode_get_parentNode
,
2225 unknode_get_childNodes
,
2226 unknode_get_firstChild
,
2227 unknode_get_lastChild
,
2228 unknode_get_previousSibling
,
2229 unknode_get_nextSibling
,
2230 unknode_get_attributes
,
2231 unknode_insertBefore
,
2232 unknode_replaceChild
,
2233 unknode_removeChild
,
2234 unknode_appendChild
,
2235 unknode_hasChildNodes
,
2236 unknode_get_ownerDocument
,
2238 unknode_get_nodeTypeString
,
2241 unknode_get_specified
,
2242 unknode_get_definition
,
2243 unknode_get_nodeTypedValue
,
2244 unknode_put_nodeTypedValue
,
2245 unknode_get_dataType
,
2246 unknode_put_dataType
,
2248 unknode_transformNode
,
2249 unknode_selectNodes
,
2250 unknode_selectSingleNode
,
2252 unknode_get_namespaceURI
,
2254 unknode_get_baseName
,
2255 unknode_transformNodeToObject
2258 IXMLDOMNode
*create_node( xmlNodePtr node
)
2267 TRACE("type %d\n", node
->type
);
2270 case XML_ELEMENT_NODE
:
2271 pUnk
= create_element( node
);
2273 case XML_ATTRIBUTE_NODE
:
2274 pUnk
= create_attribute( node
, FALSE
);
2277 pUnk
= create_text( node
);
2279 case XML_CDATA_SECTION_NODE
:
2280 pUnk
= create_cdata( node
);
2282 case XML_ENTITY_REF_NODE
:
2283 pUnk
= create_doc_entity_ref( node
);
2286 pUnk
= create_pi( node
);
2288 case XML_COMMENT_NODE
:
2289 pUnk
= create_comment( node
);
2291 case XML_DOCUMENT_NODE
:
2292 pUnk
= create_domdoc( node
);
2294 case XML_DOCUMENT_FRAG_NODE
:
2295 pUnk
= create_doc_fragment( node
);
2298 case XML_DOCUMENT_TYPE_NODE
:
2299 pUnk
= create_doc_type( node
);
2301 case XML_ENTITY_NODE
:
2302 case XML_NOTATION_NODE
: {
2305 FIXME("only creating basic node for type %d\n", node
->type
);
2307 new_node
= heap_alloc(sizeof(unknode
));
2311 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
2313 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
2314 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
2318 ERR("Called for unsupported node type %d\n", node
->type
);
2322 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
2323 IUnknown_Release(pUnk
);
2324 if(FAILED(hr
)) return NULL
;