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/imports.h>
33 # include <libxslt/variables.h>
34 # include <libxslt/xsltutils.h>
35 # include <libxslt/xsltInternals.h>
42 extern void* libxslt_handle
;
43 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
44 MAKE_FUNCPTR(xsltApplyStylesheet
);
45 MAKE_FUNCPTR(xsltApplyStylesheetUser
);
46 MAKE_FUNCPTR(xsltCleanupGlobals
);
47 MAKE_FUNCPTR(xsltFreeStylesheet
);
48 MAKE_FUNCPTR(xsltFreeTransformContext
);
49 MAKE_FUNCPTR(xsltNewTransformContext
);
50 MAKE_FUNCPTR(xsltNextImport
);
51 MAKE_FUNCPTR(xsltParseStylesheetDoc
);
52 MAKE_FUNCPTR(xsltQuoteUserParams
);
53 MAKE_FUNCPTR(xsltSaveResultTo
);
56 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
59 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
61 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
67 This
= get_node_obj( iface
);
68 if ( !This
|| !This
->node
)
70 if ( type
&& This
->node
->type
!= type
)
75 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
77 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
78 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
83 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
86 /* common ISupportErrorInfo implementation */
88 ISupportErrorInfo ISupportErrorInfo_iface
;
94 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
96 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
99 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
101 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
102 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
106 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
108 ISupportErrorInfo_AddRef(iface
);
112 return E_NOINTERFACE
;
115 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
117 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
118 ULONG ref
= InterlockedIncrement(&This
->ref
);
119 TRACE("(%p)->(%d)\n", This
, ref
);
123 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
125 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
126 LONG ref
= InterlockedDecrement(&This
->ref
);
128 TRACE("(%p)->(%d)\n", This
, ref
);
136 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
138 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
139 enum tid_t
const *tid
;
141 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
144 while (*tid
!= NULL_tid
)
146 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
154 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
155 SupportErrorInfo_QueryInterface
,
156 SupportErrorInfo_AddRef
,
157 SupportErrorInfo_Release
,
158 SupportErrorInfo_InterfaceSupportsErrorInfo
161 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
163 SupportErrorInfo
*This
;
165 This
= heap_alloc(sizeof(*This
));
166 if (!This
) return E_OUTOFMEMORY
;
168 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
172 *obj
= &This
->ISupportErrorInfo_iface
;
177 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
182 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
183 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
184 return SUCCEEDED(hres
) ? obj
: NULL
;
187 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
195 hr
= node_get_base_name(This
, &base
);
196 if (hr
!= S_OK
) return hr
;
198 hr
= node_get_prefix(This
, &prefix
);
201 static const WCHAR colW
= ':';
205 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
206 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
207 ptr
+= SysStringLen(prefix
);
208 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
209 memcpy(ptr
, base
, SysStringByteLen(base
));
212 SysFreeString(prefix
);
220 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
227 content
= xmlNodeGetContent(This
->node
);
228 V_VT(value
) = VT_BSTR
;
229 V_BSTR(value
) = bstr_from_xmlChar( content
);
232 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
236 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
240 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
241 str
= xmlchar_from_wchar(value
);
243 return E_OUTOFMEMORY
;
245 xmlNodeSetContent(This
->node
, str
);
250 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
252 xmlChar
*str
, *escaped
;
254 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
255 str
= xmlchar_from_wchar(value
);
257 return E_OUTOFMEMORY
;
259 escaped
= xmlEncodeSpecialChars(NULL
, str
);
263 return E_OUTOFMEMORY
;
266 xmlNodeSetContent(This
->node
, escaped
);
274 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
278 if (V_VT(value
) != VT_BSTR
)
280 VARIANT string_value
;
282 VariantInit(&string_value
);
283 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
285 WARN("Couldn't convert to VT_BSTR\n");
289 hr
= node_set_content(This
, V_BSTR(&string_value
));
290 VariantClear(&string_value
);
293 hr
= node_set_content(This
, V_BSTR(value
));
298 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
302 if (V_VT(value
) != VT_BSTR
)
304 VARIANT string_value
;
306 VariantInit(&string_value
);
307 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
309 WARN("Couldn't convert to VT_BSTR\n");
313 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
314 VariantClear(&string_value
);
317 hr
= node_set_content_escaped(This
, V_BSTR(value
));
322 static HRESULT
get_node(
328 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
333 /* if we don't have a doc, use our parent. */
334 if(node
&& !node
->doc
&& node
->parent
)
335 node
->doc
= node
->parent
->doc
;
337 *out
= create_node( node
);
343 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
345 return get_node( This
, "parent", This
->node
->parent
, parent
);
348 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
353 *ret
= create_children_nodelist(This
->node
);
355 return E_OUTOFMEMORY
;
360 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
362 return get_node(This
, "firstChild", This
->node
->children
, ret
);
365 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
367 return get_node(This
, "lastChild", This
->node
->last
, ret
);
370 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
372 return get_node(This
, "previous", This
->node
->prev
, ret
);
375 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
377 return get_node(This
, "next", This
->node
->next
, ret
);
380 static int node_get_inst_cnt(xmlNodePtr node
)
382 int ret
= *(LONG
*)&node
->_private
& NODE_PRIV_REFCOUNT_MASK
;
385 /* add attribute counts */
386 if (node
->type
== XML_ELEMENT_NODE
)
388 xmlAttrPtr prop
= node
->properties
;
392 ret
+= node_get_inst_cnt((xmlNodePtr
)prop
);
397 /* add children counts */
398 child
= node
->children
;
401 ret
+= node_get_inst_cnt(child
);
408 int xmlnode_get_inst_cnt(xmlnode
*node
)
410 return node_get_inst_cnt(node
->node
);
413 /* _private field holds a number of COM instances spawned from this libxml2 node
414 * most significant bits are used to store information about ignorrable whitespace nodes */
415 void xmlnode_add_ref(xmlNodePtr node
)
417 if (node
->type
== XML_DOCUMENT_NODE
) return;
418 InterlockedIncrement((LONG
*)&node
->_private
);
421 void xmlnode_release(xmlNodePtr node
)
423 if (node
->type
== XML_DOCUMENT_NODE
) return;
424 InterlockedDecrement((LONG
*)&node
->_private
);
427 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
430 IXMLDOMNode
*before
= NULL
;
439 node_obj
= get_node_obj(new_child
);
440 if(!node_obj
) return E_FAIL
;
442 switch(V_VT(ref_child
))
450 if (V_UNKNOWN(ref_child
))
452 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
453 if(FAILED(hr
)) return hr
;
458 FIXME("refChild var type %x\n", V_VT(ref_child
));
462 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
464 if(!node_obj
->node
->parent
)
465 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
466 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
468 refcount
= xmlnode_get_inst_cnt(node_obj
);
472 xmlnode
*before_node_obj
= get_node_obj(before
);
473 IXMLDOMNode_Release(before
);
474 if(!before_node_obj
) return E_FAIL
;
477 /* unlink from current parent first */
480 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
481 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
483 doc
= node_obj
->node
->doc
;
488 xmlnode
*before_node_obj
= get_node_obj(before
);
490 /* refs count including subtree */
491 if (doc
!= before_node_obj
->node
->doc
)
492 refcount
= xmlnode_get_inst_cnt(node_obj
);
494 if (refcount
) xmldoc_add_refs(before_node_obj
->node
->doc
, refcount
);
495 new_node
= xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
496 if (new_node
!= node_obj
->node
)
499 FIXME("referenced xmlNode was freed, expect crashes\n");
500 xmlnode_add_ref(new_node
);
501 node_obj
->node
= new_node
;
503 if (refcount
) xmldoc_release_refs(doc
, refcount
);
504 node_obj
->parent
= This
->parent
;
510 if (doc
!= This
->node
->doc
)
511 refcount
= xmlnode_get_inst_cnt(node_obj
);
513 if (refcount
) xmldoc_add_refs(This
->node
->doc
, refcount
);
514 /* xmlAddChild doesn't unlink node from previous parent */
515 xmlUnlinkNode(node_obj
->node
);
516 new_node
= xmlAddChild(This
->node
, node_obj
->node
);
517 if (new_node
!= node_obj
->node
)
520 FIXME("referenced xmlNode was freed, expect crashes\n");
521 xmlnode_add_ref(new_node
);
522 node_obj
->node
= new_node
;
524 if (refcount
) xmldoc_release_refs(doc
, refcount
);
525 node_obj
->parent
= This
->iface
;
530 IXMLDOMNode_AddRef(new_child
);
538 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
541 xmlnode
*old_child
, *new_child
;
542 xmlDocPtr leaving_doc
;
543 xmlNode
*my_ancestor
;
546 /* Do not believe any documentation telling that newChild == NULL
547 means removal. It does certainly *not* apply to msxml3! */
548 if(!newChild
|| !oldChild
)
554 old_child
= get_node_obj(oldChild
);
555 if(!old_child
) return E_FAIL
;
557 if(old_child
->node
->parent
!= This
->node
)
559 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
563 new_child
= get_node_obj(newChild
);
564 if(!new_child
) return E_FAIL
;
566 my_ancestor
= This
->node
;
569 if(my_ancestor
== new_child
->node
)
571 WARN("tried to create loop\n");
574 my_ancestor
= my_ancestor
->parent
;
577 if(!new_child
->node
->parent
)
578 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
579 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
581 leaving_doc
= new_child
->node
->doc
;
583 if (leaving_doc
!= old_child
->node
->doc
)
584 refcount
= xmlnode_get_inst_cnt(new_child
);
586 if (refcount
) xmldoc_add_refs(old_child
->node
->doc
, refcount
);
587 xmlReplaceNode(old_child
->node
, new_child
->node
);
588 if (refcount
) xmldoc_release_refs(leaving_doc
, refcount
);
589 new_child
->parent
= old_child
->parent
;
590 old_child
->parent
= NULL
;
592 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
596 IXMLDOMNode_AddRef(oldChild
);
603 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
607 if(!child
) return E_INVALIDARG
;
612 child_node
= get_node_obj(child
);
613 if(!child_node
) return E_FAIL
;
615 if(child_node
->node
->parent
!= This
->node
)
617 WARN("childNode %p is not a child of %p\n", child
, This
);
621 xmlUnlinkNode(child_node
->node
);
622 child_node
->parent
= NULL
;
623 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
627 IXMLDOMNode_AddRef(child
);
634 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
643 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
644 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
645 if (outChild
) *outChild
= NULL
;
650 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
653 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
655 if (!ret
) return E_INVALIDARG
;
657 if (!This
->node
->children
)
659 *ret
= VARIANT_FALSE
;
667 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
671 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
674 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
679 if(!cloneNode
) return E_INVALIDARG
;
681 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
684 xmlSetTreeDoc(clone
, This
->node
->doc
);
685 xmldoc_add_orphan(clone
->doc
, clone
);
687 node
= create_node(clone
);
690 ERR("Copy failed\n");
691 xmldoc_remove_orphan(clone
->doc
, clone
);
700 ERR("Copy failed\n");
707 static xmlChar
* do_get_text(xmlNodePtr node
, BOOL trim
, DWORD
*first
, DWORD
*last
, BOOL
*trail_ig_ws
)
711 BOOL preserving
= is_preserving_whitespace(node
);
718 str
= xmlNodeGetContent(node
);
719 *trail_ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
726 str
= xmlStrdup(BAD_CAST
"");
728 if (node
->type
!= XML_DOCUMENT_NODE
)
729 ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
730 *trail_ig_ws
= FALSE
;
732 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
736 case XML_ELEMENT_NODE
: {
737 DWORD node_first
, node_last
;
739 tmp
= do_get_text(child
, FALSE
, &node_first
, &node_last
, trail_ig_ws
);
741 if (node_first
!=-1 && pos
+node_first
<*first
)
742 *first
= pos
+node_first
;
743 if (node_last
&& pos
+node_last
>*last
)
744 *last
= pos
+node_last
;
748 tmp
= xmlNodeGetContent(child
);
749 if (!preserving
&& tmp
[0])
753 for (beg
= tmp
; *beg
; beg
++)
754 if (!isspace(*beg
)) break;
764 case XML_CDATA_SECTION_NODE
:
765 case XML_ENTITY_REF_NODE
:
766 case XML_ENTITY_NODE
:
767 tmp
= xmlNodeGetContent(child
);
774 if ((tmp
&& *tmp
) || child
->type
==XML_CDATA_SECTION_NODE
)
778 str
= xmlStrcat(str
, BAD_CAST
" ");
781 if (tmp
&& *tmp
) str
= xmlStrcat(str
, tmp
);
782 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
<*first
)
784 if (tmp
&& *tmp
) pos
+= xmlStrlen(tmp
);
785 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
>*last
)
789 if (tmp
) xmlFree(tmp
);
793 ig_ws
= *(DWORD
*)&child
->_private
& NODE_PRIV_TRAILING_IGNORABLE_WS
;
796 ig_ws
= *trail_ig_ws
;
797 *trail_ig_ws
= FALSE
;
800 *trail_ig_ws
= ig_ws
;
805 case XML_ELEMENT_NODE
:
807 case XML_ENTITY_REF_NODE
:
808 case XML_ENTITY_NODE
:
809 case XML_DOCUMENT_NODE
:
810 case XML_DOCUMENT_FRAG_NODE
:
811 if (trim
&& !preserving
)
819 for (ret
= str
; *ret
&& isspace(*ret
) && (*first
)--; ret
++)
820 if (*last
) (*last
)--;
821 for (len
= xmlStrlen(ret
)-1; len
>= 0 && len
>= *last
; len
--)
822 if(!isspace(ret
[len
])) break;
824 ret
= xmlStrndup(ret
, len
+1);
837 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
844 if (!text
) return E_INVALIDARG
;
846 content
= do_get_text(This
->node
, TRUE
, &first
, &last
, &tmp
);
849 str
= bstr_from_xmlChar(content
);
853 /* Always return a string. */
854 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
856 TRACE("%p %s\n", This
, debugstr_w(str
) );
862 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
866 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
868 str
= xmlchar_from_wchar(text
);
870 /* Escape the string. */
871 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
874 xmlNodeSetContent(This
->node
, str2
);
880 BSTR
EnsureCorrectEOL(BSTR sInput
)
887 nLen
= SysStringLen(sInput
);
888 /* Count line endings */
889 for(i
=0; i
< nLen
; i
++)
891 if(sInput
[i
] == '\n')
895 TRACE("len=%d, num=%d\n", nLen
, nNum
);
897 /* Add linefeed as needed */
901 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
902 for(i
=0; i
< nLen
; i
++)
904 if(sInput
[i
] == '\n')
906 sNew
[i
+nPlace
] = '\r';
909 sNew
[i
+nPlace
] = sInput
[i
];
912 SysFreeString(sInput
);
919 TRACE("len %d\n", SysStringLen(sNew
));
925 * We are trying to replicate the same behaviour as msxml by converting
926 * line endings to \r\n and using indents as \t. The problem is that msxml
927 * only formats nodes that have a line ending. Using libxml we cannot
928 * reproduce behaviour exactly.
931 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
933 xmlBufferPtr xml_buf
;
942 xml_buf
= xmlBufferCreate();
944 return E_OUTOFMEMORY
;
946 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
948 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
950 const xmlChar
*buf_content
;
953 /* Attribute Nodes return a space in front of their name */
954 buf_content
= xmlBufferContent(xml_buf
);
956 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
958 content
= EnsureCorrectEOL(content
);
962 *ret
= SysAllocStringLen(NULL
, 0);
965 xmlBufferFree(xml_buf
);
966 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
967 return *ret
? S_OK
: E_OUTOFMEMORY
;
970 #ifdef SONAME_LIBXSLT
972 /* duplicates xmlBufferWriteQuotedString() logic */
973 static void xml_write_quotedstring(xmlOutputBufferPtr buf
, const xmlChar
*string
)
975 const xmlChar
*cur
, *base
;
977 if (xmlStrchr(string
, '\"'))
979 if (xmlStrchr(string
, '\''))
981 xmlOutputBufferWrite(buf
, 1, "\"");
989 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
990 xmlOutputBufferWrite(buf
, 6, """);
998 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
999 xmlOutputBufferWrite(buf
, 1, "\"");
1003 xmlOutputBufferWrite(buf
, 1, "\'");
1004 xmlOutputBufferWriteString(buf
, (const char*)string
);
1005 xmlOutputBufferWrite(buf
, 1, "\'");
1010 xmlOutputBufferWrite(buf
, 1, "\"");
1011 xmlOutputBufferWriteString(buf
, (const char*)string
);
1012 xmlOutputBufferWrite(buf
, 1, "\"");
1016 static int XMLCALL
transform_to_stream_write(void *context
, const char *buffer
, int len
)
1019 HRESULT hr
= IStream_Write((IStream
*)context
, buffer
, len
, &written
);
1020 return hr
== S_OK
? written
: -1;
1023 /* Output for method "text" */
1024 static void transform_write_text(xmlDocPtr result
, xsltStylesheetPtr style
, xmlOutputBufferPtr output
)
1026 xmlNodePtr cur
= result
->children
;
1029 if (cur
->type
== XML_TEXT_NODE
)
1030 xmlOutputBufferWriteString(output
, (const char*)cur
->content
);
1032 /* skip to next node */
1035 if ((cur
->children
->type
!= XML_ENTITY_DECL
) &&
1036 (cur
->children
->type
!= XML_ENTITY_REF_NODE
) &&
1037 (cur
->children
->type
!= XML_ENTITY_NODE
))
1039 cur
= cur
->children
;
1054 if (cur
== (xmlNodePtr
) style
->doc
) {
1066 #undef XSLT_GET_IMPORT_PTR
1067 #define XSLT_GET_IMPORT_PTR(res, style, name) { \
1068 xsltStylesheetPtr st = style; \
1070 while (st != NULL) { \
1071 if (st->name != NULL) { res = st->name; break; } \
1072 st = pxsltNextImport(st); \
1075 #undef XSLT_GET_IMPORT_INT
1076 #define XSLT_GET_IMPORT_INT(res, style, name) { \
1077 xsltStylesheetPtr st = style; \
1079 while (st != NULL) { \
1080 if (st->name != -1) { res = st->name; break; } \
1081 st = pxsltNextImport(st); \
1084 static void transform_write_xmldecl(xmlDocPtr result
, xsltStylesheetPtr style
, BOOL omit_encoding
, xmlOutputBufferPtr output
)
1086 int omit_xmldecl
, standalone
;
1088 XSLT_GET_IMPORT_INT(omit_xmldecl
, style
, omitXmlDeclaration
);
1089 if (omit_xmldecl
== 1) return;
1091 XSLT_GET_IMPORT_INT(standalone
, style
, standalone
);
1093 xmlOutputBufferWriteString(output
, "<?xml version=");
1094 if (result
->version
)
1096 xmlOutputBufferWriteString(output
, "\"");
1097 xmlOutputBufferWriteString(output
, (const char *)result
->version
);
1098 xmlOutputBufferWriteString(output
, "\"");
1101 xmlOutputBufferWriteString(output
, "\"1.0\"");
1105 const xmlChar
*encoding
;
1107 /* default encoding is UTF-16 */
1108 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1109 xmlOutputBufferWriteString(output
, " encoding=");
1110 xmlOutputBufferWriteString(output
, "\"");
1111 xmlOutputBufferWriteString(output
, encoding
? (const char *)encoding
: "UTF-16");
1112 xmlOutputBufferWriteString(output
, "\"");
1115 /* standalone attribute */
1116 if (standalone
!= -1)
1117 xmlOutputBufferWriteString(output
, standalone
== 0 ? " standalone=\"no\"" : " standalone=\"yes\"");
1119 xmlOutputBufferWriteString(output
, "?>");
1122 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
1124 xmlDtdPtr cur
= doc
->intSubset
;
1126 xmlOutputBufferWriteString(buf
, "<!DOCTYPE ");
1127 xmlOutputBufferWriteString(buf
, (const char *)cur
->name
);
1128 if (cur
->ExternalID
)
1130 xmlOutputBufferWriteString(buf
, " PUBLIC ");
1131 xml_write_quotedstring(buf
, cur
->ExternalID
);
1134 xmlOutputBufferWriteString(buf
, " ");
1135 xml_write_quotedstring(buf
, cur
->SystemID
);
1138 else if (cur
->SystemID
)
1140 xmlOutputBufferWriteString(buf
, " SYSTEM ");
1141 xml_write_quotedstring(buf
, cur
->SystemID
);
1143 xmlOutputBufferWriteString(buf
, ">\n");
1146 /* Duplicates htmlDocContentDumpFormatOutput() the way we need it - doesn't add trailing newline. */
1147 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
, const char *encoding
, int format
)
1149 xmlElementType type
;
1151 /* force HTML output */
1153 doc
->type
= XML_HTML_DOCUMENT_NODE
;
1155 htmldtd_dumpcontent(buf
, doc
);
1156 if (doc
->children
) {
1157 xmlNodePtr cur
= doc
->children
;
1159 htmlNodeDumpFormatOutput(buf
, doc
, cur
, encoding
, format
);
1166 static inline BOOL
transform_is_empty_resultdoc(xmlDocPtr result
)
1168 return !result
->children
|| ((result
->children
->type
== XML_DTD_NODE
) && !result
->children
->next
);
1171 static inline BOOL
transform_is_valid_method(xsltStylesheetPtr style
)
1173 return !style
->methodURI
|| !(style
->method
&& xmlStrEqual(style
->method
, (const xmlChar
*)"xhtml"));
1176 /* Helper to write transformation result to specified output buffer. */
1177 static HRESULT
node_transform_write(xsltStylesheetPtr style
, xmlDocPtr result
, BOOL omit_encoding
, const char *encoding
, xmlOutputBufferPtr output
)
1179 const xmlChar
*method
;
1182 if (!transform_is_valid_method(style
))
1184 ERR("unknown output method\n");
1188 XSLT_GET_IMPORT_PTR(method
, style
, method
)
1189 XSLT_GET_IMPORT_INT(indent
, style
, indent
);
1191 if (!method
&& (result
->type
== XML_HTML_DOCUMENT_NODE
))
1192 method
= (const xmlChar
*) "html";
1194 if (method
&& xmlStrEqual(method
, (const xmlChar
*)"html"))
1196 htmlSetMetaEncoding(result
, (const xmlChar
*)encoding
);
1199 htmldoc_dumpcontent(output
, result
, (const char*)encoding
, indent
);
1201 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"xhtml"))
1203 htmlSetMetaEncoding(result
, (const xmlChar
*) encoding
);
1204 htmlDocContentDumpOutput(output
, result
, encoding
);
1206 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"text"))
1207 transform_write_text(result
, style
, output
);
1210 transform_write_xmldecl(result
, style
, omit_encoding
, output
);
1212 if (result
->children
)
1214 xmlNodePtr child
= result
->children
;
1218 xmlNodeDumpOutput(output
, result
, child
, 0, indent
== 1, encoding
);
1219 if (indent
&& ((child
->type
== XML_DTD_NODE
) || ((child
->type
== XML_COMMENT_NODE
) && child
->next
)))
1220 xmlOutputBufferWriteString(output
, "\r\n");
1221 child
= child
->next
;
1226 xmlOutputBufferFlush(output
);
1230 /* For BSTR output is always UTF-16, without 'encoding' attribute */
1231 static HRESULT
node_transform_write_to_bstr(xsltStylesheetPtr style
, xmlDocPtr result
, BSTR
*str
)
1235 if (transform_is_empty_resultdoc(result
))
1236 *str
= SysAllocStringLen(NULL
, 0);
1239 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(xmlFindCharEncodingHandler("UTF-16"));
1240 const xmlChar
*content
;
1245 return E_OUTOFMEMORY
;
1247 hr
= node_transform_write(style
, result
, TRUE
, "UTF-16", output
);
1248 #ifdef LIBXML2_NEW_BUFFER
1249 content
= xmlBufContent(output
->conv
);
1250 len
= xmlBufUse(output
->conv
);
1252 content
= xmlBufferContent(output
->conv
);
1253 len
= xmlBufferLength(output
->conv
);
1255 /* UTF-16 encoder places UTF-16 bom, we don't need it for BSTR */
1256 content
+= sizeof(WCHAR
);
1257 *str
= SysAllocStringLen((WCHAR
*)content
, len
/sizeof(WCHAR
) - 1);
1258 xmlOutputBufferClose(output
);
1261 return *str
? hr
: E_OUTOFMEMORY
;
1264 static HRESULT
node_transform_write_to_stream(xsltStylesheetPtr style
, xmlDocPtr result
, IStream
*stream
)
1266 static const xmlChar
*utf16
= (const xmlChar
*)"UTF-16";
1267 xmlOutputBufferPtr output
;
1268 const xmlChar
*encoding
;
1271 if (transform_is_empty_resultdoc(result
))
1273 WARN("empty result document\n");
1277 if (style
->methodURI
&& (!style
->method
|| !xmlStrEqual(style
->method
, (const xmlChar
*) "xhtml")))
1279 ERR("unknown output method\n");
1283 /* default encoding is UTF-16 */
1284 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1288 output
= xmlOutputBufferCreateIO(transform_to_stream_write
, NULL
, stream
, xmlFindCharEncodingHandler((const char*)encoding
));
1290 return E_OUTOFMEMORY
;
1292 hr
= node_transform_write(style
, result
, FALSE
, (const char*)encoding
, output
);
1293 xmlOutputBufferClose(output
);
1299 HRESULT
node_transform_node_params(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
,
1300 IStream
*stream
, const struct xslprocessor_params
*params
)
1302 #ifdef SONAME_LIBXSLT
1303 xsltStylesheetPtr xsltSS
;
1307 if (!libxslt_handle
) return E_NOTIMPL
;
1308 if (!stylesheet
|| !p
) return E_INVALIDARG
;
1312 sheet
= get_node_obj(stylesheet
);
1313 if(!sheet
) return E_FAIL
;
1315 xsltSS
= pxsltParseStylesheetDoc(sheet
->node
->doc
);
1318 const char **xslparams
= NULL
;
1322 /* convert our parameter list to libxml2 format */
1323 if (params
&& params
->count
)
1325 struct xslprocessor_par
*par
;
1328 xslparams
= heap_alloc((params
->count
*2 + 1)*sizeof(char*));
1329 LIST_FOR_EACH_ENTRY(par
, ¶ms
->list
, struct xslprocessor_par
, entry
)
1331 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->name
);
1332 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->value
);
1334 xslparams
[i
] = NULL
;
1339 xsltTransformContextPtr ctxt
= pxsltNewTransformContext(xsltSS
, This
->node
->doc
);
1341 /* push parameters to user context */
1342 pxsltQuoteUserParams(ctxt
, xslparams
);
1343 result
= pxsltApplyStylesheetUser(xsltSS
, This
->node
->doc
, NULL
, NULL
, NULL
, ctxt
);
1344 pxsltFreeTransformContext(ctxt
);
1346 for (i
= 0; i
< params
->count
*2; i
++)
1347 heap_free((char*)xslparams
[i
]);
1348 heap_free(xslparams
);
1351 result
= pxsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1356 hr
= node_transform_write_to_stream(xsltSS
, result
, stream
);
1358 hr
= node_transform_write_to_bstr(xsltSS
, result
, p
);
1361 /* libxslt "helpfully" frees the XML document the stylesheet was
1362 generated from, too */
1364 pxsltFreeStylesheet(xsltSS
);
1367 if(!*p
) *p
= SysAllocStringLen(NULL
, 0);
1371 ERR_(winediag
)("libxslt headers were not found at compile time. Expect problems.\n");
1377 HRESULT
node_transform_node(const xmlnode
*node
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
1379 return node_transform_node_params(node
, stylesheet
, p
, NULL
, NULL
);
1382 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1387 if (!query
|| !nodes
) return E_INVALIDARG
;
1389 str
= xmlchar_from_wchar(query
);
1390 hr
= create_selection(This
->node
, str
, nodes
);
1396 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1398 IXMLDOMNodeList
*list
;
1401 hr
= node_select_nodes(This
, query
, &list
);
1404 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1405 IXMLDOMNodeList_Release(list
);
1410 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1412 xmlNsPtr ns
= This
->node
->ns
;
1415 return E_INVALIDARG
;
1417 *namespaceURI
= NULL
;
1420 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1422 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1424 return *namespaceURI
? S_OK
: S_FALSE
;
1427 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1429 xmlNsPtr ns
= This
->node
->ns
;
1431 if (!prefix
) return E_INVALIDARG
;
1435 if (ns
&& ns
->prefix
)
1436 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1438 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1440 return *prefix
? S_OK
: S_FALSE
;
1443 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1445 if (!name
) return E_INVALIDARG
;
1447 *name
= bstr_from_xmlChar(This
->node
->name
);
1448 if (!*name
) return E_OUTOFMEMORY
;
1450 TRACE("returning %s\n", debugstr_w(*name
));
1455 void destroy_xmlnode(xmlnode
*This
)
1459 xmlnode_release(This
->node
);
1460 xmldoc_release(This
->node
->doc
);
1464 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1468 xmlnode_add_ref(node
);
1469 xmldoc_add_ref(node
->doc
);
1473 This
->iface
= node_iface
;
1474 This
->parent
= NULL
;
1476 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1481 IXMLDOMNode IXMLDOMNode_iface
;
1485 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1487 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1490 static HRESULT WINAPI
unknode_QueryInterface(
1495 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1497 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1499 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1501 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1502 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1503 *ppvObject
= &This
->IXMLDOMNode_iface
;
1504 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1505 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1507 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1509 return E_NOINTERFACE
;
1512 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1516 static ULONG WINAPI
unknode_AddRef(
1517 IXMLDOMNode
*iface
)
1519 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1521 return InterlockedIncrement(&This
->ref
);
1524 static ULONG WINAPI
unknode_Release(
1525 IXMLDOMNode
*iface
)
1527 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1530 ref
= InterlockedDecrement( &This
->ref
);
1532 destroy_xmlnode(&This
->node
);
1539 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1543 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1545 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1552 static HRESULT WINAPI
unknode_GetTypeInfo(
1556 ITypeInfo
** ppTInfo
)
1558 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1561 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1563 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1568 static HRESULT WINAPI
unknode_GetIDsOfNames(
1571 LPOLESTR
* rgszNames
,
1576 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1578 ITypeInfo
*typeinfo
;
1581 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1584 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1585 return E_INVALIDARG
;
1587 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1590 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1591 ITypeInfo_Release(typeinfo
);
1597 static HRESULT WINAPI
unknode_Invoke(
1599 DISPID dispIdMember
,
1603 DISPPARAMS
* pDispParams
,
1604 VARIANT
* pVarResult
,
1605 EXCEPINFO
* pExcepInfo
,
1608 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1609 ITypeInfo
*typeinfo
;
1612 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1613 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1615 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1618 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1619 pVarResult
, pExcepInfo
, puArgErr
);
1620 ITypeInfo_Release(typeinfo
);
1626 static HRESULT WINAPI
unknode_get_nodeName(
1630 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1632 FIXME("(%p)->(%p)\n", This
, p
);
1634 return node_get_nodeName(&This
->node
, p
);
1637 static HRESULT WINAPI
unknode_get_nodeValue(
1641 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1643 FIXME("(%p)->(%p)\n", This
, value
);
1646 return E_INVALIDARG
;
1648 V_VT(value
) = VT_NULL
;
1652 static HRESULT WINAPI
unknode_put_nodeValue(
1656 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1657 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1661 static HRESULT WINAPI
unknode_get_nodeType(
1663 DOMNodeType
* domNodeType
)
1665 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1667 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1669 switch (This
->node
.node
->type
)
1671 case XML_ELEMENT_NODE
:
1672 case XML_ATTRIBUTE_NODE
:
1674 case XML_CDATA_SECTION_NODE
:
1675 case XML_ENTITY_REF_NODE
:
1676 case XML_ENTITY_NODE
:
1678 case XML_COMMENT_NODE
:
1679 case XML_DOCUMENT_NODE
:
1680 case XML_DOCUMENT_TYPE_NODE
:
1681 case XML_DOCUMENT_FRAG_NODE
:
1682 case XML_NOTATION_NODE
:
1683 /* we only care about this set of types, libxml2 type values are
1684 exactly what we need */
1685 *domNodeType
= (DOMNodeType
)This
->node
.node
->type
;
1688 *domNodeType
= NODE_INVALID
;
1695 static HRESULT WINAPI
unknode_get_parentNode(
1697 IXMLDOMNode
** parent
)
1699 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1700 FIXME("(%p)->(%p)\n", This
, parent
);
1701 if (!parent
) return E_INVALIDARG
;
1706 static HRESULT WINAPI
unknode_get_childNodes(
1708 IXMLDOMNodeList
** outList
)
1710 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1712 TRACE("(%p)->(%p)\n", This
, outList
);
1714 return node_get_child_nodes(&This
->node
, outList
);
1717 static HRESULT WINAPI
unknode_get_firstChild(
1719 IXMLDOMNode
** domNode
)
1721 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1723 TRACE("(%p)->(%p)\n", This
, domNode
);
1725 return node_get_first_child(&This
->node
, domNode
);
1728 static HRESULT WINAPI
unknode_get_lastChild(
1730 IXMLDOMNode
** domNode
)
1732 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1734 TRACE("(%p)->(%p)\n", This
, domNode
);
1736 return node_get_last_child(&This
->node
, domNode
);
1739 static HRESULT WINAPI
unknode_get_previousSibling(
1741 IXMLDOMNode
** domNode
)
1743 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1745 TRACE("(%p)->(%p)\n", This
, domNode
);
1747 return node_get_previous_sibling(&This
->node
, domNode
);
1750 static HRESULT WINAPI
unknode_get_nextSibling(
1752 IXMLDOMNode
** domNode
)
1754 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1756 TRACE("(%p)->(%p)\n", This
, domNode
);
1758 return node_get_next_sibling(&This
->node
, domNode
);
1761 static HRESULT WINAPI
unknode_get_attributes(
1763 IXMLDOMNamedNodeMap
** attributeMap
)
1765 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1767 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1769 return return_null_ptr((void**)attributeMap
);
1772 static HRESULT WINAPI
unknode_insertBefore(
1774 IXMLDOMNode
* newNode
, VARIANT refChild
,
1775 IXMLDOMNode
** outOldNode
)
1777 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1779 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1781 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1784 static HRESULT WINAPI
unknode_replaceChild(
1786 IXMLDOMNode
* newNode
,
1787 IXMLDOMNode
* oldNode
,
1788 IXMLDOMNode
** outOldNode
)
1790 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1792 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1794 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1797 static HRESULT WINAPI
unknode_removeChild(
1799 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1801 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1802 return node_remove_child(&This
->node
, domNode
, oldNode
);
1805 static HRESULT WINAPI
unknode_appendChild(
1807 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1809 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1810 return node_append_child(&This
->node
, newNode
, outNewNode
);
1813 static HRESULT WINAPI
unknode_hasChildNodes(
1815 VARIANT_BOOL
* pbool
)
1817 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1818 return node_has_childnodes(&This
->node
, pbool
);
1821 static HRESULT WINAPI
unknode_get_ownerDocument(
1823 IXMLDOMDocument
** domDocument
)
1825 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1826 return node_get_owner_doc(&This
->node
, domDocument
);
1829 static HRESULT WINAPI
unknode_cloneNode(
1831 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1833 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1834 return node_clone(&This
->node
, pbool
, outNode
);
1837 static HRESULT WINAPI
unknode_get_nodeTypeString(
1841 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1843 FIXME("(%p)->(%p)\n", This
, p
);
1845 return node_get_nodeName(&This
->node
, p
);
1848 static HRESULT WINAPI
unknode_get_text(
1852 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1853 return node_get_text(&This
->node
, p
);
1856 static HRESULT WINAPI
unknode_put_text(
1860 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1861 return node_put_text(&This
->node
, p
);
1864 static HRESULT WINAPI
unknode_get_specified(
1866 VARIANT_BOOL
* isSpecified
)
1868 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1869 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
1870 *isSpecified
= VARIANT_TRUE
;
1874 static HRESULT WINAPI
unknode_get_definition(
1876 IXMLDOMNode
** definitionNode
)
1878 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1879 FIXME("(%p)->(%p)\n", This
, definitionNode
);
1883 static HRESULT WINAPI
unknode_get_nodeTypedValue(
1887 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1888 FIXME("(%p)->(%p)\n", This
, var1
);
1889 return return_null_var(var1
);
1892 static HRESULT WINAPI
unknode_put_nodeTypedValue(
1896 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1897 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
1901 static HRESULT WINAPI
unknode_get_dataType(
1905 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1906 TRACE("(%p)->(%p)\n", This
, var1
);
1907 return return_null_var(var1
);
1910 static HRESULT WINAPI
unknode_put_dataType(
1914 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1916 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
1919 return E_INVALIDARG
;
1924 static HRESULT WINAPI
unknode_get_xml(
1928 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1930 FIXME("(%p)->(%p)\n", This
, p
);
1932 return node_get_xml(&This
->node
, FALSE
, p
);
1935 static HRESULT WINAPI
unknode_transformNode(
1937 IXMLDOMNode
* domNode
, BSTR
* p
)
1939 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1940 return node_transform_node(&This
->node
, domNode
, p
);
1943 static HRESULT WINAPI
unknode_selectNodes(
1945 BSTR p
, IXMLDOMNodeList
** outList
)
1947 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1948 return node_select_nodes(&This
->node
, p
, outList
);
1951 static HRESULT WINAPI
unknode_selectSingleNode(
1953 BSTR p
, IXMLDOMNode
** outNode
)
1955 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1956 return node_select_singlenode(&This
->node
, p
, outNode
);
1959 static HRESULT WINAPI
unknode_get_parsed(
1961 VARIANT_BOOL
* isParsed
)
1963 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1964 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
1965 *isParsed
= VARIANT_TRUE
;
1969 static HRESULT WINAPI
unknode_get_namespaceURI(
1973 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1974 TRACE("(%p)->(%p)\n", This
, p
);
1975 return node_get_namespaceURI(&This
->node
, p
);
1978 static HRESULT WINAPI
unknode_get_prefix(
1982 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1983 return node_get_prefix(&This
->node
, p
);
1986 static HRESULT WINAPI
unknode_get_baseName(
1990 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1991 return node_get_base_name(&This
->node
, p
);
1994 static HRESULT WINAPI
unknode_transformNodeToObject(
1996 IXMLDOMNode
* domNode
, VARIANT var1
)
1998 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1999 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
2003 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
2005 unknode_QueryInterface
,
2008 unknode_GetTypeInfoCount
,
2009 unknode_GetTypeInfo
,
2010 unknode_GetIDsOfNames
,
2012 unknode_get_nodeName
,
2013 unknode_get_nodeValue
,
2014 unknode_put_nodeValue
,
2015 unknode_get_nodeType
,
2016 unknode_get_parentNode
,
2017 unknode_get_childNodes
,
2018 unknode_get_firstChild
,
2019 unknode_get_lastChild
,
2020 unknode_get_previousSibling
,
2021 unknode_get_nextSibling
,
2022 unknode_get_attributes
,
2023 unknode_insertBefore
,
2024 unknode_replaceChild
,
2025 unknode_removeChild
,
2026 unknode_appendChild
,
2027 unknode_hasChildNodes
,
2028 unknode_get_ownerDocument
,
2030 unknode_get_nodeTypeString
,
2033 unknode_get_specified
,
2034 unknode_get_definition
,
2035 unknode_get_nodeTypedValue
,
2036 unknode_put_nodeTypedValue
,
2037 unknode_get_dataType
,
2038 unknode_put_dataType
,
2040 unknode_transformNode
,
2041 unknode_selectNodes
,
2042 unknode_selectSingleNode
,
2044 unknode_get_namespaceURI
,
2046 unknode_get_baseName
,
2047 unknode_transformNodeToObject
2050 IXMLDOMNode
*create_node( xmlNodePtr node
)
2059 TRACE("type %d\n", node
->type
);
2062 case XML_ELEMENT_NODE
:
2063 pUnk
= create_element( node
);
2065 case XML_ATTRIBUTE_NODE
:
2066 pUnk
= create_attribute( node
);
2069 pUnk
= create_text( node
);
2071 case XML_CDATA_SECTION_NODE
:
2072 pUnk
= create_cdata( node
);
2074 case XML_ENTITY_REF_NODE
:
2075 pUnk
= create_doc_entity_ref( node
);
2078 pUnk
= create_pi( node
);
2080 case XML_COMMENT_NODE
:
2081 pUnk
= create_comment( node
);
2083 case XML_DOCUMENT_NODE
:
2084 pUnk
= create_domdoc( node
);
2086 case XML_DOCUMENT_FRAG_NODE
:
2087 pUnk
= create_doc_fragment( node
);
2090 case XML_DOCUMENT_TYPE_NODE
:
2091 pUnk
= create_doc_type( node
);
2093 case XML_ENTITY_NODE
:
2094 case XML_NOTATION_NODE
: {
2097 FIXME("only creating basic node for type %d\n", node
->type
);
2099 new_node
= heap_alloc(sizeof(unknode
));
2103 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
2105 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
2106 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
2110 ERR("Called for unsupported node type %d\n", node
->type
);
2114 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
2115 IUnknown_Release(pUnk
);
2116 if(FAILED(hr
)) return NULL
;