4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 # include <libxml/HTMLtree.h>
31 # ifdef SONAME_LIBXSLT
32 # ifdef HAVE_LIBXSLT_PATTERN_H
33 # include <libxslt/pattern.h>
35 # ifdef HAVE_LIBXSLT_TRANSFORM_H
36 # include <libxslt/transform.h>
38 # include <libxslt/xsltutils.h>
39 # include <libxslt/xsltInternals.h>
50 #include "msxml_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
59 extern void* libxslt_handle
;
60 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
61 MAKE_FUNCPTR(xsltApplyStylesheet
);
62 MAKE_FUNCPTR(xsltCleanupGlobals
);
63 MAKE_FUNCPTR(xsltFreeStylesheet
);
64 MAKE_FUNCPTR(xsltParseStylesheetDoc
);
68 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
70 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
76 This
= get_node_obj( iface
);
77 if ( !This
|| !This
->node
)
79 if ( type
&& This
->node
->type
!= type
)
84 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
86 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
87 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
92 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
95 /* common ISupportErrorInfo implementation */
97 ISupportErrorInfo ISupportErrorInfo_iface
;
103 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
105 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
108 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
110 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
111 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
115 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
117 ISupportErrorInfo_AddRef(iface
);
121 return E_NOINTERFACE
;
124 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
126 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
127 ULONG ref
= InterlockedIncrement(&This
->ref
);
128 TRACE("(%p)->(%d)\n", This
, ref
);
132 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
134 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
135 LONG ref
= InterlockedDecrement(&This
->ref
);
137 TRACE("(%p)->(%d)\n", This
, ref
);
145 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
147 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
148 enum tid_t
const *tid
;
150 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
153 while (*tid
!= NULL_tid
)
155 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
163 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
164 SupportErrorInfo_QueryInterface
,
165 SupportErrorInfo_AddRef
,
166 SupportErrorInfo_Release
,
167 SupportErrorInfo_InterfaceSupportsErrorInfo
170 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
172 SupportErrorInfo
*This
;
174 This
= heap_alloc(sizeof(*This
));
175 if (!This
) return E_OUTOFMEMORY
;
177 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
181 *obj
= &This
->ISupportErrorInfo_iface
;
186 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
191 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
192 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
193 return SUCCEEDED(hres
) ? obj
: NULL
;
196 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
204 hr
= node_get_base_name(This
, &base
);
205 if (hr
!= S_OK
) return hr
;
207 hr
= node_get_prefix(This
, &prefix
);
210 static const WCHAR colW
= ':';
214 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
215 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
216 ptr
+= SysStringLen(prefix
);
217 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
218 memcpy(ptr
, base
, SysStringByteLen(base
));
221 SysFreeString(prefix
);
229 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
236 content
= xmlNodeGetContent(This
->node
);
237 V_VT(value
) = VT_BSTR
;
238 V_BSTR(value
) = bstr_from_xmlChar( content
);
241 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
245 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
249 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
250 str
= xmlchar_from_wchar(value
);
252 return E_OUTOFMEMORY
;
254 xmlNodeSetContent(This
->node
, str
);
259 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
261 xmlChar
*str
, *escaped
;
263 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
264 str
= xmlchar_from_wchar(value
);
266 return E_OUTOFMEMORY
;
268 escaped
= xmlEncodeSpecialChars(NULL
, str
);
272 return E_OUTOFMEMORY
;
275 xmlNodeSetContent(This
->node
, escaped
);
283 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
287 if (V_VT(value
) != VT_BSTR
)
289 VARIANT string_value
;
291 VariantInit(&string_value
);
292 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
294 WARN("Couldn't convert to VT_BSTR\n");
298 hr
= node_set_content(This
, V_BSTR(&string_value
));
299 VariantClear(&string_value
);
302 hr
= node_set_content(This
, V_BSTR(value
));
307 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
311 if (V_VT(value
) != VT_BSTR
)
313 VARIANT string_value
;
315 VariantInit(&string_value
);
316 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
318 WARN("Couldn't convert to VT_BSTR\n");
322 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
323 VariantClear(&string_value
);
326 hr
= node_set_content_escaped(This
, V_BSTR(value
));
331 static HRESULT
get_node(
337 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
342 /* if we don't have a doc, use our parent. */
343 if(node
&& !node
->doc
&& node
->parent
)
344 node
->doc
= node
->parent
->doc
;
346 *out
= create_node( node
);
352 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
354 return get_node( This
, "parent", This
->node
->parent
, parent
);
357 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
362 *ret
= create_children_nodelist(This
->node
);
364 return E_OUTOFMEMORY
;
369 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
371 return get_node(This
, "firstChild", This
->node
->children
, ret
);
374 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
376 return get_node(This
, "lastChild", This
->node
->last
, ret
);
379 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
381 return get_node(This
, "previous", This
->node
->prev
, ret
);
384 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
386 return get_node(This
, "next", This
->node
->next
, ret
);
389 static int node_get_inst_cnt(xmlNodePtr node
)
391 int ret
= *(LONG
*)&node
->_private
;
394 /* add attribute counts */
395 if (node
->type
== XML_ELEMENT_NODE
)
397 xmlAttrPtr prop
= node
->properties
;
401 ret
+= node_get_inst_cnt((xmlNodePtr
)prop
);
406 /* add children counts */
407 child
= node
->children
;
410 ret
+= node_get_inst_cnt(child
);
417 int xmlnode_get_inst_cnt(xmlnode
*node
)
419 return node_get_inst_cnt(node
->node
);
422 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
425 IXMLDOMNode
*before
= NULL
;
434 node_obj
= get_node_obj(new_child
);
435 if(!node_obj
) return E_FAIL
;
437 switch(V_VT(ref_child
))
445 if (V_UNKNOWN(ref_child
))
447 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
448 if(FAILED(hr
)) return hr
;
453 FIXME("refChild var type %x\n", V_VT(ref_child
));
457 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
459 if(!node_obj
->node
->parent
)
460 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
461 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
463 refcount
= xmlnode_get_inst_cnt(node_obj
);
467 xmlnode
*before_node_obj
= get_node_obj(before
);
468 IXMLDOMNode_Release(before
);
469 if(!before_node_obj
) return E_FAIL
;
471 /* unlink from current parent first */
474 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
475 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
478 doc
= node_obj
->node
->doc
;
480 /* refs count including subtree */
481 if (doc
!= before_node_obj
->node
->doc
)
482 refcount
= xmlnode_get_inst_cnt(node_obj
);
484 if (refcount
) xmldoc_add_refs(before_node_obj
->node
->doc
, refcount
);
485 xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
486 if (refcount
) xmldoc_release_refs(doc
, refcount
);
487 node_obj
->parent
= This
->parent
;
491 /* unlink from current parent first */
494 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
495 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
497 doc
= node_obj
->node
->doc
;
499 if (doc
!= This
->node
->doc
)
500 refcount
= xmlnode_get_inst_cnt(node_obj
);
502 if (refcount
) xmldoc_add_refs(This
->node
->doc
, refcount
);
503 /* xmlAddChild doesn't unlink node from previous parent */
504 xmlUnlinkNode(node_obj
->node
);
505 xmlAddChild(This
->node
, node_obj
->node
);
506 if (refcount
) xmldoc_release_refs(doc
, refcount
);
507 node_obj
->parent
= This
->iface
;
512 IXMLDOMNode_AddRef(new_child
);
520 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
523 xmlnode
*old_child
, *new_child
;
524 xmlDocPtr leaving_doc
;
525 xmlNode
*my_ancestor
;
528 /* Do not believe any documentation telling that newChild == NULL
529 means removal. It does certainly *not* apply to msxml3! */
530 if(!newChild
|| !oldChild
)
536 old_child
= get_node_obj(oldChild
);
537 if(!old_child
) return E_FAIL
;
539 if(old_child
->node
->parent
!= This
->node
)
541 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
545 new_child
= get_node_obj(newChild
);
546 if(!new_child
) return E_FAIL
;
548 my_ancestor
= This
->node
;
551 if(my_ancestor
== new_child
->node
)
553 WARN("tried to create loop\n");
556 my_ancestor
= my_ancestor
->parent
;
559 if(!new_child
->node
->parent
)
560 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
561 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
563 leaving_doc
= new_child
->node
->doc
;
565 if (leaving_doc
!= old_child
->node
->doc
)
566 refcount
= xmlnode_get_inst_cnt(new_child
);
568 if (refcount
) xmldoc_add_refs(old_child
->node
->doc
, refcount
);
569 xmlReplaceNode(old_child
->node
, new_child
->node
);
570 if (refcount
) xmldoc_release_refs(leaving_doc
, refcount
);
571 new_child
->parent
= old_child
->parent
;
572 old_child
->parent
= NULL
;
574 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
578 IXMLDOMNode_AddRef(oldChild
);
585 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
589 if(!child
) return E_INVALIDARG
;
594 child_node
= get_node_obj(child
);
595 if(!child_node
) return E_FAIL
;
597 if(child_node
->node
->parent
!= This
->node
)
599 WARN("childNode %p is not a child of %p\n", child
, This
);
603 xmlUnlinkNode(child_node
->node
);
604 child_node
->parent
= NULL
;
605 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
609 IXMLDOMNode_AddRef(child
);
616 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
622 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
623 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
624 if (outChild
) *outChild
= NULL
;
629 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
632 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
634 if (!ret
) return E_INVALIDARG
;
636 if (!This
->node
->children
)
638 *ret
= VARIANT_FALSE
;
646 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
648 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
651 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
656 if(!cloneNode
) return E_INVALIDARG
;
658 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
661 xmlSetTreeDoc(clone
, This
->node
->doc
);
662 xmldoc_add_orphan(clone
->doc
, clone
);
664 node
= create_node(clone
);
667 ERR("Copy failed\n");
668 xmldoc_remove_orphan(clone
->doc
, clone
);
677 ERR("Copy failed\n");
684 static inline xmlChar
* trim_whitespace(xmlChar
* str
)
692 while (*ret
&& isspace(*ret
))
694 len
= xmlStrlen(ret
);
696 while (isspace(ret
[len
-1])) --len
;
698 ret
= xmlStrndup(ret
, len
);
703 static xmlChar
* do_get_text(xmlNodePtr node
)
707 BOOL preserving
= is_preserving_whitespace(node
);
711 str
= xmlNodeGetContent(node
);
715 xmlElementType prev_type
= XML_TEXT_NODE
;
717 str
= xmlStrdup(BAD_CAST
"");
718 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
722 case XML_ELEMENT_NODE
:
723 tmp
= do_get_text(child
);
726 case XML_CDATA_SECTION_NODE
:
727 case XML_ENTITY_REF_NODE
:
728 case XML_ENTITY_NODE
:
729 tmp
= xmlNodeGetContent(child
);
740 if (prev_type
== XML_ELEMENT_NODE
&& child
->type
== XML_ELEMENT_NODE
)
741 str
= xmlStrcat(str
, BAD_CAST
" ");
742 str
= xmlStrcat(str
, tmp
);
743 prev_type
= child
->type
;
752 case XML_ELEMENT_NODE
:
754 case XML_ENTITY_REF_NODE
:
755 case XML_ENTITY_NODE
:
756 case XML_DOCUMENT_NODE
:
757 case XML_DOCUMENT_FRAG_NODE
:
759 str
= trim_whitespace(str
);
768 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
773 if (!text
) return E_INVALIDARG
;
775 content
= do_get_text(This
->node
);
778 str
= bstr_from_xmlChar(content
);
782 /* Always return a string. */
783 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
785 TRACE("%p %s\n", This
, debugstr_w(str
) );
791 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
795 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
797 str
= xmlchar_from_wchar(text
);
799 /* Escape the string. */
800 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
803 xmlNodeSetContent(This
->node
, str2
);
809 BSTR
EnsureCorrectEOL(BSTR sInput
)
816 nLen
= SysStringLen(sInput
);
817 /* Count line endings */
818 for(i
=0; i
< nLen
; i
++)
820 if(sInput
[i
] == '\n')
824 TRACE("len=%d, num=%d\n", nLen
, nNum
);
826 /* Add linefeed as needed */
830 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
831 for(i
=0; i
< nLen
; i
++)
833 if(sInput
[i
] == '\n')
835 sNew
[i
+nPlace
] = '\r';
838 sNew
[i
+nPlace
] = sInput
[i
];
841 SysFreeString(sInput
);
848 TRACE("len %d\n", SysStringLen(sNew
));
854 * We are trying to replicate the same behaviour as msxml by converting
855 * line endings to \r\n and using indents as \t. The problem is that msxml
856 * only formats nodes that have a line ending. Using libxml we cannot
857 * reproduce behaviour exactly.
860 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
862 xmlBufferPtr xml_buf
;
871 xml_buf
= xmlBufferCreate();
873 return E_OUTOFMEMORY
;
875 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
877 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
879 const xmlChar
*buf_content
;
882 /* Attribute Nodes return a space in front of their name */
883 buf_content
= xmlBufferContent(xml_buf
);
885 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
887 content
= EnsureCorrectEOL(content
);
891 *ret
= SysAllocStringLen(NULL
, 0);
894 xmlBufferFree(xml_buf
);
895 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
896 return *ret
? S_OK
: E_OUTOFMEMORY
;
899 /* duplicates xmlBufferWriteQuotedString() logic */
900 static void xml_write_quotedstring(xmlOutputBufferPtr buf
, const xmlChar
*string
)
902 const xmlChar
*cur
, *base
;
904 if (xmlStrchr(string
, '\"'))
906 if (xmlStrchr(string
, '\''))
908 xmlOutputBufferWrite(buf
, 1, "\"");
916 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
917 xmlOutputBufferWrite(buf
, 6, """);
925 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
926 xmlOutputBufferWrite(buf
, 1, "\"");
930 xmlOutputBufferWrite(buf
, 1, "\'");
931 xmlOutputBufferWriteString(buf
, (const char*)string
);
932 xmlOutputBufferWrite(buf
, 1, "\'");
937 xmlOutputBufferWrite(buf
, 1, "\"");
938 xmlOutputBufferWriteString(buf
, (const char*)string
);
939 xmlOutputBufferWrite(buf
, 1, "\"");
943 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
945 xmlDtdPtr cur
= doc
->intSubset
;
947 xmlOutputBufferWriteString(buf
, "<!DOCTYPE ");
948 xmlOutputBufferWriteString(buf
, (const char *)cur
->name
);
951 xmlOutputBufferWriteString(buf
, " PUBLIC ");
952 xml_write_quotedstring(buf
, cur
->ExternalID
);
955 xmlOutputBufferWriteString(buf
, " ");
956 xml_write_quotedstring(buf
, cur
->SystemID
);
959 else if (cur
->SystemID
)
961 xmlOutputBufferWriteString(buf
, " SYSTEM ");
962 xml_write_quotedstring(buf
, cur
->SystemID
);
964 xmlOutputBufferWriteString(buf
, ">\n");
967 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
971 /* force HTML output */
973 doc
->type
= XML_HTML_DOCUMENT_NODE
;
975 htmldtd_dumpcontent(buf
, doc
);
978 xmlNodePtr cur
= doc
->children
;
982 htmlNodeDumpFormatOutput(buf
, doc
, cur
, NULL
, 1);
990 static const xmlChar
*get_output_buffer_content(xmlOutputBufferPtr output
)
992 #ifdef LIBXML2_NEW_BUFFER
993 return xmlOutputBufferGetContent(output
);
995 return xmlBufferContent(output
->buffer
);
999 HRESULT
node_transform_node(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
1001 #ifdef SONAME_LIBXSLT
1002 xsltStylesheetPtr xsltSS
;
1005 if (!libxslt_handle
) return E_NOTIMPL
;
1006 if (!stylesheet
|| !p
) return E_INVALIDARG
;
1010 sheet
= get_node_obj(stylesheet
);
1011 if(!sheet
) return E_FAIL
;
1013 xsltSS
= pxsltParseStylesheetDoc(sheet
->node
->doc
);
1016 xmlDocPtr result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1019 const xmlChar
*content
;
1021 if(result
->type
== XML_HTML_DOCUMENT_NODE
)
1023 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(NULL
);
1026 htmldoc_dumpcontent(output
, result
->doc
);
1027 content
= get_output_buffer_content(output
);
1028 *p
= bstr_from_xmlChar(content
);
1029 xmlOutputBufferClose(output
);
1034 xmlBufferPtr buf
= xmlBufferCreate();
1037 int size
= xmlNodeDump(buf
, NULL
, (xmlNodePtr
)result
, 0, 0);
1040 content
= xmlBufferContent(buf
);
1041 *p
= bstr_from_xmlChar(content
);
1048 /* libxslt "helpfully" frees the XML document the stylesheet was
1049 generated from, too */
1051 pxsltFreeStylesheet(xsltSS
);
1054 if(!*p
) *p
= SysAllocStringLen(NULL
, 0);
1058 FIXME("libxslt headers were not found at compile time\n");
1063 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1068 if (!query
|| !nodes
) return E_INVALIDARG
;
1070 str
= xmlchar_from_wchar(query
);
1071 hr
= create_selection(This
->node
, str
, nodes
);
1077 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1079 IXMLDOMNodeList
*list
;
1082 hr
= node_select_nodes(This
, query
, &list
);
1085 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1086 IXMLDOMNodeList_Release(list
);
1091 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1093 xmlNsPtr ns
= This
->node
->ns
;
1096 return E_INVALIDARG
;
1098 *namespaceURI
= NULL
;
1101 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1103 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1105 return *namespaceURI
? S_OK
: S_FALSE
;
1108 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1110 xmlNsPtr ns
= This
->node
->ns
;
1112 if (!prefix
) return E_INVALIDARG
;
1116 if (ns
&& ns
->prefix
)
1117 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1119 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1121 return *prefix
? S_OK
: S_FALSE
;
1124 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1126 if (!name
) return E_INVALIDARG
;
1128 *name
= bstr_from_xmlChar(This
->node
->name
);
1129 if (!*name
) return E_OUTOFMEMORY
;
1131 TRACE("returning %s\n", debugstr_w(*name
));
1136 /* _private field holds a number of COM instances spawned from this libxml2 node */
1137 static void xmlnode_add_ref(xmlNodePtr node
)
1139 if (node
->type
== XML_DOCUMENT_NODE
) return;
1140 InterlockedIncrement((LONG
*)&node
->_private
);
1143 static void xmlnode_release(xmlNodePtr node
)
1145 if (node
->type
== XML_DOCUMENT_NODE
) return;
1146 InterlockedDecrement((LONG
*)&node
->_private
);
1149 void destroy_xmlnode(xmlnode
*This
)
1153 xmlnode_release(This
->node
);
1154 xmldoc_release(This
->node
->doc
);
1156 release_dispex(&This
->dispex
);
1159 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1163 xmlnode_add_ref(node
);
1164 xmldoc_add_ref(node
->doc
);
1168 This
->iface
= node_iface
;
1169 This
->parent
= NULL
;
1171 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1176 IXMLDOMNode IXMLDOMNode_iface
;
1180 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1182 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1185 static HRESULT WINAPI
unknode_QueryInterface(
1190 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1192 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1194 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1196 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1197 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1198 *ppvObject
= &This
->IXMLDOMNode_iface
;
1199 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1200 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1202 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1204 return E_NOINTERFACE
;
1207 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1211 static ULONG WINAPI
unknode_AddRef(
1212 IXMLDOMNode
*iface
)
1214 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1216 return InterlockedIncrement(&This
->ref
);
1219 static ULONG WINAPI
unknode_Release(
1220 IXMLDOMNode
*iface
)
1222 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1225 ref
= InterlockedDecrement( &This
->ref
);
1227 destroy_xmlnode(&This
->node
);
1234 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1238 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1240 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1247 static HRESULT WINAPI
unknode_GetTypeInfo(
1251 ITypeInfo
** ppTInfo
)
1253 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1256 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1258 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1263 static HRESULT WINAPI
unknode_GetIDsOfNames(
1266 LPOLESTR
* rgszNames
,
1271 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1273 ITypeInfo
*typeinfo
;
1276 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1279 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1280 return E_INVALIDARG
;
1282 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1285 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1286 ITypeInfo_Release(typeinfo
);
1292 static HRESULT WINAPI
unknode_Invoke(
1294 DISPID dispIdMember
,
1298 DISPPARAMS
* pDispParams
,
1299 VARIANT
* pVarResult
,
1300 EXCEPINFO
* pExcepInfo
,
1303 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1304 ITypeInfo
*typeinfo
;
1307 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1308 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1310 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1313 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1314 pVarResult
, pExcepInfo
, puArgErr
);
1315 ITypeInfo_Release(typeinfo
);
1321 static HRESULT WINAPI
unknode_get_nodeName(
1325 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1327 FIXME("(%p)->(%p)\n", This
, p
);
1329 return node_get_nodeName(&This
->node
, p
);
1332 static HRESULT WINAPI
unknode_get_nodeValue(
1336 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1338 FIXME("(%p)->(%p)\n", This
, value
);
1341 return E_INVALIDARG
;
1343 V_VT(value
) = VT_NULL
;
1347 static HRESULT WINAPI
unknode_put_nodeValue(
1351 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1352 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1356 static HRESULT WINAPI
unknode_get_nodeType(
1358 DOMNodeType
* domNodeType
)
1360 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1362 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1364 *domNodeType
= This
->node
.node
->type
;
1368 static HRESULT WINAPI
unknode_get_parentNode(
1370 IXMLDOMNode
** parent
)
1372 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1373 FIXME("(%p)->(%p)\n", This
, parent
);
1374 if (!parent
) return E_INVALIDARG
;
1379 static HRESULT WINAPI
unknode_get_childNodes(
1381 IXMLDOMNodeList
** outList
)
1383 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1385 TRACE("(%p)->(%p)\n", This
, outList
);
1387 return node_get_child_nodes(&This
->node
, outList
);
1390 static HRESULT WINAPI
unknode_get_firstChild(
1392 IXMLDOMNode
** domNode
)
1394 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1396 TRACE("(%p)->(%p)\n", This
, domNode
);
1398 return node_get_first_child(&This
->node
, domNode
);
1401 static HRESULT WINAPI
unknode_get_lastChild(
1403 IXMLDOMNode
** domNode
)
1405 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1407 TRACE("(%p)->(%p)\n", This
, domNode
);
1409 return node_get_last_child(&This
->node
, domNode
);
1412 static HRESULT WINAPI
unknode_get_previousSibling(
1414 IXMLDOMNode
** domNode
)
1416 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1418 TRACE("(%p)->(%p)\n", This
, domNode
);
1420 return node_get_previous_sibling(&This
->node
, domNode
);
1423 static HRESULT WINAPI
unknode_get_nextSibling(
1425 IXMLDOMNode
** domNode
)
1427 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1429 TRACE("(%p)->(%p)\n", This
, domNode
);
1431 return node_get_next_sibling(&This
->node
, domNode
);
1434 static HRESULT WINAPI
unknode_get_attributes(
1436 IXMLDOMNamedNodeMap
** attributeMap
)
1438 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1440 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1442 return return_null_ptr((void**)attributeMap
);
1445 static HRESULT WINAPI
unknode_insertBefore(
1447 IXMLDOMNode
* newNode
, VARIANT refChild
,
1448 IXMLDOMNode
** outOldNode
)
1450 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1452 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1454 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1457 static HRESULT WINAPI
unknode_replaceChild(
1459 IXMLDOMNode
* newNode
,
1460 IXMLDOMNode
* oldNode
,
1461 IXMLDOMNode
** outOldNode
)
1463 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1465 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1467 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1470 static HRESULT WINAPI
unknode_removeChild(
1472 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1474 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1475 return node_remove_child(&This
->node
, domNode
, oldNode
);
1478 static HRESULT WINAPI
unknode_appendChild(
1480 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1482 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1483 return node_append_child(&This
->node
, newNode
, outNewNode
);
1486 static HRESULT WINAPI
unknode_hasChildNodes(
1488 VARIANT_BOOL
* pbool
)
1490 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1491 return node_has_childnodes(&This
->node
, pbool
);
1494 static HRESULT WINAPI
unknode_get_ownerDocument(
1496 IXMLDOMDocument
** domDocument
)
1498 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1499 return node_get_owner_doc(&This
->node
, domDocument
);
1502 static HRESULT WINAPI
unknode_cloneNode(
1504 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1506 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1507 return node_clone(&This
->node
, pbool
, outNode
);
1510 static HRESULT WINAPI
unknode_get_nodeTypeString(
1514 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1516 FIXME("(%p)->(%p)\n", This
, p
);
1518 return node_get_nodeName(&This
->node
, p
);
1521 static HRESULT WINAPI
unknode_get_text(
1525 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1526 return node_get_text(&This
->node
, p
);
1529 static HRESULT WINAPI
unknode_put_text(
1533 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1534 return node_put_text(&This
->node
, p
);
1537 static HRESULT WINAPI
unknode_get_specified(
1539 VARIANT_BOOL
* isSpecified
)
1541 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1542 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
1543 *isSpecified
= VARIANT_TRUE
;
1547 static HRESULT WINAPI
unknode_get_definition(
1549 IXMLDOMNode
** definitionNode
)
1551 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1552 FIXME("(%p)->(%p)\n", This
, definitionNode
);
1556 static HRESULT WINAPI
unknode_get_nodeTypedValue(
1560 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1561 FIXME("(%p)->(%p)\n", This
, var1
);
1562 return return_null_var(var1
);
1565 static HRESULT WINAPI
unknode_put_nodeTypedValue(
1569 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1570 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
1574 static HRESULT WINAPI
unknode_get_dataType(
1578 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1579 TRACE("(%p)->(%p)\n", This
, var1
);
1580 return return_null_var(var1
);
1583 static HRESULT WINAPI
unknode_put_dataType(
1587 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1589 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
1592 return E_INVALIDARG
;
1597 static HRESULT WINAPI
unknode_get_xml(
1601 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1603 FIXME("(%p)->(%p)\n", This
, p
);
1605 return node_get_xml(&This
->node
, FALSE
, p
);
1608 static HRESULT WINAPI
unknode_transformNode(
1610 IXMLDOMNode
* domNode
, BSTR
* p
)
1612 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1613 return node_transform_node(&This
->node
, domNode
, p
);
1616 static HRESULT WINAPI
unknode_selectNodes(
1618 BSTR p
, IXMLDOMNodeList
** outList
)
1620 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1621 return node_select_nodes(&This
->node
, p
, outList
);
1624 static HRESULT WINAPI
unknode_selectSingleNode(
1626 BSTR p
, IXMLDOMNode
** outNode
)
1628 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1629 return node_select_singlenode(&This
->node
, p
, outNode
);
1632 static HRESULT WINAPI
unknode_get_parsed(
1634 VARIANT_BOOL
* isParsed
)
1636 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1637 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
1638 *isParsed
= VARIANT_TRUE
;
1642 static HRESULT WINAPI
unknode_get_namespaceURI(
1646 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1647 TRACE("(%p)->(%p)\n", This
, p
);
1648 return node_get_namespaceURI(&This
->node
, p
);
1651 static HRESULT WINAPI
unknode_get_prefix(
1655 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1656 return node_get_prefix(&This
->node
, p
);
1659 static HRESULT WINAPI
unknode_get_baseName(
1663 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1664 return node_get_base_name(&This
->node
, p
);
1667 static HRESULT WINAPI
unknode_transformNodeToObject(
1669 IXMLDOMNode
* domNode
, VARIANT var1
)
1671 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1672 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
1676 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
1678 unknode_QueryInterface
,
1681 unknode_GetTypeInfoCount
,
1682 unknode_GetTypeInfo
,
1683 unknode_GetIDsOfNames
,
1685 unknode_get_nodeName
,
1686 unknode_get_nodeValue
,
1687 unknode_put_nodeValue
,
1688 unknode_get_nodeType
,
1689 unknode_get_parentNode
,
1690 unknode_get_childNodes
,
1691 unknode_get_firstChild
,
1692 unknode_get_lastChild
,
1693 unknode_get_previousSibling
,
1694 unknode_get_nextSibling
,
1695 unknode_get_attributes
,
1696 unknode_insertBefore
,
1697 unknode_replaceChild
,
1698 unknode_removeChild
,
1699 unknode_appendChild
,
1700 unknode_hasChildNodes
,
1701 unknode_get_ownerDocument
,
1703 unknode_get_nodeTypeString
,
1706 unknode_get_specified
,
1707 unknode_get_definition
,
1708 unknode_get_nodeTypedValue
,
1709 unknode_put_nodeTypedValue
,
1710 unknode_get_dataType
,
1711 unknode_put_dataType
,
1713 unknode_transformNode
,
1714 unknode_selectNodes
,
1715 unknode_selectSingleNode
,
1717 unknode_get_namespaceURI
,
1719 unknode_get_baseName
,
1720 unknode_transformNodeToObject
1723 IXMLDOMNode
*create_node( xmlNodePtr node
)
1732 TRACE("type %d\n", node
->type
);
1735 case XML_ELEMENT_NODE
:
1736 pUnk
= create_element( node
);
1738 case XML_ATTRIBUTE_NODE
:
1739 pUnk
= create_attribute( node
);
1742 pUnk
= create_text( node
);
1744 case XML_CDATA_SECTION_NODE
:
1745 pUnk
= create_cdata( node
);
1747 case XML_ENTITY_REF_NODE
:
1748 pUnk
= create_doc_entity_ref( node
);
1751 pUnk
= create_pi( node
);
1753 case XML_COMMENT_NODE
:
1754 pUnk
= create_comment( node
);
1756 case XML_DOCUMENT_NODE
:
1757 pUnk
= create_domdoc( node
);
1759 case XML_DOCUMENT_FRAG_NODE
:
1760 pUnk
= create_doc_fragment( node
);
1763 pUnk
= create_doc_type( node
);
1768 FIXME("only creating basic node for type %d\n", node
->type
);
1770 new_node
= heap_alloc(sizeof(unknode
));
1774 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
1776 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
1777 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
1781 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
1782 IUnknown_Release(pUnk
);
1783 if(FAILED(hr
)) return NULL
;