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/imports.h>
39 # include <libxslt/variables.h>
40 # include <libxslt/xsltutils.h>
41 # include <libxslt/xsltInternals.h>
52 #include "msxml_private.h"
54 #include "wine/debug.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
61 extern void* libxslt_handle
;
62 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
63 MAKE_FUNCPTR(xsltApplyStylesheet
);
64 MAKE_FUNCPTR(xsltApplyStylesheetUser
);
65 MAKE_FUNCPTR(xsltCleanupGlobals
);
66 MAKE_FUNCPTR(xsltFreeStylesheet
);
67 MAKE_FUNCPTR(xsltFreeTransformContext
);
68 MAKE_FUNCPTR(xsltNewTransformContext
);
69 MAKE_FUNCPTR(xsltNextImport
);
70 MAKE_FUNCPTR(xsltParseStylesheetDoc
);
71 MAKE_FUNCPTR(xsltQuoteUserParams
);
72 MAKE_FUNCPTR(xsltSaveResultTo
);
75 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
78 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
80 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
86 This
= get_node_obj( iface
);
87 if ( !This
|| !This
->node
)
89 if ( type
&& This
->node
->type
!= type
)
94 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
96 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
97 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
102 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
105 /* common ISupportErrorInfo implementation */
107 ISupportErrorInfo ISupportErrorInfo_iface
;
113 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
115 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
118 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
120 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
121 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
125 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
127 ISupportErrorInfo_AddRef(iface
);
131 return E_NOINTERFACE
;
134 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
136 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
137 ULONG ref
= InterlockedIncrement(&This
->ref
);
138 TRACE("(%p)->(%d)\n", This
, ref
);
142 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
144 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
145 LONG ref
= InterlockedDecrement(&This
->ref
);
147 TRACE("(%p)->(%d)\n", This
, ref
);
155 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
157 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
158 enum tid_t
const *tid
;
160 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
163 while (*tid
!= NULL_tid
)
165 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
173 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
174 SupportErrorInfo_QueryInterface
,
175 SupportErrorInfo_AddRef
,
176 SupportErrorInfo_Release
,
177 SupportErrorInfo_InterfaceSupportsErrorInfo
180 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
182 SupportErrorInfo
*This
;
184 This
= heap_alloc(sizeof(*This
));
185 if (!This
) return E_OUTOFMEMORY
;
187 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
191 *obj
= &This
->ISupportErrorInfo_iface
;
196 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
201 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
202 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
203 return SUCCEEDED(hres
) ? obj
: NULL
;
206 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
214 hr
= node_get_base_name(This
, &base
);
215 if (hr
!= S_OK
) return hr
;
217 hr
= node_get_prefix(This
, &prefix
);
220 static const WCHAR colW
= ':';
224 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
225 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
226 ptr
+= SysStringLen(prefix
);
227 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
228 memcpy(ptr
, base
, SysStringByteLen(base
));
231 SysFreeString(prefix
);
239 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
246 content
= xmlNodeGetContent(This
->node
);
247 V_VT(value
) = VT_BSTR
;
248 V_BSTR(value
) = bstr_from_xmlChar( content
);
251 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
255 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
259 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
260 str
= xmlchar_from_wchar(value
);
262 return E_OUTOFMEMORY
;
264 xmlNodeSetContent(This
->node
, str
);
269 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
271 xmlChar
*str
, *escaped
;
273 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
274 str
= xmlchar_from_wchar(value
);
276 return E_OUTOFMEMORY
;
278 escaped
= xmlEncodeSpecialChars(NULL
, str
);
282 return E_OUTOFMEMORY
;
285 xmlNodeSetContent(This
->node
, escaped
);
293 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
297 if (V_VT(value
) != VT_BSTR
)
299 VARIANT string_value
;
301 VariantInit(&string_value
);
302 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
304 WARN("Couldn't convert to VT_BSTR\n");
308 hr
= node_set_content(This
, V_BSTR(&string_value
));
309 VariantClear(&string_value
);
312 hr
= node_set_content(This
, V_BSTR(value
));
317 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
321 if (V_VT(value
) != VT_BSTR
)
323 VARIANT string_value
;
325 VariantInit(&string_value
);
326 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
328 WARN("Couldn't convert to VT_BSTR\n");
332 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
333 VariantClear(&string_value
);
336 hr
= node_set_content_escaped(This
, V_BSTR(value
));
341 static HRESULT
get_node(
347 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
352 /* if we don't have a doc, use our parent. */
353 if(node
&& !node
->doc
&& node
->parent
)
354 node
->doc
= node
->parent
->doc
;
356 *out
= create_node( node
);
362 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
364 return get_node( This
, "parent", This
->node
->parent
, parent
);
367 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
372 *ret
= create_children_nodelist(This
->node
);
374 return E_OUTOFMEMORY
;
379 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
381 return get_node(This
, "firstChild", This
->node
->children
, ret
);
384 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
386 return get_node(This
, "lastChild", This
->node
->last
, ret
);
389 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
391 return get_node(This
, "previous", This
->node
->prev
, ret
);
394 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
396 return get_node(This
, "next", This
->node
->next
, ret
);
399 static int node_get_inst_cnt(xmlNodePtr node
)
401 int ret
= *(LONG
*)&node
->_private
& NODE_PRIV_REFCOUNT_MASK
;
404 /* add attribute counts */
405 if (node
->type
== XML_ELEMENT_NODE
)
407 xmlAttrPtr prop
= node
->properties
;
411 ret
+= node_get_inst_cnt((xmlNodePtr
)prop
);
416 /* add children counts */
417 child
= node
->children
;
420 ret
+= node_get_inst_cnt(child
);
427 int xmlnode_get_inst_cnt(xmlnode
*node
)
429 return node_get_inst_cnt(node
->node
);
432 /* _private field holds a number of COM instances spawned from this libxml2 node
433 * most significant bits are used to store information about ignorrable whitespace nodes */
434 void xmlnode_add_ref(xmlNodePtr node
)
436 if (node
->type
== XML_DOCUMENT_NODE
) return;
437 InterlockedIncrement((LONG
*)&node
->_private
);
440 void xmlnode_release(xmlNodePtr node
)
442 if (node
->type
== XML_DOCUMENT_NODE
) return;
443 InterlockedDecrement((LONG
*)&node
->_private
);
446 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
449 IXMLDOMNode
*before
= NULL
;
458 node_obj
= get_node_obj(new_child
);
459 if(!node_obj
) return E_FAIL
;
461 switch(V_VT(ref_child
))
469 if (V_UNKNOWN(ref_child
))
471 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
472 if(FAILED(hr
)) return hr
;
477 FIXME("refChild var type %x\n", V_VT(ref_child
));
481 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
483 if(!node_obj
->node
->parent
)
484 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
485 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
487 refcount
= xmlnode_get_inst_cnt(node_obj
);
491 xmlnode
*before_node_obj
= get_node_obj(before
);
492 IXMLDOMNode_Release(before
);
493 if(!before_node_obj
) return E_FAIL
;
496 /* unlink from current parent first */
499 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
500 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
502 doc
= node_obj
->node
->doc
;
507 xmlnode
*before_node_obj
= get_node_obj(before
);
509 /* refs count including subtree */
510 if (doc
!= before_node_obj
->node
->doc
)
511 refcount
= xmlnode_get_inst_cnt(node_obj
);
513 if (refcount
) xmldoc_add_refs(before_node_obj
->node
->doc
, refcount
);
514 new_node
= xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
515 if (new_node
!= node_obj
->node
)
518 FIXME("referenced xmlNode was freed, expect crashes\n");
519 xmlnode_add_ref(new_node
);
520 node_obj
->node
= new_node
;
522 if (refcount
) xmldoc_release_refs(doc
, refcount
);
523 node_obj
->parent
= This
->parent
;
529 if (doc
!= This
->node
->doc
)
530 refcount
= xmlnode_get_inst_cnt(node_obj
);
532 if (refcount
) xmldoc_add_refs(This
->node
->doc
, refcount
);
533 /* xmlAddChild doesn't unlink node from previous parent */
534 xmlUnlinkNode(node_obj
->node
);
535 new_node
= xmlAddChild(This
->node
, node_obj
->node
);
536 if (new_node
!= node_obj
->node
)
539 FIXME("referenced xmlNode was freed, expect crashes\n");
540 xmlnode_add_ref(new_node
);
541 node_obj
->node
= new_node
;
543 if (refcount
) xmldoc_release_refs(doc
, refcount
);
544 node_obj
->parent
= This
->iface
;
549 IXMLDOMNode_AddRef(new_child
);
557 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
560 xmlnode
*old_child
, *new_child
;
561 xmlDocPtr leaving_doc
;
562 xmlNode
*my_ancestor
;
565 /* Do not believe any documentation telling that newChild == NULL
566 means removal. It does certainly *not* apply to msxml3! */
567 if(!newChild
|| !oldChild
)
573 old_child
= get_node_obj(oldChild
);
574 if(!old_child
) return E_FAIL
;
576 if(old_child
->node
->parent
!= This
->node
)
578 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
582 new_child
= get_node_obj(newChild
);
583 if(!new_child
) return E_FAIL
;
585 my_ancestor
= This
->node
;
588 if(my_ancestor
== new_child
->node
)
590 WARN("tried to create loop\n");
593 my_ancestor
= my_ancestor
->parent
;
596 if(!new_child
->node
->parent
)
597 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
598 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
600 leaving_doc
= new_child
->node
->doc
;
602 if (leaving_doc
!= old_child
->node
->doc
)
603 refcount
= xmlnode_get_inst_cnt(new_child
);
605 if (refcount
) xmldoc_add_refs(old_child
->node
->doc
, refcount
);
606 xmlReplaceNode(old_child
->node
, new_child
->node
);
607 if (refcount
) xmldoc_release_refs(leaving_doc
, refcount
);
608 new_child
->parent
= old_child
->parent
;
609 old_child
->parent
= NULL
;
611 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
615 IXMLDOMNode_AddRef(oldChild
);
622 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
626 if(!child
) return E_INVALIDARG
;
631 child_node
= get_node_obj(child
);
632 if(!child_node
) return E_FAIL
;
634 if(child_node
->node
->parent
!= This
->node
)
636 WARN("childNode %p is not a child of %p\n", child
, This
);
640 xmlUnlinkNode(child_node
->node
);
641 child_node
->parent
= NULL
;
642 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
646 IXMLDOMNode_AddRef(child
);
653 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
662 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
663 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
664 if (outChild
) *outChild
= NULL
;
669 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
672 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
674 if (!ret
) return E_INVALIDARG
;
676 if (!This
->node
->children
)
678 *ret
= VARIANT_FALSE
;
686 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
690 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
693 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
698 if(!cloneNode
) return E_INVALIDARG
;
700 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
703 xmlSetTreeDoc(clone
, This
->node
->doc
);
704 xmldoc_add_orphan(clone
->doc
, clone
);
706 node
= create_node(clone
);
709 ERR("Copy failed\n");
710 xmldoc_remove_orphan(clone
->doc
, clone
);
719 ERR("Copy failed\n");
726 static xmlChar
* do_get_text(xmlNodePtr node
, BOOL trim
, DWORD
*first
, DWORD
*last
, BOOL
*trail_ig_ws
)
730 BOOL preserving
= is_preserving_whitespace(node
);
737 str
= xmlNodeGetContent(node
);
738 *trail_ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
745 str
= xmlStrdup(BAD_CAST
"");
747 if (node
->type
!= XML_DOCUMENT_NODE
)
748 ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
749 *trail_ig_ws
= FALSE
;
751 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
755 case XML_ELEMENT_NODE
: {
756 DWORD node_first
, node_last
;
758 tmp
= do_get_text(child
, FALSE
, &node_first
, &node_last
, trail_ig_ws
);
760 if (node_first
!=-1 && pos
+node_first
<*first
)
761 *first
= pos
+node_first
;
762 if (node_last
&& pos
+node_last
>*last
)
763 *last
= pos
+node_last
;
767 tmp
= xmlNodeGetContent(child
);
768 if (!preserving
&& tmp
[0])
772 for (beg
= tmp
; *beg
; beg
++)
773 if (!isspace(*beg
)) break;
783 case XML_CDATA_SECTION_NODE
:
784 case XML_ENTITY_REF_NODE
:
785 case XML_ENTITY_NODE
:
786 tmp
= xmlNodeGetContent(child
);
793 if ((tmp
&& *tmp
) || child
->type
==XML_CDATA_SECTION_NODE
)
797 str
= xmlStrcat(str
, BAD_CAST
" ");
800 if (tmp
&& *tmp
) str
= xmlStrcat(str
, tmp
);
801 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
<*first
)
803 if (tmp
&& *tmp
) pos
+= xmlStrlen(tmp
);
804 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
>*last
)
808 if (tmp
) xmlFree(tmp
);
812 ig_ws
= *(DWORD
*)&child
->_private
& NODE_PRIV_TRAILING_IGNORABLE_WS
;
815 ig_ws
= *trail_ig_ws
;
816 *trail_ig_ws
= FALSE
;
819 *trail_ig_ws
= ig_ws
;
824 case XML_ELEMENT_NODE
:
826 case XML_ENTITY_REF_NODE
:
827 case XML_ENTITY_NODE
:
828 case XML_DOCUMENT_NODE
:
829 case XML_DOCUMENT_FRAG_NODE
:
830 if (trim
&& !preserving
)
838 for (ret
= str
; *ret
&& isspace(*ret
) && (*first
)--; ret
++)
839 if (*last
) (*last
)--;
840 for (len
= xmlStrlen(ret
)-1; len
>= 0 && len
>= *last
; len
--)
841 if(!isspace(ret
[len
])) break;
843 ret
= xmlStrndup(ret
, len
+1);
856 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
863 if (!text
) return E_INVALIDARG
;
865 content
= do_get_text(This
->node
, TRUE
, &first
, &last
, &tmp
);
868 str
= bstr_from_xmlChar(content
);
872 /* Always return a string. */
873 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
875 TRACE("%p %s\n", This
, debugstr_w(str
) );
881 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
885 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
887 str
= xmlchar_from_wchar(text
);
889 /* Escape the string. */
890 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
893 xmlNodeSetContent(This
->node
, str2
);
899 BSTR
EnsureCorrectEOL(BSTR sInput
)
906 nLen
= SysStringLen(sInput
);
907 /* Count line endings */
908 for(i
=0; i
< nLen
; i
++)
910 if(sInput
[i
] == '\n')
914 TRACE("len=%d, num=%d\n", nLen
, nNum
);
916 /* Add linefeed as needed */
920 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
921 for(i
=0; i
< nLen
; i
++)
923 if(sInput
[i
] == '\n')
925 sNew
[i
+nPlace
] = '\r';
928 sNew
[i
+nPlace
] = sInput
[i
];
931 SysFreeString(sInput
);
938 TRACE("len %d\n", SysStringLen(sNew
));
944 * We are trying to replicate the same behaviour as msxml by converting
945 * line endings to \r\n and using indents as \t. The problem is that msxml
946 * only formats nodes that have a line ending. Using libxml we cannot
947 * reproduce behaviour exactly.
950 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
952 xmlBufferPtr xml_buf
;
961 xml_buf
= xmlBufferCreate();
963 return E_OUTOFMEMORY
;
965 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
967 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
969 const xmlChar
*buf_content
;
972 /* Attribute Nodes return a space in front of their name */
973 buf_content
= xmlBufferContent(xml_buf
);
975 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
977 content
= EnsureCorrectEOL(content
);
981 *ret
= SysAllocStringLen(NULL
, 0);
984 xmlBufferFree(xml_buf
);
985 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
986 return *ret
? S_OK
: E_OUTOFMEMORY
;
989 #ifdef SONAME_LIBXSLT
991 /* duplicates xmlBufferWriteQuotedString() logic */
992 static void xml_write_quotedstring(xmlOutputBufferPtr buf
, const xmlChar
*string
)
994 const xmlChar
*cur
, *base
;
996 if (xmlStrchr(string
, '\"'))
998 if (xmlStrchr(string
, '\''))
1000 xmlOutputBufferWrite(buf
, 1, "\"");
1001 base
= cur
= string
;
1008 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
1009 xmlOutputBufferWrite(buf
, 6, """);
1017 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
1018 xmlOutputBufferWrite(buf
, 1, "\"");
1022 xmlOutputBufferWrite(buf
, 1, "\'");
1023 xmlOutputBufferWriteString(buf
, (const char*)string
);
1024 xmlOutputBufferWrite(buf
, 1, "\'");
1029 xmlOutputBufferWrite(buf
, 1, "\"");
1030 xmlOutputBufferWriteString(buf
, (const char*)string
);
1031 xmlOutputBufferWrite(buf
, 1, "\"");
1035 static int XMLCALL
transform_to_stream_write(void *context
, const char *buffer
, int len
)
1038 HRESULT hr
= IStream_Write((IStream
*)context
, buffer
, len
, &written
);
1039 return hr
== S_OK
? written
: -1;
1042 /* Output for method "text" */
1043 static void transform_write_text(xmlDocPtr result
, xsltStylesheetPtr style
, xmlOutputBufferPtr output
)
1045 xmlNodePtr cur
= result
->children
;
1048 if (cur
->type
== XML_TEXT_NODE
)
1049 xmlOutputBufferWriteString(output
, (const char*)cur
->content
);
1051 /* skip to next node */
1054 if ((cur
->children
->type
!= XML_ENTITY_DECL
) &&
1055 (cur
->children
->type
!= XML_ENTITY_REF_NODE
) &&
1056 (cur
->children
->type
!= XML_ENTITY_NODE
))
1058 cur
= cur
->children
;
1073 if (cur
== (xmlNodePtr
) style
->doc
) {
1085 #undef XSLT_GET_IMPORT_PTR
1086 #define XSLT_GET_IMPORT_PTR(res, style, name) { \
1087 xsltStylesheetPtr st = style; \
1089 while (st != NULL) { \
1090 if (st->name != NULL) { res = st->name; break; } \
1091 st = pxsltNextImport(st); \
1094 #undef XSLT_GET_IMPORT_INT
1095 #define XSLT_GET_IMPORT_INT(res, style, name) { \
1096 xsltStylesheetPtr st = style; \
1098 while (st != NULL) { \
1099 if (st->name != -1) { res = st->name; break; } \
1100 st = pxsltNextImport(st); \
1103 static void transform_write_xmldecl(xmlDocPtr result
, xsltStylesheetPtr style
, BOOL omit_encoding
, xmlOutputBufferPtr output
)
1105 int omit_xmldecl
, standalone
;
1107 XSLT_GET_IMPORT_INT(omit_xmldecl
, style
, omitXmlDeclaration
);
1108 if (omit_xmldecl
== 1) return;
1110 XSLT_GET_IMPORT_INT(standalone
, style
, standalone
);
1112 xmlOutputBufferWriteString(output
, "<?xml version=");
1113 if (result
->version
)
1115 xmlOutputBufferWriteString(output
, "\"");
1116 xmlOutputBufferWriteString(output
, (const char *)result
->version
);
1117 xmlOutputBufferWriteString(output
, "\"");
1120 xmlOutputBufferWriteString(output
, "\"1.0\"");
1124 const xmlChar
*encoding
;
1126 /* default encoding is UTF-16 */
1127 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1128 xmlOutputBufferWriteString(output
, " encoding=");
1129 xmlOutputBufferWriteString(output
, "\"");
1130 xmlOutputBufferWriteString(output
, encoding
? (const char *)encoding
: "UTF-16");
1131 xmlOutputBufferWriteString(output
, "\"");
1134 /* standalone attribute */
1135 if (standalone
!= -1)
1136 xmlOutputBufferWriteString(output
, standalone
== 0 ? " standalone=\"no\"" : " standalone=\"yes\"");
1138 xmlOutputBufferWriteString(output
, "?>");
1141 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
1143 xmlDtdPtr cur
= doc
->intSubset
;
1145 xmlOutputBufferWriteString(buf
, "<!DOCTYPE ");
1146 xmlOutputBufferWriteString(buf
, (const char *)cur
->name
);
1147 if (cur
->ExternalID
)
1149 xmlOutputBufferWriteString(buf
, " PUBLIC ");
1150 xml_write_quotedstring(buf
, cur
->ExternalID
);
1153 xmlOutputBufferWriteString(buf
, " ");
1154 xml_write_quotedstring(buf
, cur
->SystemID
);
1157 else if (cur
->SystemID
)
1159 xmlOutputBufferWriteString(buf
, " SYSTEM ");
1160 xml_write_quotedstring(buf
, cur
->SystemID
);
1162 xmlOutputBufferWriteString(buf
, ">\n");
1165 /* Duplicates htmlDocContentDumpFormatOutput() the way we need it - doesn't add trailing newline. */
1166 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
, const char *encoding
, int format
)
1168 xmlElementType type
;
1170 /* force HTML output */
1172 doc
->type
= XML_HTML_DOCUMENT_NODE
;
1174 htmldtd_dumpcontent(buf
, doc
);
1175 if (doc
->children
) {
1176 xmlNodePtr cur
= doc
->children
;
1178 htmlNodeDumpFormatOutput(buf
, doc
, cur
, encoding
, format
);
1185 static inline BOOL
transform_is_empty_resultdoc(xmlDocPtr result
)
1187 return !result
->children
|| ((result
->children
->type
== XML_DTD_NODE
) && !result
->children
->next
);
1190 static inline BOOL
transform_is_valid_method(xsltStylesheetPtr style
)
1192 return !style
->methodURI
|| !(style
->method
&& xmlStrEqual(style
->method
, (const xmlChar
*)"xhtml"));
1195 /* Helper to write transformation result to specified output buffer. */
1196 static HRESULT
node_transform_write(xsltStylesheetPtr style
, xmlDocPtr result
, BOOL omit_encoding
, const char *encoding
, xmlOutputBufferPtr output
)
1198 const xmlChar
*method
;
1201 if (!transform_is_valid_method(style
))
1203 ERR("unknown output method\n");
1207 XSLT_GET_IMPORT_PTR(method
, style
, method
)
1208 XSLT_GET_IMPORT_INT(indent
, style
, indent
);
1210 if (!method
&& (result
->type
== XML_HTML_DOCUMENT_NODE
))
1211 method
= (const xmlChar
*) "html";
1213 if (method
&& xmlStrEqual(method
, (const xmlChar
*)"html"))
1215 htmlSetMetaEncoding(result
, (const xmlChar
*)encoding
);
1218 htmldoc_dumpcontent(output
, result
, (const char*)encoding
, indent
);
1220 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"xhtml"))
1222 htmlSetMetaEncoding(result
, (const xmlChar
*) encoding
);
1223 htmlDocContentDumpOutput(output
, result
, encoding
);
1225 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"text"))
1226 transform_write_text(result
, style
, output
);
1229 transform_write_xmldecl(result
, style
, omit_encoding
, output
);
1231 if (result
->children
)
1233 xmlNodePtr child
= result
->children
;
1237 xmlNodeDumpOutput(output
, result
, child
, 0, indent
== 1, encoding
);
1238 if (indent
&& ((child
->type
== XML_DTD_NODE
) || ((child
->type
== XML_COMMENT_NODE
) && child
->next
)))
1239 xmlOutputBufferWriteString(output
, "\r\n");
1240 child
= child
->next
;
1245 xmlOutputBufferFlush(output
);
1249 /* For BSTR output is always UTF-16, without 'encoding' attribute */
1250 static HRESULT
node_transform_write_to_bstr(xsltStylesheetPtr style
, xmlDocPtr result
, BSTR
*str
)
1254 if (transform_is_empty_resultdoc(result
))
1255 *str
= SysAllocStringLen(NULL
, 0);
1258 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(xmlFindCharEncodingHandler("UTF-16"));
1259 const xmlChar
*content
;
1264 return E_OUTOFMEMORY
;
1266 hr
= node_transform_write(style
, result
, TRUE
, "UTF-16", output
);
1267 #ifdef LIBXML2_NEW_BUFFER
1268 content
= xmlBufContent(output
->conv
);
1269 len
= xmlBufUse(output
->conv
);
1271 content
= xmlBufferContent(output
->conv
);
1272 len
= xmlBufferLength(output
->conv
);
1274 /* UTF-16 encoder places UTF-16 bom, we don't need it for BSTR */
1275 content
+= sizeof(WCHAR
);
1276 *str
= SysAllocStringLen((WCHAR
*)content
, len
/sizeof(WCHAR
) - 1);
1277 xmlOutputBufferClose(output
);
1280 return *str
? hr
: E_OUTOFMEMORY
;
1283 static HRESULT
node_transform_write_to_stream(xsltStylesheetPtr style
, xmlDocPtr result
, IStream
*stream
)
1285 static const xmlChar
*utf16
= (const xmlChar
*)"UTF-16";
1286 xmlOutputBufferPtr output
;
1287 const xmlChar
*encoding
;
1290 if (transform_is_empty_resultdoc(result
))
1292 WARN("empty result document\n");
1296 if (style
->methodURI
&& (!style
->method
|| !xmlStrEqual(style
->method
, (const xmlChar
*) "xhtml")))
1298 ERR("unknown output method\n");
1302 /* default encoding is UTF-16 */
1303 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1307 output
= xmlOutputBufferCreateIO(transform_to_stream_write
, NULL
, stream
, xmlFindCharEncodingHandler((const char*)encoding
));
1309 return E_OUTOFMEMORY
;
1311 hr
= node_transform_write(style
, result
, FALSE
, (const char*)encoding
, output
);
1312 xmlOutputBufferClose(output
);
1318 HRESULT
node_transform_node_params(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
,
1319 IStream
*stream
, const struct xslprocessor_params
*params
)
1321 #ifdef SONAME_LIBXSLT
1322 xsltStylesheetPtr xsltSS
;
1326 if (!libxslt_handle
) return E_NOTIMPL
;
1327 if (!stylesheet
|| !p
) return E_INVALIDARG
;
1331 sheet
= get_node_obj(stylesheet
);
1332 if(!sheet
) return E_FAIL
;
1334 xsltSS
= pxsltParseStylesheetDoc(sheet
->node
->doc
);
1337 const char **xslparams
= NULL
;
1341 /* convert our parameter list to libxml2 format */
1342 if (params
&& params
->count
)
1344 struct xslprocessor_par
*par
;
1347 xslparams
= heap_alloc((params
->count
*2 + 1)*sizeof(char*));
1348 LIST_FOR_EACH_ENTRY(par
, ¶ms
->list
, struct xslprocessor_par
, entry
)
1350 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->name
);
1351 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->value
);
1353 xslparams
[i
] = NULL
;
1358 xsltTransformContextPtr ctxt
= pxsltNewTransformContext(xsltSS
, This
->node
->doc
);
1360 /* push parameters to user context */
1361 pxsltQuoteUserParams(ctxt
, xslparams
);
1362 result
= pxsltApplyStylesheetUser(xsltSS
, This
->node
->doc
, NULL
, NULL
, NULL
, ctxt
);
1363 pxsltFreeTransformContext(ctxt
);
1365 for (i
= 0; i
< params
->count
*2; i
++)
1366 heap_free((char*)xslparams
[i
]);
1367 heap_free(xslparams
);
1370 result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1375 hr
= node_transform_write_to_stream(xsltSS
, result
, stream
);
1377 hr
= node_transform_write_to_bstr(xsltSS
, result
, p
);
1380 /* libxslt "helpfully" frees the XML document the stylesheet was
1381 generated from, too */
1383 pxsltFreeStylesheet(xsltSS
);
1386 if(!*p
) *p
= SysAllocStringLen(NULL
, 0);
1390 ERR_(winediag
)("libxslt headers were not found at compile time. Expect problems.\n");
1396 HRESULT
node_transform_node(const xmlnode
*node
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
1398 return node_transform_node_params(node
, stylesheet
, p
, NULL
, NULL
);
1401 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1406 if (!query
|| !nodes
) return E_INVALIDARG
;
1408 str
= xmlchar_from_wchar(query
);
1409 hr
= create_selection(This
->node
, str
, nodes
);
1415 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1417 IXMLDOMNodeList
*list
;
1420 hr
= node_select_nodes(This
, query
, &list
);
1423 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1424 IXMLDOMNodeList_Release(list
);
1429 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1431 xmlNsPtr ns
= This
->node
->ns
;
1434 return E_INVALIDARG
;
1436 *namespaceURI
= NULL
;
1439 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1441 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1443 return *namespaceURI
? S_OK
: S_FALSE
;
1446 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1448 xmlNsPtr ns
= This
->node
->ns
;
1450 if (!prefix
) return E_INVALIDARG
;
1454 if (ns
&& ns
->prefix
)
1455 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1457 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1459 return *prefix
? S_OK
: S_FALSE
;
1462 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1464 if (!name
) return E_INVALIDARG
;
1466 *name
= bstr_from_xmlChar(This
->node
->name
);
1467 if (!*name
) return E_OUTOFMEMORY
;
1469 TRACE("returning %s\n", debugstr_w(*name
));
1474 void destroy_xmlnode(xmlnode
*This
)
1478 xmlnode_release(This
->node
);
1479 xmldoc_release(This
->node
->doc
);
1483 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1487 xmlnode_add_ref(node
);
1488 xmldoc_add_ref(node
->doc
);
1492 This
->iface
= node_iface
;
1493 This
->parent
= NULL
;
1495 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1500 IXMLDOMNode IXMLDOMNode_iface
;
1504 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1506 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1509 static HRESULT WINAPI
unknode_QueryInterface(
1514 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1516 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1518 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1520 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1521 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1522 *ppvObject
= &This
->IXMLDOMNode_iface
;
1523 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1524 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1526 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1528 return E_NOINTERFACE
;
1531 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1535 static ULONG WINAPI
unknode_AddRef(
1536 IXMLDOMNode
*iface
)
1538 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1540 return InterlockedIncrement(&This
->ref
);
1543 static ULONG WINAPI
unknode_Release(
1544 IXMLDOMNode
*iface
)
1546 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1549 ref
= InterlockedDecrement( &This
->ref
);
1551 destroy_xmlnode(&This
->node
);
1558 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1562 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1564 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1571 static HRESULT WINAPI
unknode_GetTypeInfo(
1575 ITypeInfo
** ppTInfo
)
1577 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1580 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1582 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1587 static HRESULT WINAPI
unknode_GetIDsOfNames(
1590 LPOLESTR
* rgszNames
,
1595 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1597 ITypeInfo
*typeinfo
;
1600 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1603 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1604 return E_INVALIDARG
;
1606 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1609 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1610 ITypeInfo_Release(typeinfo
);
1616 static HRESULT WINAPI
unknode_Invoke(
1618 DISPID dispIdMember
,
1622 DISPPARAMS
* pDispParams
,
1623 VARIANT
* pVarResult
,
1624 EXCEPINFO
* pExcepInfo
,
1627 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1628 ITypeInfo
*typeinfo
;
1631 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1632 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1634 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1637 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1638 pVarResult
, pExcepInfo
, puArgErr
);
1639 ITypeInfo_Release(typeinfo
);
1645 static HRESULT WINAPI
unknode_get_nodeName(
1649 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1651 FIXME("(%p)->(%p)\n", This
, p
);
1653 return node_get_nodeName(&This
->node
, p
);
1656 static HRESULT WINAPI
unknode_get_nodeValue(
1660 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1662 FIXME("(%p)->(%p)\n", This
, value
);
1665 return E_INVALIDARG
;
1667 V_VT(value
) = VT_NULL
;
1671 static HRESULT WINAPI
unknode_put_nodeValue(
1675 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1676 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1680 static HRESULT WINAPI
unknode_get_nodeType(
1682 DOMNodeType
* domNodeType
)
1684 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1686 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1688 switch (This
->node
.node
->type
)
1690 case XML_ELEMENT_NODE
:
1691 case XML_ATTRIBUTE_NODE
:
1693 case XML_CDATA_SECTION_NODE
:
1694 case XML_ENTITY_REF_NODE
:
1695 case XML_ENTITY_NODE
:
1697 case XML_COMMENT_NODE
:
1698 case XML_DOCUMENT_NODE
:
1699 case XML_DOCUMENT_TYPE_NODE
:
1700 case XML_DOCUMENT_FRAG_NODE
:
1701 case XML_NOTATION_NODE
:
1702 /* we only care about this set of types, libxml2 type values are
1703 exactly what we need */
1704 *domNodeType
= (DOMNodeType
)This
->node
.node
->type
;
1707 *domNodeType
= NODE_INVALID
;
1714 static HRESULT WINAPI
unknode_get_parentNode(
1716 IXMLDOMNode
** parent
)
1718 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1719 FIXME("(%p)->(%p)\n", This
, parent
);
1720 if (!parent
) return E_INVALIDARG
;
1725 static HRESULT WINAPI
unknode_get_childNodes(
1727 IXMLDOMNodeList
** outList
)
1729 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1731 TRACE("(%p)->(%p)\n", This
, outList
);
1733 return node_get_child_nodes(&This
->node
, outList
);
1736 static HRESULT WINAPI
unknode_get_firstChild(
1738 IXMLDOMNode
** domNode
)
1740 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1742 TRACE("(%p)->(%p)\n", This
, domNode
);
1744 return node_get_first_child(&This
->node
, domNode
);
1747 static HRESULT WINAPI
unknode_get_lastChild(
1749 IXMLDOMNode
** domNode
)
1751 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1753 TRACE("(%p)->(%p)\n", This
, domNode
);
1755 return node_get_last_child(&This
->node
, domNode
);
1758 static HRESULT WINAPI
unknode_get_previousSibling(
1760 IXMLDOMNode
** domNode
)
1762 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1764 TRACE("(%p)->(%p)\n", This
, domNode
);
1766 return node_get_previous_sibling(&This
->node
, domNode
);
1769 static HRESULT WINAPI
unknode_get_nextSibling(
1771 IXMLDOMNode
** domNode
)
1773 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1775 TRACE("(%p)->(%p)\n", This
, domNode
);
1777 return node_get_next_sibling(&This
->node
, domNode
);
1780 static HRESULT WINAPI
unknode_get_attributes(
1782 IXMLDOMNamedNodeMap
** attributeMap
)
1784 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1786 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1788 return return_null_ptr((void**)attributeMap
);
1791 static HRESULT WINAPI
unknode_insertBefore(
1793 IXMLDOMNode
* newNode
, VARIANT refChild
,
1794 IXMLDOMNode
** outOldNode
)
1796 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1798 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1800 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1803 static HRESULT WINAPI
unknode_replaceChild(
1805 IXMLDOMNode
* newNode
,
1806 IXMLDOMNode
* oldNode
,
1807 IXMLDOMNode
** outOldNode
)
1809 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1811 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1813 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1816 static HRESULT WINAPI
unknode_removeChild(
1818 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1820 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1821 return node_remove_child(&This
->node
, domNode
, oldNode
);
1824 static HRESULT WINAPI
unknode_appendChild(
1826 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1828 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1829 return node_append_child(&This
->node
, newNode
, outNewNode
);
1832 static HRESULT WINAPI
unknode_hasChildNodes(
1834 VARIANT_BOOL
* pbool
)
1836 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1837 return node_has_childnodes(&This
->node
, pbool
);
1840 static HRESULT WINAPI
unknode_get_ownerDocument(
1842 IXMLDOMDocument
** domDocument
)
1844 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1845 return node_get_owner_doc(&This
->node
, domDocument
);
1848 static HRESULT WINAPI
unknode_cloneNode(
1850 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1852 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1853 return node_clone(&This
->node
, pbool
, outNode
);
1856 static HRESULT WINAPI
unknode_get_nodeTypeString(
1860 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1862 FIXME("(%p)->(%p)\n", This
, p
);
1864 return node_get_nodeName(&This
->node
, p
);
1867 static HRESULT WINAPI
unknode_get_text(
1871 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1872 return node_get_text(&This
->node
, p
);
1875 static HRESULT WINAPI
unknode_put_text(
1879 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1880 return node_put_text(&This
->node
, p
);
1883 static HRESULT WINAPI
unknode_get_specified(
1885 VARIANT_BOOL
* isSpecified
)
1887 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1888 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
1889 *isSpecified
= VARIANT_TRUE
;
1893 static HRESULT WINAPI
unknode_get_definition(
1895 IXMLDOMNode
** definitionNode
)
1897 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1898 FIXME("(%p)->(%p)\n", This
, definitionNode
);
1902 static HRESULT WINAPI
unknode_get_nodeTypedValue(
1906 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1907 FIXME("(%p)->(%p)\n", This
, var1
);
1908 return return_null_var(var1
);
1911 static HRESULT WINAPI
unknode_put_nodeTypedValue(
1915 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1916 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
1920 static HRESULT WINAPI
unknode_get_dataType(
1924 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1925 TRACE("(%p)->(%p)\n", This
, var1
);
1926 return return_null_var(var1
);
1929 static HRESULT WINAPI
unknode_put_dataType(
1933 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1935 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
1938 return E_INVALIDARG
;
1943 static HRESULT WINAPI
unknode_get_xml(
1947 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1949 FIXME("(%p)->(%p)\n", This
, p
);
1951 return node_get_xml(&This
->node
, FALSE
, p
);
1954 static HRESULT WINAPI
unknode_transformNode(
1956 IXMLDOMNode
* domNode
, BSTR
* p
)
1958 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1959 return node_transform_node(&This
->node
, domNode
, p
);
1962 static HRESULT WINAPI
unknode_selectNodes(
1964 BSTR p
, IXMLDOMNodeList
** outList
)
1966 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1967 return node_select_nodes(&This
->node
, p
, outList
);
1970 static HRESULT WINAPI
unknode_selectSingleNode(
1972 BSTR p
, IXMLDOMNode
** outNode
)
1974 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1975 return node_select_singlenode(&This
->node
, p
, outNode
);
1978 static HRESULT WINAPI
unknode_get_parsed(
1980 VARIANT_BOOL
* isParsed
)
1982 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1983 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
1984 *isParsed
= VARIANT_TRUE
;
1988 static HRESULT WINAPI
unknode_get_namespaceURI(
1992 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1993 TRACE("(%p)->(%p)\n", This
, p
);
1994 return node_get_namespaceURI(&This
->node
, p
);
1997 static HRESULT WINAPI
unknode_get_prefix(
2001 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2002 return node_get_prefix(&This
->node
, p
);
2005 static HRESULT WINAPI
unknode_get_baseName(
2009 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2010 return node_get_base_name(&This
->node
, p
);
2013 static HRESULT WINAPI
unknode_transformNodeToObject(
2015 IXMLDOMNode
* domNode
, VARIANT var1
)
2017 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2018 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
2022 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
2024 unknode_QueryInterface
,
2027 unknode_GetTypeInfoCount
,
2028 unknode_GetTypeInfo
,
2029 unknode_GetIDsOfNames
,
2031 unknode_get_nodeName
,
2032 unknode_get_nodeValue
,
2033 unknode_put_nodeValue
,
2034 unknode_get_nodeType
,
2035 unknode_get_parentNode
,
2036 unknode_get_childNodes
,
2037 unknode_get_firstChild
,
2038 unknode_get_lastChild
,
2039 unknode_get_previousSibling
,
2040 unknode_get_nextSibling
,
2041 unknode_get_attributes
,
2042 unknode_insertBefore
,
2043 unknode_replaceChild
,
2044 unknode_removeChild
,
2045 unknode_appendChild
,
2046 unknode_hasChildNodes
,
2047 unknode_get_ownerDocument
,
2049 unknode_get_nodeTypeString
,
2052 unknode_get_specified
,
2053 unknode_get_definition
,
2054 unknode_get_nodeTypedValue
,
2055 unknode_put_nodeTypedValue
,
2056 unknode_get_dataType
,
2057 unknode_put_dataType
,
2059 unknode_transformNode
,
2060 unknode_selectNodes
,
2061 unknode_selectSingleNode
,
2063 unknode_get_namespaceURI
,
2065 unknode_get_baseName
,
2066 unknode_transformNodeToObject
2069 IXMLDOMNode
*create_node( xmlNodePtr node
)
2078 TRACE("type %d\n", node
->type
);
2081 case XML_ELEMENT_NODE
:
2082 pUnk
= create_element( node
);
2084 case XML_ATTRIBUTE_NODE
:
2085 pUnk
= create_attribute( node
);
2088 pUnk
= create_text( node
);
2090 case XML_CDATA_SECTION_NODE
:
2091 pUnk
= create_cdata( node
);
2093 case XML_ENTITY_REF_NODE
:
2094 pUnk
= create_doc_entity_ref( node
);
2097 pUnk
= create_pi( node
);
2099 case XML_COMMENT_NODE
:
2100 pUnk
= create_comment( node
);
2102 case XML_DOCUMENT_NODE
:
2103 pUnk
= create_domdoc( node
);
2105 case XML_DOCUMENT_FRAG_NODE
:
2106 pUnk
= create_doc_fragment( node
);
2109 case XML_DOCUMENT_TYPE_NODE
:
2110 pUnk
= create_doc_type( node
);
2112 case XML_ENTITY_NODE
:
2113 case XML_NOTATION_NODE
: {
2116 FIXME("only creating basic node for type %d\n", node
->type
);
2118 new_node
= heap_alloc(sizeof(unknode
));
2122 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
2124 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
2125 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
2129 ERR("Called for unsupported node type %d\n", node
->type
);
2133 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
2134 IUnknown_Release(pUnk
);
2135 if(FAILED(hr
)) return NULL
;