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
= ISequentialStream_Write((ISequentialStream
*)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
, ISequentialStream
*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 ISequentialStream
*stream
, const struct xslprocessor_params
*params
)
1321 #ifdef SONAME_LIBXSLT
1322 xsltStylesheetPtr xsltSS
;
1323 xmlDocPtr sheet_doc
;
1327 if (!libxslt_handle
) return E_NOTIMPL
;
1328 if (!stylesheet
|| !p
) return E_INVALIDARG
;
1332 sheet
= get_node_obj(stylesheet
);
1333 if(!sheet
) return E_FAIL
;
1335 sheet_doc
= xmlCopyDoc(sheet
->node
->doc
, 1);
1336 xsltSS
= pxsltParseStylesheetDoc(sheet_doc
);
1339 const char **xslparams
= NULL
;
1343 /* convert our parameter list to libxml2 format */
1344 if (params
&& params
->count
)
1346 struct xslprocessor_par
*par
;
1349 xslparams
= heap_alloc((params
->count
*2 + 1)*sizeof(char*));
1350 LIST_FOR_EACH_ENTRY(par
, ¶ms
->list
, struct xslprocessor_par
, entry
)
1352 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->name
);
1353 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->value
);
1355 xslparams
[i
] = NULL
;
1360 xsltTransformContextPtr ctxt
= pxsltNewTransformContext(xsltSS
, This
->node
->doc
);
1362 /* push parameters to user context */
1363 pxsltQuoteUserParams(ctxt
, xslparams
);
1364 result
= pxsltApplyStylesheetUser(xsltSS
, This
->node
->doc
, NULL
, NULL
, NULL
, ctxt
);
1365 pxsltFreeTransformContext(ctxt
);
1367 for (i
= 0; i
< params
->count
*2; i
++)
1368 heap_free((char*)xslparams
[i
]);
1369 heap_free(xslparams
);
1372 result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1377 hr
= node_transform_write_to_stream(xsltSS
, result
, stream
);
1379 hr
= node_transform_write_to_bstr(xsltSS
, result
, p
);
1383 pxsltFreeStylesheet(xsltSS
);
1386 xmlFreeDoc(sheet_doc
);
1388 if(!*p
) *p
= SysAllocStringLen(NULL
, 0);
1392 ERR_(winediag
)("libxslt headers were not found at compile time. Expect problems.\n");
1398 HRESULT
node_transform_node(const xmlnode
*node
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
1400 return node_transform_node_params(node
, stylesheet
, p
, NULL
, NULL
);
1403 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1408 if (!query
|| !nodes
) return E_INVALIDARG
;
1410 str
= xmlchar_from_wchar(query
);
1411 hr
= create_selection(This
->node
, str
, nodes
);
1417 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1419 IXMLDOMNodeList
*list
;
1422 hr
= node_select_nodes(This
, query
, &list
);
1425 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1426 IXMLDOMNodeList_Release(list
);
1431 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1433 xmlNsPtr ns
= This
->node
->ns
;
1436 return E_INVALIDARG
;
1438 *namespaceURI
= NULL
;
1441 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1443 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1445 return *namespaceURI
? S_OK
: S_FALSE
;
1448 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1450 xmlNsPtr ns
= This
->node
->ns
;
1452 if (!prefix
) return E_INVALIDARG
;
1456 if (ns
&& ns
->prefix
)
1457 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1459 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1461 return *prefix
? S_OK
: S_FALSE
;
1464 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1466 if (!name
) return E_INVALIDARG
;
1468 *name
= bstr_from_xmlChar(This
->node
->name
);
1469 if (!*name
) return E_OUTOFMEMORY
;
1471 TRACE("returning %s\n", debugstr_w(*name
));
1476 void destroy_xmlnode(xmlnode
*This
)
1480 xmlnode_release(This
->node
);
1481 xmldoc_release(This
->node
->doc
);
1485 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1489 xmlnode_add_ref(node
);
1490 xmldoc_add_ref(node
->doc
);
1494 This
->iface
= node_iface
;
1495 This
->parent
= NULL
;
1497 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1502 IXMLDOMNode IXMLDOMNode_iface
;
1506 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1508 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1511 static HRESULT WINAPI
unknode_QueryInterface(
1516 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1518 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1520 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1522 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1523 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1524 *ppvObject
= &This
->IXMLDOMNode_iface
;
1525 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1526 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1528 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1530 return E_NOINTERFACE
;
1533 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1537 static ULONG WINAPI
unknode_AddRef(
1538 IXMLDOMNode
*iface
)
1540 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1542 return InterlockedIncrement(&This
->ref
);
1545 static ULONG WINAPI
unknode_Release(
1546 IXMLDOMNode
*iface
)
1548 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1551 ref
= InterlockedDecrement( &This
->ref
);
1553 destroy_xmlnode(&This
->node
);
1560 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1564 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1566 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1573 static HRESULT WINAPI
unknode_GetTypeInfo(
1577 ITypeInfo
** ppTInfo
)
1579 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1582 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1584 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1589 static HRESULT WINAPI
unknode_GetIDsOfNames(
1592 LPOLESTR
* rgszNames
,
1597 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1599 ITypeInfo
*typeinfo
;
1602 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1605 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1606 return E_INVALIDARG
;
1608 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1611 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1612 ITypeInfo_Release(typeinfo
);
1618 static HRESULT WINAPI
unknode_Invoke(
1620 DISPID dispIdMember
,
1624 DISPPARAMS
* pDispParams
,
1625 VARIANT
* pVarResult
,
1626 EXCEPINFO
* pExcepInfo
,
1629 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1630 ITypeInfo
*typeinfo
;
1633 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1634 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1636 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1639 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1640 pVarResult
, pExcepInfo
, puArgErr
);
1641 ITypeInfo_Release(typeinfo
);
1647 static HRESULT WINAPI
unknode_get_nodeName(
1651 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1653 FIXME("(%p)->(%p)\n", This
, p
);
1655 return node_get_nodeName(&This
->node
, p
);
1658 static HRESULT WINAPI
unknode_get_nodeValue(
1662 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1664 FIXME("(%p)->(%p)\n", This
, value
);
1667 return E_INVALIDARG
;
1669 V_VT(value
) = VT_NULL
;
1673 static HRESULT WINAPI
unknode_put_nodeValue(
1677 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1678 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1682 static HRESULT WINAPI
unknode_get_nodeType(
1684 DOMNodeType
* domNodeType
)
1686 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1688 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1690 switch (This
->node
.node
->type
)
1692 case XML_ELEMENT_NODE
:
1693 case XML_ATTRIBUTE_NODE
:
1695 case XML_CDATA_SECTION_NODE
:
1696 case XML_ENTITY_REF_NODE
:
1697 case XML_ENTITY_NODE
:
1699 case XML_COMMENT_NODE
:
1700 case XML_DOCUMENT_NODE
:
1701 case XML_DOCUMENT_TYPE_NODE
:
1702 case XML_DOCUMENT_FRAG_NODE
:
1703 case XML_NOTATION_NODE
:
1704 /* we only care about this set of types, libxml2 type values are
1705 exactly what we need */
1706 *domNodeType
= (DOMNodeType
)This
->node
.node
->type
;
1709 *domNodeType
= NODE_INVALID
;
1716 static HRESULT WINAPI
unknode_get_parentNode(
1718 IXMLDOMNode
** parent
)
1720 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1721 FIXME("(%p)->(%p)\n", This
, parent
);
1722 if (!parent
) return E_INVALIDARG
;
1727 static HRESULT WINAPI
unknode_get_childNodes(
1729 IXMLDOMNodeList
** outList
)
1731 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1733 TRACE("(%p)->(%p)\n", This
, outList
);
1735 return node_get_child_nodes(&This
->node
, outList
);
1738 static HRESULT WINAPI
unknode_get_firstChild(
1740 IXMLDOMNode
** domNode
)
1742 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1744 TRACE("(%p)->(%p)\n", This
, domNode
);
1746 return node_get_first_child(&This
->node
, domNode
);
1749 static HRESULT WINAPI
unknode_get_lastChild(
1751 IXMLDOMNode
** domNode
)
1753 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1755 TRACE("(%p)->(%p)\n", This
, domNode
);
1757 return node_get_last_child(&This
->node
, domNode
);
1760 static HRESULT WINAPI
unknode_get_previousSibling(
1762 IXMLDOMNode
** domNode
)
1764 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1766 TRACE("(%p)->(%p)\n", This
, domNode
);
1768 return node_get_previous_sibling(&This
->node
, domNode
);
1771 static HRESULT WINAPI
unknode_get_nextSibling(
1773 IXMLDOMNode
** domNode
)
1775 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1777 TRACE("(%p)->(%p)\n", This
, domNode
);
1779 return node_get_next_sibling(&This
->node
, domNode
);
1782 static HRESULT WINAPI
unknode_get_attributes(
1784 IXMLDOMNamedNodeMap
** attributeMap
)
1786 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1788 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1790 return return_null_ptr((void**)attributeMap
);
1793 static HRESULT WINAPI
unknode_insertBefore(
1795 IXMLDOMNode
* newNode
, VARIANT refChild
,
1796 IXMLDOMNode
** outOldNode
)
1798 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1800 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1802 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1805 static HRESULT WINAPI
unknode_replaceChild(
1807 IXMLDOMNode
* newNode
,
1808 IXMLDOMNode
* oldNode
,
1809 IXMLDOMNode
** outOldNode
)
1811 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1813 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1815 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1818 static HRESULT WINAPI
unknode_removeChild(
1820 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1822 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1823 return node_remove_child(&This
->node
, domNode
, oldNode
);
1826 static HRESULT WINAPI
unknode_appendChild(
1828 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1830 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1831 return node_append_child(&This
->node
, newNode
, outNewNode
);
1834 static HRESULT WINAPI
unknode_hasChildNodes(
1836 VARIANT_BOOL
* pbool
)
1838 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1839 return node_has_childnodes(&This
->node
, pbool
);
1842 static HRESULT WINAPI
unknode_get_ownerDocument(
1844 IXMLDOMDocument
** domDocument
)
1846 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1847 return node_get_owner_doc(&This
->node
, domDocument
);
1850 static HRESULT WINAPI
unknode_cloneNode(
1852 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1854 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1855 return node_clone(&This
->node
, pbool
, outNode
);
1858 static HRESULT WINAPI
unknode_get_nodeTypeString(
1862 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1864 FIXME("(%p)->(%p)\n", This
, p
);
1866 return node_get_nodeName(&This
->node
, p
);
1869 static HRESULT WINAPI
unknode_get_text(
1873 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1874 return node_get_text(&This
->node
, p
);
1877 static HRESULT WINAPI
unknode_put_text(
1881 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1882 return node_put_text(&This
->node
, p
);
1885 static HRESULT WINAPI
unknode_get_specified(
1887 VARIANT_BOOL
* isSpecified
)
1889 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1890 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
1891 *isSpecified
= VARIANT_TRUE
;
1895 static HRESULT WINAPI
unknode_get_definition(
1897 IXMLDOMNode
** definitionNode
)
1899 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1900 FIXME("(%p)->(%p)\n", This
, definitionNode
);
1904 static HRESULT WINAPI
unknode_get_nodeTypedValue(
1908 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1909 FIXME("(%p)->(%p)\n", This
, var1
);
1910 return return_null_var(var1
);
1913 static HRESULT WINAPI
unknode_put_nodeTypedValue(
1917 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1918 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
1922 static HRESULT WINAPI
unknode_get_dataType(
1926 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1927 TRACE("(%p)->(%p)\n", This
, var1
);
1928 return return_null_var(var1
);
1931 static HRESULT WINAPI
unknode_put_dataType(
1935 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1937 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
1940 return E_INVALIDARG
;
1945 static HRESULT WINAPI
unknode_get_xml(
1949 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1951 FIXME("(%p)->(%p)\n", This
, p
);
1953 return node_get_xml(&This
->node
, FALSE
, p
);
1956 static HRESULT WINAPI
unknode_transformNode(
1958 IXMLDOMNode
* domNode
, BSTR
* p
)
1960 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1961 return node_transform_node(&This
->node
, domNode
, p
);
1964 static HRESULT WINAPI
unknode_selectNodes(
1966 BSTR p
, IXMLDOMNodeList
** outList
)
1968 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1969 return node_select_nodes(&This
->node
, p
, outList
);
1972 static HRESULT WINAPI
unknode_selectSingleNode(
1974 BSTR p
, IXMLDOMNode
** outNode
)
1976 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1977 return node_select_singlenode(&This
->node
, p
, outNode
);
1980 static HRESULT WINAPI
unknode_get_parsed(
1982 VARIANT_BOOL
* isParsed
)
1984 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1985 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
1986 *isParsed
= VARIANT_TRUE
;
1990 static HRESULT WINAPI
unknode_get_namespaceURI(
1994 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1995 TRACE("(%p)->(%p)\n", This
, p
);
1996 return node_get_namespaceURI(&This
->node
, p
);
1999 static HRESULT WINAPI
unknode_get_prefix(
2003 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2004 return node_get_prefix(&This
->node
, p
);
2007 static HRESULT WINAPI
unknode_get_baseName(
2011 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2012 return node_get_base_name(&This
->node
, p
);
2015 static HRESULT WINAPI
unknode_transformNodeToObject(
2017 IXMLDOMNode
* domNode
, VARIANT var1
)
2019 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2020 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
2024 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
2026 unknode_QueryInterface
,
2029 unknode_GetTypeInfoCount
,
2030 unknode_GetTypeInfo
,
2031 unknode_GetIDsOfNames
,
2033 unknode_get_nodeName
,
2034 unknode_get_nodeValue
,
2035 unknode_put_nodeValue
,
2036 unknode_get_nodeType
,
2037 unknode_get_parentNode
,
2038 unknode_get_childNodes
,
2039 unknode_get_firstChild
,
2040 unknode_get_lastChild
,
2041 unknode_get_previousSibling
,
2042 unknode_get_nextSibling
,
2043 unknode_get_attributes
,
2044 unknode_insertBefore
,
2045 unknode_replaceChild
,
2046 unknode_removeChild
,
2047 unknode_appendChild
,
2048 unknode_hasChildNodes
,
2049 unknode_get_ownerDocument
,
2051 unknode_get_nodeTypeString
,
2054 unknode_get_specified
,
2055 unknode_get_definition
,
2056 unknode_get_nodeTypedValue
,
2057 unknode_put_nodeTypedValue
,
2058 unknode_get_dataType
,
2059 unknode_put_dataType
,
2061 unknode_transformNode
,
2062 unknode_selectNodes
,
2063 unknode_selectSingleNode
,
2065 unknode_get_namespaceURI
,
2067 unknode_get_baseName
,
2068 unknode_transformNodeToObject
2071 IXMLDOMNode
*create_node( xmlNodePtr node
)
2080 TRACE("type %d\n", node
->type
);
2083 case XML_ELEMENT_NODE
:
2084 pUnk
= create_element( node
);
2086 case XML_ATTRIBUTE_NODE
:
2087 pUnk
= create_attribute( node
);
2090 pUnk
= create_text( node
);
2092 case XML_CDATA_SECTION_NODE
:
2093 pUnk
= create_cdata( node
);
2095 case XML_ENTITY_REF_NODE
:
2096 pUnk
= create_doc_entity_ref( node
);
2099 pUnk
= create_pi( node
);
2101 case XML_COMMENT_NODE
:
2102 pUnk
= create_comment( node
);
2104 case XML_DOCUMENT_NODE
:
2105 pUnk
= create_domdoc( node
);
2107 case XML_DOCUMENT_FRAG_NODE
:
2108 pUnk
= create_doc_fragment( node
);
2111 case XML_DOCUMENT_TYPE_NODE
:
2112 pUnk
= create_doc_type( node
);
2114 case XML_ENTITY_NODE
:
2115 case XML_NOTATION_NODE
: {
2118 FIXME("only creating basic node for type %d\n", node
->type
);
2120 new_node
= heap_alloc(sizeof(unknode
));
2124 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
2126 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
2127 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
2131 ERR("Called for unsupported node type %d\n", node
->type
);
2135 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
2136 IUnknown_Release(pUnk
);
2137 if(FAILED(hr
)) return NULL
;