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
24 # include <libxml/HTMLtree.h>
25 # ifdef SONAME_LIBXSLT
26 # ifdef HAVE_LIBXSLT_PATTERN_H
27 # include <libxslt/pattern.h>
29 # ifdef HAVE_LIBXSLT_TRANSFORM_H
30 # include <libxslt/transform.h>
32 # include <libxslt/xsltutils.h>
33 # include <libxslt/xsltInternals.h>
40 extern void* libxslt_handle
;
41 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
42 MAKE_FUNCPTR(xsltApplyStylesheet
);
43 MAKE_FUNCPTR(xsltCleanupGlobals
);
44 MAKE_FUNCPTR(xsltFreeStylesheet
);
45 MAKE_FUNCPTR(xsltParseStylesheetDoc
);
49 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
51 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
57 This
= get_node_obj( iface
);
58 if ( !This
|| !This
->node
)
60 if ( type
&& This
->node
->type
!= type
)
65 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
67 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
68 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
73 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
76 /* common ISupportErrorInfo implementation */
78 ISupportErrorInfo ISupportErrorInfo_iface
;
84 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
86 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
89 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
91 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
92 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
96 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
98 ISupportErrorInfo_AddRef(iface
);
102 return E_NOINTERFACE
;
105 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
107 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
108 ULONG ref
= InterlockedIncrement(&This
->ref
);
109 TRACE("(%p)->(%d)\n", This
, ref
);
113 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
115 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
116 LONG ref
= InterlockedDecrement(&This
->ref
);
118 TRACE("(%p)->(%d)\n", This
, ref
);
126 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
128 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
129 enum tid_t
const *tid
;
131 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
134 while (*tid
!= NULL_tid
)
136 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
144 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
145 SupportErrorInfo_QueryInterface
,
146 SupportErrorInfo_AddRef
,
147 SupportErrorInfo_Release
,
148 SupportErrorInfo_InterfaceSupportsErrorInfo
151 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
153 SupportErrorInfo
*This
;
155 This
= heap_alloc(sizeof(*This
));
156 if (!This
) return E_OUTOFMEMORY
;
158 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
162 *obj
= &This
->ISupportErrorInfo_iface
;
167 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
172 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
173 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
174 return SUCCEEDED(hres
) ? obj
: NULL
;
177 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
185 hr
= node_get_base_name(This
, &base
);
186 if (hr
!= S_OK
) return hr
;
188 hr
= node_get_prefix(This
, &prefix
);
191 static const WCHAR colW
= ':';
195 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
196 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
197 ptr
+= SysStringLen(prefix
);
198 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
199 memcpy(ptr
, base
, SysStringByteLen(base
));
202 SysFreeString(prefix
);
210 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
217 content
= xmlNodeGetContent(This
->node
);
218 V_VT(value
) = VT_BSTR
;
219 V_BSTR(value
) = bstr_from_xmlChar( content
);
222 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
226 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
230 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
231 str
= xmlchar_from_wchar(value
);
233 return E_OUTOFMEMORY
;
235 xmlNodeSetContent(This
->node
, str
);
240 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
242 xmlChar
*str
, *escaped
;
244 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
245 str
= xmlchar_from_wchar(value
);
247 return E_OUTOFMEMORY
;
249 escaped
= xmlEncodeSpecialChars(NULL
, str
);
253 return E_OUTOFMEMORY
;
256 xmlNodeSetContent(This
->node
, escaped
);
264 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
268 if (V_VT(value
) != VT_BSTR
)
270 VARIANT string_value
;
272 VariantInit(&string_value
);
273 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
275 WARN("Couldn't convert to VT_BSTR\n");
279 hr
= node_set_content(This
, V_BSTR(&string_value
));
280 VariantClear(&string_value
);
283 hr
= node_set_content(This
, V_BSTR(value
));
288 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
292 if (V_VT(value
) != VT_BSTR
)
294 VARIANT string_value
;
296 VariantInit(&string_value
);
297 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
299 WARN("Couldn't convert to VT_BSTR\n");
303 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
304 VariantClear(&string_value
);
307 hr
= node_set_content_escaped(This
, V_BSTR(value
));
312 static HRESULT
get_node(
318 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
323 /* if we don't have a doc, use our parent. */
324 if(node
&& !node
->doc
&& node
->parent
)
325 node
->doc
= node
->parent
->doc
;
327 *out
= create_node( node
);
333 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
335 return get_node( This
, "parent", This
->node
->parent
, parent
);
338 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
343 *ret
= create_children_nodelist(This
->node
);
345 return E_OUTOFMEMORY
;
350 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
352 return get_node(This
, "firstChild", This
->node
->children
, ret
);
355 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
357 return get_node(This
, "lastChild", This
->node
->last
, ret
);
360 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
362 return get_node(This
, "previous", This
->node
->prev
, ret
);
365 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
367 return get_node(This
, "next", This
->node
->next
, ret
);
370 static int node_get_inst_cnt(xmlNodePtr node
)
372 int ret
= *(LONG
*)&node
->_private
;
375 /* add attribute counts */
376 if (node
->type
== XML_ELEMENT_NODE
)
378 xmlAttrPtr prop
= node
->properties
;
382 ret
+= node_get_inst_cnt((xmlNodePtr
)prop
);
387 /* add children counts */
388 child
= node
->children
;
391 ret
+= node_get_inst_cnt(child
);
398 int xmlnode_get_inst_cnt(xmlnode
*node
)
400 return node_get_inst_cnt(node
->node
);
403 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
406 IXMLDOMNode
*before
= NULL
;
415 node_obj
= get_node_obj(new_child
);
416 if(!node_obj
) return E_FAIL
;
418 switch(V_VT(ref_child
))
426 if (V_UNKNOWN(ref_child
))
428 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
429 if(FAILED(hr
)) return hr
;
434 FIXME("refChild var type %x\n", V_VT(ref_child
));
438 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
440 if(!node_obj
->node
->parent
)
441 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
442 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
444 refcount
= xmlnode_get_inst_cnt(node_obj
);
448 xmlnode
*before_node_obj
= get_node_obj(before
);
449 IXMLDOMNode_Release(before
);
450 if(!before_node_obj
) return E_FAIL
;
452 /* unlink from current parent first */
455 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
456 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
459 doc
= node_obj
->node
->doc
;
461 /* refs count including subtree */
462 if (doc
!= before_node_obj
->node
->doc
)
463 refcount
= xmlnode_get_inst_cnt(node_obj
);
465 if (refcount
) xmldoc_add_refs(before_node_obj
->node
->doc
, refcount
);
466 xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
467 if (refcount
) xmldoc_release_refs(doc
, refcount
);
468 node_obj
->parent
= This
->parent
;
472 /* unlink from current parent first */
475 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
476 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
478 doc
= node_obj
->node
->doc
;
480 if (doc
!= This
->node
->doc
)
481 refcount
= xmlnode_get_inst_cnt(node_obj
);
483 if (refcount
) xmldoc_add_refs(This
->node
->doc
, refcount
);
484 /* xmlAddChild doesn't unlink node from previous parent */
485 xmlUnlinkNode(node_obj
->node
);
486 xmlAddChild(This
->node
, node_obj
->node
);
487 if (refcount
) xmldoc_release_refs(doc
, refcount
);
488 node_obj
->parent
= This
->iface
;
493 IXMLDOMNode_AddRef(new_child
);
501 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
504 xmlnode
*old_child
, *new_child
;
505 xmlDocPtr leaving_doc
;
506 xmlNode
*my_ancestor
;
509 /* Do not believe any documentation telling that newChild == NULL
510 means removal. It does certainly *not* apply to msxml3! */
511 if(!newChild
|| !oldChild
)
517 old_child
= get_node_obj(oldChild
);
518 if(!old_child
) return E_FAIL
;
520 if(old_child
->node
->parent
!= This
->node
)
522 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
526 new_child
= get_node_obj(newChild
);
527 if(!new_child
) return E_FAIL
;
529 my_ancestor
= This
->node
;
532 if(my_ancestor
== new_child
->node
)
534 WARN("tried to create loop\n");
537 my_ancestor
= my_ancestor
->parent
;
540 if(!new_child
->node
->parent
)
541 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
542 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
544 leaving_doc
= new_child
->node
->doc
;
546 if (leaving_doc
!= old_child
->node
->doc
)
547 refcount
= xmlnode_get_inst_cnt(new_child
);
549 if (refcount
) xmldoc_add_refs(old_child
->node
->doc
, refcount
);
550 xmlReplaceNode(old_child
->node
, new_child
->node
);
551 if (refcount
) xmldoc_release_refs(leaving_doc
, refcount
);
552 new_child
->parent
= old_child
->parent
;
553 old_child
->parent
= NULL
;
555 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
559 IXMLDOMNode_AddRef(oldChild
);
566 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
570 if(!child
) return E_INVALIDARG
;
575 child_node
= get_node_obj(child
);
576 if(!child_node
) return E_FAIL
;
578 if(child_node
->node
->parent
!= This
->node
)
580 WARN("childNode %p is not a child of %p\n", child
, This
);
584 xmlUnlinkNode(child_node
->node
);
585 child_node
->parent
= NULL
;
586 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
590 IXMLDOMNode_AddRef(child
);
597 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
603 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
604 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
605 if (outChild
) *outChild
= NULL
;
610 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
613 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
615 if (!ret
) return E_INVALIDARG
;
617 if (!This
->node
->children
)
619 *ret
= VARIANT_FALSE
;
627 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
629 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
632 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
637 if(!cloneNode
) return E_INVALIDARG
;
639 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
642 xmlSetTreeDoc(clone
, This
->node
->doc
);
643 xmldoc_add_orphan(clone
->doc
, clone
);
645 node
= create_node(clone
);
648 ERR("Copy failed\n");
649 xmldoc_remove_orphan(clone
->doc
, clone
);
658 ERR("Copy failed\n");
665 static inline xmlChar
* trim_whitespace(xmlChar
* str
)
673 while (*ret
&& isspace(*ret
))
675 len
= xmlStrlen(ret
);
677 while (isspace(ret
[len
-1])) --len
;
679 ret
= xmlStrndup(ret
, len
);
684 static xmlChar
* do_get_text(xmlNodePtr node
)
688 BOOL preserving
= is_preserving_whitespace(node
);
692 str
= xmlNodeGetContent(node
);
696 xmlElementType prev_type
= XML_TEXT_NODE
;
698 str
= xmlStrdup(BAD_CAST
"");
699 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
703 case XML_ELEMENT_NODE
:
704 tmp
= do_get_text(child
);
707 case XML_CDATA_SECTION_NODE
:
708 case XML_ENTITY_REF_NODE
:
709 case XML_ENTITY_NODE
:
710 tmp
= xmlNodeGetContent(child
);
721 if (prev_type
== XML_ELEMENT_NODE
&& child
->type
== XML_ELEMENT_NODE
)
722 str
= xmlStrcat(str
, BAD_CAST
" ");
723 str
= xmlStrcat(str
, tmp
);
724 prev_type
= child
->type
;
733 case XML_ELEMENT_NODE
:
735 case XML_ENTITY_REF_NODE
:
736 case XML_ENTITY_NODE
:
737 case XML_DOCUMENT_NODE
:
738 case XML_DOCUMENT_FRAG_NODE
:
740 str
= trim_whitespace(str
);
749 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
754 if (!text
) return E_INVALIDARG
;
756 content
= do_get_text(This
->node
);
759 str
= bstr_from_xmlChar(content
);
763 /* Always return a string. */
764 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
766 TRACE("%p %s\n", This
, debugstr_w(str
) );
772 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
776 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
778 str
= xmlchar_from_wchar(text
);
780 /* Escape the string. */
781 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
784 xmlNodeSetContent(This
->node
, str2
);
790 BSTR
EnsureCorrectEOL(BSTR sInput
)
797 nLen
= SysStringLen(sInput
);
798 /* Count line endings */
799 for(i
=0; i
< nLen
; i
++)
801 if(sInput
[i
] == '\n')
805 TRACE("len=%d, num=%d\n", nLen
, nNum
);
807 /* Add linefeed as needed */
811 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
812 for(i
=0; i
< nLen
; i
++)
814 if(sInput
[i
] == '\n')
816 sNew
[i
+nPlace
] = '\r';
819 sNew
[i
+nPlace
] = sInput
[i
];
822 SysFreeString(sInput
);
829 TRACE("len %d\n", SysStringLen(sNew
));
835 * We are trying to replicate the same behaviour as msxml by converting
836 * line endings to \r\n and using indents as \t. The problem is that msxml
837 * only formats nodes that have a line ending. Using libxml we cannot
838 * reproduce behaviour exactly.
841 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
843 xmlBufferPtr xml_buf
;
852 xml_buf
= xmlBufferCreate();
854 return E_OUTOFMEMORY
;
856 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
858 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
860 const xmlChar
*buf_content
;
863 /* Attribute Nodes return a space in front of their name */
864 buf_content
= xmlBufferContent(xml_buf
);
866 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
868 content
= EnsureCorrectEOL(content
);
872 *ret
= SysAllocStringLen(NULL
, 0);
875 xmlBufferFree(xml_buf
);
876 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
877 return *ret
? S_OK
: E_OUTOFMEMORY
;
880 /* duplicates xmlBufferWriteQuotedString() logic */
881 static void xml_write_quotedstring(xmlOutputBufferPtr buf
, const xmlChar
*string
)
883 const xmlChar
*cur
, *base
;
885 if (xmlStrchr(string
, '\"'))
887 if (xmlStrchr(string
, '\''))
889 xmlOutputBufferWrite(buf
, 1, "\"");
897 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
898 xmlOutputBufferWrite(buf
, 6, """);
906 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
907 xmlOutputBufferWrite(buf
, 1, "\"");
911 xmlOutputBufferWrite(buf
, 1, "\'");
912 xmlOutputBufferWriteString(buf
, (const char*)string
);
913 xmlOutputBufferWrite(buf
, 1, "\'");
918 xmlOutputBufferWrite(buf
, 1, "\"");
919 xmlOutputBufferWriteString(buf
, (const char*)string
);
920 xmlOutputBufferWrite(buf
, 1, "\"");
924 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
926 xmlDtdPtr cur
= doc
->intSubset
;
928 xmlOutputBufferWriteString(buf
, "<!DOCTYPE ");
929 xmlOutputBufferWriteString(buf
, (const char *)cur
->name
);
932 xmlOutputBufferWriteString(buf
, " PUBLIC ");
933 xml_write_quotedstring(buf
, cur
->ExternalID
);
936 xmlOutputBufferWriteString(buf
, " ");
937 xml_write_quotedstring(buf
, cur
->SystemID
);
940 else if (cur
->SystemID
)
942 xmlOutputBufferWriteString(buf
, " SYSTEM ");
943 xml_write_quotedstring(buf
, cur
->SystemID
);
945 xmlOutputBufferWriteString(buf
, ">\n");
948 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
952 /* force HTML output */
954 doc
->type
= XML_HTML_DOCUMENT_NODE
;
956 htmldtd_dumpcontent(buf
, doc
);
959 xmlNodePtr cur
= doc
->children
;
963 htmlNodeDumpFormatOutput(buf
, doc
, cur
, NULL
, 1);
971 static const xmlChar
*get_output_buffer_content(xmlOutputBufferPtr output
)
973 #ifdef LIBXML2_NEW_BUFFER
974 return xmlOutputBufferGetContent(output
);
976 return xmlBufferContent(output
->buffer
);
980 HRESULT
node_transform_node(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
982 #ifdef SONAME_LIBXSLT
983 xsltStylesheetPtr xsltSS
;
986 if (!libxslt_handle
) return E_NOTIMPL
;
987 if (!stylesheet
|| !p
) return E_INVALIDARG
;
991 sheet
= get_node_obj(stylesheet
);
992 if(!sheet
) return E_FAIL
;
994 xsltSS
= pxsltParseStylesheetDoc(sheet
->node
->doc
);
997 xmlDocPtr result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1000 const xmlChar
*content
;
1002 if(result
->type
== XML_HTML_DOCUMENT_NODE
)
1004 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(NULL
);
1007 htmldoc_dumpcontent(output
, result
->doc
);
1008 content
= get_output_buffer_content(output
);
1009 *p
= bstr_from_xmlChar(content
);
1010 xmlOutputBufferClose(output
);
1015 xmlBufferPtr buf
= xmlBufferCreate();
1018 int size
= xmlNodeDump(buf
, NULL
, (xmlNodePtr
)result
, 0, 0);
1021 content
= xmlBufferContent(buf
);
1022 *p
= bstr_from_xmlChar(content
);
1029 /* libxslt "helpfully" frees the XML document the stylesheet was
1030 generated from, too */
1032 pxsltFreeStylesheet(xsltSS
);
1035 if(!*p
) *p
= SysAllocStringLen(NULL
, 0);
1039 FIXME("libxslt headers were not found at compile time\n");
1044 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1049 if (!query
|| !nodes
) return E_INVALIDARG
;
1051 str
= xmlchar_from_wchar(query
);
1052 hr
= create_selection(This
->node
, str
, nodes
);
1058 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1060 IXMLDOMNodeList
*list
;
1063 hr
= node_select_nodes(This
, query
, &list
);
1066 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1067 IXMLDOMNodeList_Release(list
);
1072 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1074 xmlNsPtr ns
= This
->node
->ns
;
1077 return E_INVALIDARG
;
1079 *namespaceURI
= NULL
;
1082 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1084 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1086 return *namespaceURI
? S_OK
: S_FALSE
;
1089 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1091 xmlNsPtr ns
= This
->node
->ns
;
1093 if (!prefix
) return E_INVALIDARG
;
1097 if (ns
&& ns
->prefix
)
1098 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1100 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1102 return *prefix
? S_OK
: S_FALSE
;
1105 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1107 if (!name
) return E_INVALIDARG
;
1109 *name
= bstr_from_xmlChar(This
->node
->name
);
1110 if (!*name
) return E_OUTOFMEMORY
;
1112 TRACE("returning %s\n", debugstr_w(*name
));
1117 /* _private field holds a number of COM instances spawned from this libxml2 node */
1118 static void xmlnode_add_ref(xmlNodePtr node
)
1120 if (node
->type
== XML_DOCUMENT_NODE
) return;
1121 InterlockedIncrement((LONG
*)&node
->_private
);
1124 static void xmlnode_release(xmlNodePtr node
)
1126 if (node
->type
== XML_DOCUMENT_NODE
) return;
1127 InterlockedDecrement((LONG
*)&node
->_private
);
1130 void destroy_xmlnode(xmlnode
*This
)
1134 xmlnode_release(This
->node
);
1135 xmldoc_release(This
->node
->doc
);
1137 release_dispex(&This
->dispex
);
1140 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1144 xmlnode_add_ref(node
);
1145 xmldoc_add_ref(node
->doc
);
1149 This
->iface
= node_iface
;
1150 This
->parent
= NULL
;
1152 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1157 IXMLDOMNode IXMLDOMNode_iface
;
1161 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1163 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1166 static HRESULT WINAPI
unknode_QueryInterface(
1171 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1173 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1175 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1177 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1178 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1179 *ppvObject
= &This
->IXMLDOMNode_iface
;
1180 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1181 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1183 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1185 return E_NOINTERFACE
;
1188 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1192 static ULONG WINAPI
unknode_AddRef(
1193 IXMLDOMNode
*iface
)
1195 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1197 return InterlockedIncrement(&This
->ref
);
1200 static ULONG WINAPI
unknode_Release(
1201 IXMLDOMNode
*iface
)
1203 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1206 ref
= InterlockedDecrement( &This
->ref
);
1208 destroy_xmlnode(&This
->node
);
1215 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1219 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1221 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1228 static HRESULT WINAPI
unknode_GetTypeInfo(
1232 ITypeInfo
** ppTInfo
)
1234 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1237 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1239 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1244 static HRESULT WINAPI
unknode_GetIDsOfNames(
1247 LPOLESTR
* rgszNames
,
1252 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1254 ITypeInfo
*typeinfo
;
1257 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1260 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1261 return E_INVALIDARG
;
1263 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1266 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1267 ITypeInfo_Release(typeinfo
);
1273 static HRESULT WINAPI
unknode_Invoke(
1275 DISPID dispIdMember
,
1279 DISPPARAMS
* pDispParams
,
1280 VARIANT
* pVarResult
,
1281 EXCEPINFO
* pExcepInfo
,
1284 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1285 ITypeInfo
*typeinfo
;
1288 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1289 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1291 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1294 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1295 pVarResult
, pExcepInfo
, puArgErr
);
1296 ITypeInfo_Release(typeinfo
);
1302 static HRESULT WINAPI
unknode_get_nodeName(
1306 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1308 FIXME("(%p)->(%p)\n", This
, p
);
1310 return node_get_nodeName(&This
->node
, p
);
1313 static HRESULT WINAPI
unknode_get_nodeValue(
1317 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1319 FIXME("(%p)->(%p)\n", This
, value
);
1322 return E_INVALIDARG
;
1324 V_VT(value
) = VT_NULL
;
1328 static HRESULT WINAPI
unknode_put_nodeValue(
1332 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1333 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1337 static HRESULT WINAPI
unknode_get_nodeType(
1339 DOMNodeType
* domNodeType
)
1341 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1343 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1345 *domNodeType
= This
->node
.node
->type
;
1349 static HRESULT WINAPI
unknode_get_parentNode(
1351 IXMLDOMNode
** parent
)
1353 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1354 FIXME("(%p)->(%p)\n", This
, parent
);
1355 if (!parent
) return E_INVALIDARG
;
1360 static HRESULT WINAPI
unknode_get_childNodes(
1362 IXMLDOMNodeList
** outList
)
1364 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1366 TRACE("(%p)->(%p)\n", This
, outList
);
1368 return node_get_child_nodes(&This
->node
, outList
);
1371 static HRESULT WINAPI
unknode_get_firstChild(
1373 IXMLDOMNode
** domNode
)
1375 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1377 TRACE("(%p)->(%p)\n", This
, domNode
);
1379 return node_get_first_child(&This
->node
, domNode
);
1382 static HRESULT WINAPI
unknode_get_lastChild(
1384 IXMLDOMNode
** domNode
)
1386 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1388 TRACE("(%p)->(%p)\n", This
, domNode
);
1390 return node_get_last_child(&This
->node
, domNode
);
1393 static HRESULT WINAPI
unknode_get_previousSibling(
1395 IXMLDOMNode
** domNode
)
1397 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1399 TRACE("(%p)->(%p)\n", This
, domNode
);
1401 return node_get_previous_sibling(&This
->node
, domNode
);
1404 static HRESULT WINAPI
unknode_get_nextSibling(
1406 IXMLDOMNode
** domNode
)
1408 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1410 TRACE("(%p)->(%p)\n", This
, domNode
);
1412 return node_get_next_sibling(&This
->node
, domNode
);
1415 static HRESULT WINAPI
unknode_get_attributes(
1417 IXMLDOMNamedNodeMap
** attributeMap
)
1419 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1421 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1423 return return_null_ptr((void**)attributeMap
);
1426 static HRESULT WINAPI
unknode_insertBefore(
1428 IXMLDOMNode
* newNode
, VARIANT refChild
,
1429 IXMLDOMNode
** outOldNode
)
1431 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1433 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1435 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1438 static HRESULT WINAPI
unknode_replaceChild(
1440 IXMLDOMNode
* newNode
,
1441 IXMLDOMNode
* oldNode
,
1442 IXMLDOMNode
** outOldNode
)
1444 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1446 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1448 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1451 static HRESULT WINAPI
unknode_removeChild(
1453 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1455 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1456 return node_remove_child(&This
->node
, domNode
, oldNode
);
1459 static HRESULT WINAPI
unknode_appendChild(
1461 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1463 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1464 return node_append_child(&This
->node
, newNode
, outNewNode
);
1467 static HRESULT WINAPI
unknode_hasChildNodes(
1469 VARIANT_BOOL
* pbool
)
1471 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1472 return node_has_childnodes(&This
->node
, pbool
);
1475 static HRESULT WINAPI
unknode_get_ownerDocument(
1477 IXMLDOMDocument
** domDocument
)
1479 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1480 return node_get_owner_doc(&This
->node
, domDocument
);
1483 static HRESULT WINAPI
unknode_cloneNode(
1485 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1487 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1488 return node_clone(&This
->node
, pbool
, outNode
);
1491 static HRESULT WINAPI
unknode_get_nodeTypeString(
1495 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1497 FIXME("(%p)->(%p)\n", This
, p
);
1499 return node_get_nodeName(&This
->node
, p
);
1502 static HRESULT WINAPI
unknode_get_text(
1506 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1507 return node_get_text(&This
->node
, p
);
1510 static HRESULT WINAPI
unknode_put_text(
1514 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1515 return node_put_text(&This
->node
, p
);
1518 static HRESULT WINAPI
unknode_get_specified(
1520 VARIANT_BOOL
* isSpecified
)
1522 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1523 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
1524 *isSpecified
= VARIANT_TRUE
;
1528 static HRESULT WINAPI
unknode_get_definition(
1530 IXMLDOMNode
** definitionNode
)
1532 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1533 FIXME("(%p)->(%p)\n", This
, definitionNode
);
1537 static HRESULT WINAPI
unknode_get_nodeTypedValue(
1541 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1542 FIXME("(%p)->(%p)\n", This
, var1
);
1543 return return_null_var(var1
);
1546 static HRESULT WINAPI
unknode_put_nodeTypedValue(
1550 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1551 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
1555 static HRESULT WINAPI
unknode_get_dataType(
1559 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1560 TRACE("(%p)->(%p)\n", This
, var1
);
1561 return return_null_var(var1
);
1564 static HRESULT WINAPI
unknode_put_dataType(
1568 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1570 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
1573 return E_INVALIDARG
;
1578 static HRESULT WINAPI
unknode_get_xml(
1582 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1584 FIXME("(%p)->(%p)\n", This
, p
);
1586 return node_get_xml(&This
->node
, FALSE
, p
);
1589 static HRESULT WINAPI
unknode_transformNode(
1591 IXMLDOMNode
* domNode
, BSTR
* p
)
1593 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1594 return node_transform_node(&This
->node
, domNode
, p
);
1597 static HRESULT WINAPI
unknode_selectNodes(
1599 BSTR p
, IXMLDOMNodeList
** outList
)
1601 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1602 return node_select_nodes(&This
->node
, p
, outList
);
1605 static HRESULT WINAPI
unknode_selectSingleNode(
1607 BSTR p
, IXMLDOMNode
** outNode
)
1609 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1610 return node_select_singlenode(&This
->node
, p
, outNode
);
1613 static HRESULT WINAPI
unknode_get_parsed(
1615 VARIANT_BOOL
* isParsed
)
1617 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1618 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
1619 *isParsed
= VARIANT_TRUE
;
1623 static HRESULT WINAPI
unknode_get_namespaceURI(
1627 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1628 TRACE("(%p)->(%p)\n", This
, p
);
1629 return node_get_namespaceURI(&This
->node
, p
);
1632 static HRESULT WINAPI
unknode_get_prefix(
1636 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1637 return node_get_prefix(&This
->node
, p
);
1640 static HRESULT WINAPI
unknode_get_baseName(
1644 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1645 return node_get_base_name(&This
->node
, p
);
1648 static HRESULT WINAPI
unknode_transformNodeToObject(
1650 IXMLDOMNode
* domNode
, VARIANT var1
)
1652 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1653 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
1657 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
1659 unknode_QueryInterface
,
1662 unknode_GetTypeInfoCount
,
1663 unknode_GetTypeInfo
,
1664 unknode_GetIDsOfNames
,
1666 unknode_get_nodeName
,
1667 unknode_get_nodeValue
,
1668 unknode_put_nodeValue
,
1669 unknode_get_nodeType
,
1670 unknode_get_parentNode
,
1671 unknode_get_childNodes
,
1672 unknode_get_firstChild
,
1673 unknode_get_lastChild
,
1674 unknode_get_previousSibling
,
1675 unknode_get_nextSibling
,
1676 unknode_get_attributes
,
1677 unknode_insertBefore
,
1678 unknode_replaceChild
,
1679 unknode_removeChild
,
1680 unknode_appendChild
,
1681 unknode_hasChildNodes
,
1682 unknode_get_ownerDocument
,
1684 unknode_get_nodeTypeString
,
1687 unknode_get_specified
,
1688 unknode_get_definition
,
1689 unknode_get_nodeTypedValue
,
1690 unknode_put_nodeTypedValue
,
1691 unknode_get_dataType
,
1692 unknode_put_dataType
,
1694 unknode_transformNode
,
1695 unknode_selectNodes
,
1696 unknode_selectSingleNode
,
1698 unknode_get_namespaceURI
,
1700 unknode_get_baseName
,
1701 unknode_transformNodeToObject
1704 IXMLDOMNode
*create_node( xmlNodePtr node
)
1713 TRACE("type %d\n", node
->type
);
1716 case XML_ELEMENT_NODE
:
1717 pUnk
= create_element( node
);
1719 case XML_ATTRIBUTE_NODE
:
1720 pUnk
= create_attribute( node
);
1723 pUnk
= create_text( node
);
1725 case XML_CDATA_SECTION_NODE
:
1726 pUnk
= create_cdata( node
);
1728 case XML_ENTITY_REF_NODE
:
1729 pUnk
= create_doc_entity_ref( node
);
1732 pUnk
= create_pi( node
);
1734 case XML_COMMENT_NODE
:
1735 pUnk
= create_comment( node
);
1737 case XML_DOCUMENT_NODE
:
1738 pUnk
= create_domdoc( node
);
1740 case XML_DOCUMENT_FRAG_NODE
:
1741 pUnk
= create_doc_fragment( node
);
1744 pUnk
= create_doc_type( node
);
1749 FIXME("only creating basic node for type %d\n", node
->type
);
1751 new_node
= heap_alloc(sizeof(unknode
));
1755 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
1757 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
1758 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
1762 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
1763 IUnknown_Release(pUnk
);
1764 if(FAILED(hr
)) return NULL
;