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
25 #include <libxml/parser.h>
26 #include <libxml/parserInternals.h>
27 #include <libxml/xmlerror.h>
28 #include <libxml/HTMLtree.h>
29 #include <libxslt/pattern.h>
30 #include <libxslt/transform.h>
31 #include <libxslt/imports.h>
32 #include <libxslt/variables.h>
33 #include <libxslt/xsltutils.h>
34 #include <libxslt/xsltInternals.h>
35 #include <libxslt/documents.h>
44 #include "msxml_private.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msxml
);
50 static const IID IID_xmlnode
= {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
52 xmlNodePtr
xmlNodePtr_from_domnode( IXMLDOMNode
*iface
, xmlElementType type
)
58 This
= get_node_obj( iface
);
59 if ( !This
|| !This
->node
)
61 if ( type
&& This
->node
->type
!= type
)
66 BOOL
node_query_interface(xmlnode
*This
, REFIID riid
, void **ppv
)
68 if(IsEqualGUID(&IID_xmlnode
, riid
)) {
69 TRACE("(%p)->(IID_xmlnode %p)\n", This
, ppv
);
74 return dispex_query_interface(&This
->dispex
, riid
, ppv
);
77 /* common ISupportErrorInfo implementation */
79 ISupportErrorInfo ISupportErrorInfo_iface
;
85 static inline SupportErrorInfo
*impl_from_ISupportErrorInfo(ISupportErrorInfo
*iface
)
87 return CONTAINING_RECORD(iface
, SupportErrorInfo
, ISupportErrorInfo_iface
);
90 static HRESULT WINAPI
SupportErrorInfo_QueryInterface(ISupportErrorInfo
*iface
, REFIID riid
, void **obj
)
92 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
93 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), obj
);
97 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_ISupportErrorInfo
)) {
99 ISupportErrorInfo_AddRef(iface
);
103 return E_NOINTERFACE
;
106 static ULONG WINAPI
SupportErrorInfo_AddRef(ISupportErrorInfo
*iface
)
108 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
109 ULONG ref
= InterlockedIncrement(&This
->ref
);
110 TRACE("(%p)->(%d)\n", This
, ref
);
114 static ULONG WINAPI
SupportErrorInfo_Release(ISupportErrorInfo
*iface
)
116 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
117 LONG ref
= InterlockedDecrement(&This
->ref
);
119 TRACE("(%p)->(%d)\n", This
, ref
);
127 static HRESULT WINAPI
SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo
*iface
, REFIID riid
)
129 SupportErrorInfo
*This
= impl_from_ISupportErrorInfo(iface
);
130 enum tid_t
const *tid
;
132 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
135 while (*tid
!= NULL_tid
)
137 if (IsEqualGUID(riid
, get_riid_from_tid(*tid
)))
145 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl
= {
146 SupportErrorInfo_QueryInterface
,
147 SupportErrorInfo_AddRef
,
148 SupportErrorInfo_Release
,
149 SupportErrorInfo_InterfaceSupportsErrorInfo
152 HRESULT
node_create_supporterrorinfo(enum tid_t
const *iids
, void **obj
)
154 SupportErrorInfo
*This
;
156 This
= heap_alloc(sizeof(*This
));
157 if (!This
) return E_OUTOFMEMORY
;
159 This
->ISupportErrorInfo_iface
.lpVtbl
= &SupportErrorInfoVtbl
;
163 *obj
= &This
->ISupportErrorInfo_iface
;
168 xmlnode
*get_node_obj(IXMLDOMNode
*node
)
173 hres
= IXMLDOMNode_QueryInterface(node
, &IID_xmlnode
, (void**)&obj
);
174 if (!obj
) WARN("node is not our IXMLDOMNode implementation\n");
175 return SUCCEEDED(hres
) ? obj
: NULL
;
178 HRESULT
node_get_nodeName(xmlnode
*This
, BSTR
*name
)
186 hr
= node_get_base_name(This
, &base
);
187 if (hr
!= S_OK
) return hr
;
189 hr
= node_get_prefix(This
, &prefix
);
192 static const WCHAR colW
= ':';
196 ptr
= *name
= SysAllocStringLen(NULL
, SysStringLen(base
) + SysStringLen(prefix
) + 1);
197 memcpy(ptr
, prefix
, SysStringByteLen(prefix
));
198 ptr
+= SysStringLen(prefix
);
199 memcpy(ptr
++, &colW
, sizeof(WCHAR
));
200 memcpy(ptr
, base
, SysStringByteLen(base
));
203 SysFreeString(prefix
);
211 HRESULT
node_get_content(xmlnode
*This
, VARIANT
*value
)
218 content
= xmlNodeGetContent(This
->node
);
219 V_VT(value
) = VT_BSTR
;
220 V_BSTR(value
) = bstr_from_xmlChar( content
);
223 TRACE("%p returned %s\n", This
, debugstr_w(V_BSTR(value
)));
227 HRESULT
node_set_content(xmlnode
*This
, LPCWSTR value
)
231 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
232 str
= xmlchar_from_wchar(value
);
234 return E_OUTOFMEMORY
;
236 xmlNodeSetContent(This
->node
, str
);
241 static HRESULT
node_set_content_escaped(xmlnode
*This
, LPCWSTR value
)
243 xmlChar
*str
, *escaped
;
245 TRACE("(%p)->(%s)\n", This
, debugstr_w(value
));
246 str
= xmlchar_from_wchar(value
);
248 return E_OUTOFMEMORY
;
250 escaped
= xmlEncodeSpecialChars(NULL
, str
);
254 return E_OUTOFMEMORY
;
257 xmlNodeSetContent(This
->node
, escaped
);
265 HRESULT
node_put_value(xmlnode
*This
, VARIANT
*value
)
269 if (V_VT(value
) != VT_BSTR
)
271 VARIANT string_value
;
273 VariantInit(&string_value
);
274 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
276 WARN("Couldn't convert to VT_BSTR\n");
280 hr
= node_set_content(This
, V_BSTR(&string_value
));
281 VariantClear(&string_value
);
284 hr
= node_set_content(This
, V_BSTR(value
));
289 HRESULT
node_put_value_escaped(xmlnode
*This
, VARIANT
*value
)
293 if (V_VT(value
) != VT_BSTR
)
295 VARIANT string_value
;
297 VariantInit(&string_value
);
298 hr
= VariantChangeType(&string_value
, value
, 0, VT_BSTR
);
300 WARN("Couldn't convert to VT_BSTR\n");
304 hr
= node_set_content_escaped(This
, V_BSTR(&string_value
));
305 VariantClear(&string_value
);
308 hr
= node_set_content_escaped(This
, V_BSTR(value
));
313 static HRESULT
get_node(
319 TRACE("(%p)->(%s %p %p)\n", This
, name
, node
, out
);
324 /* if we don't have a doc, use our parent. */
325 if(node
&& !node
->doc
&& node
->parent
)
326 node
->doc
= node
->parent
->doc
;
328 *out
= create_node( node
);
334 HRESULT
node_get_parent(xmlnode
*This
, IXMLDOMNode
**parent
)
336 return get_node( This
, "parent", This
->node
->parent
, parent
);
339 HRESULT
node_get_child_nodes(xmlnode
*This
, IXMLDOMNodeList
**ret
)
344 *ret
= create_children_nodelist(This
->node
);
346 return E_OUTOFMEMORY
;
351 HRESULT
node_get_first_child(xmlnode
*This
, IXMLDOMNode
**ret
)
353 return get_node(This
, "firstChild", This
->node
->children
, ret
);
356 HRESULT
node_get_last_child(xmlnode
*This
, IXMLDOMNode
**ret
)
358 return get_node(This
, "lastChild", This
->node
->last
, ret
);
361 HRESULT
node_get_previous_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
363 return get_node(This
, "previous", This
->node
->prev
, ret
);
366 HRESULT
node_get_next_sibling(xmlnode
*This
, IXMLDOMNode
**ret
)
368 return get_node(This
, "next", This
->node
->next
, ret
);
371 static int node_get_inst_cnt(xmlNodePtr node
)
373 int ret
= *(LONG
*)&node
->_private
& NODE_PRIV_REFCOUNT_MASK
;
376 /* add attribute counts */
377 if (node
->type
== XML_ELEMENT_NODE
)
379 xmlAttrPtr prop
= node
->properties
;
383 ret
+= node_get_inst_cnt((xmlNodePtr
)prop
);
388 /* add children counts */
389 child
= node
->children
;
392 ret
+= node_get_inst_cnt(child
);
399 int xmlnode_get_inst_cnt(xmlnode
*node
)
401 return node_get_inst_cnt(node
->node
);
404 /* _private field holds a number of COM instances spawned from this libxml2 node
405 * most significant bits are used to store information about ignorable whitespace nodes */
406 void xmlnode_add_ref(xmlNodePtr node
)
408 if (node
->type
== XML_DOCUMENT_NODE
) return;
409 InterlockedIncrement((LONG
*)&node
->_private
);
412 void xmlnode_release(xmlNodePtr node
)
414 if (node
->type
== XML_DOCUMENT_NODE
) return;
415 InterlockedDecrement((LONG
*)&node
->_private
);
418 HRESULT
node_insert_before(xmlnode
*This
, IXMLDOMNode
*new_child
, const VARIANT
*ref_child
,
421 IXMLDOMNode
*before
= NULL
;
430 node_obj
= get_node_obj(new_child
);
431 if(!node_obj
) return E_FAIL
;
433 switch(V_VT(ref_child
))
441 if (V_UNKNOWN(ref_child
))
443 hr
= IUnknown_QueryInterface(V_UNKNOWN(ref_child
), &IID_IXMLDOMNode
, (void**)&before
);
444 if(FAILED(hr
)) return hr
;
449 FIXME("refChild var type %x\n", V_VT(ref_child
));
453 TRACE("new child %p, This->node %p\n", node_obj
->node
, This
->node
);
455 if(!node_obj
->node
->parent
)
456 if(xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
) != S_OK
)
457 WARN("%p is not an orphan of %p\n", node_obj
->node
, node_obj
->node
->doc
);
459 refcount
= xmlnode_get_inst_cnt(node_obj
);
463 xmlnode
*before_node_obj
= get_node_obj(before
);
464 IXMLDOMNode_Release(before
);
465 if(!before_node_obj
) return E_FAIL
;
468 /* unlink from current parent first */
471 hr
= IXMLDOMNode_removeChild(node_obj
->parent
, node_obj
->iface
, NULL
);
472 if (hr
== S_OK
) xmldoc_remove_orphan(node_obj
->node
->doc
, node_obj
->node
);
474 doc
= node_obj
->node
->doc
;
479 xmlnode
*before_node_obj
= get_node_obj(before
);
481 /* refs count including subtree */
482 if (doc
!= before_node_obj
->node
->doc
)
483 refcount
= xmlnode_get_inst_cnt(node_obj
);
485 if (refcount
) xmldoc_add_refs(before_node_obj
->node
->doc
, refcount
);
486 new_node
= xmlAddPrevSibling(before_node_obj
->node
, node_obj
->node
);
487 if (new_node
!= node_obj
->node
)
490 FIXME("referenced xmlNode was freed, expect crashes\n");
491 xmlnode_add_ref(new_node
);
492 node_obj
->node
= new_node
;
494 if (refcount
) xmldoc_release_refs(doc
, refcount
);
495 node_obj
->parent
= This
->parent
;
501 if (doc
!= This
->node
->doc
)
502 refcount
= xmlnode_get_inst_cnt(node_obj
);
504 if (refcount
) xmldoc_add_refs(This
->node
->doc
, refcount
);
505 /* xmlAddChild doesn't unlink node from previous parent */
506 xmlUnlinkNode(node_obj
->node
);
507 new_node
= xmlAddChild(This
->node
, node_obj
->node
);
508 if (new_node
!= node_obj
->node
)
511 FIXME("referenced xmlNode was freed, expect crashes\n");
512 xmlnode_add_ref(new_node
);
513 node_obj
->node
= new_node
;
515 if (refcount
) xmldoc_release_refs(doc
, refcount
);
516 node_obj
->parent
= This
->iface
;
521 IXMLDOMNode_AddRef(new_child
);
529 HRESULT
node_replace_child(xmlnode
*This
, IXMLDOMNode
*newChild
, IXMLDOMNode
*oldChild
,
532 xmlnode
*old_child
, *new_child
;
533 xmlDocPtr leaving_doc
;
534 xmlNode
*my_ancestor
;
537 /* Do not believe any documentation telling that newChild == NULL
538 means removal. It does certainly *not* apply to msxml3! */
539 if(!newChild
|| !oldChild
)
545 old_child
= get_node_obj(oldChild
);
546 if(!old_child
) return E_FAIL
;
548 if(old_child
->node
->parent
!= This
->node
)
550 WARN("childNode %p is not a child of %p\n", oldChild
, This
);
554 new_child
= get_node_obj(newChild
);
555 if(!new_child
) return E_FAIL
;
557 my_ancestor
= This
->node
;
560 if(my_ancestor
== new_child
->node
)
562 WARN("tried to create loop\n");
565 my_ancestor
= my_ancestor
->parent
;
568 if(!new_child
->node
->parent
)
569 if(xmldoc_remove_orphan(new_child
->node
->doc
, new_child
->node
) != S_OK
)
570 WARN("%p is not an orphan of %p\n", new_child
->node
, new_child
->node
->doc
);
572 leaving_doc
= new_child
->node
->doc
;
574 if (leaving_doc
!= old_child
->node
->doc
)
575 refcount
= xmlnode_get_inst_cnt(new_child
);
577 if (refcount
) xmldoc_add_refs(old_child
->node
->doc
, refcount
);
578 xmlReplaceNode(old_child
->node
, new_child
->node
);
579 if (refcount
) xmldoc_release_refs(leaving_doc
, refcount
);
580 new_child
->parent
= old_child
->parent
;
581 old_child
->parent
= NULL
;
583 xmldoc_add_orphan(old_child
->node
->doc
, old_child
->node
);
587 IXMLDOMNode_AddRef(oldChild
);
594 HRESULT
node_remove_child(xmlnode
*This
, IXMLDOMNode
* child
, IXMLDOMNode
** oldChild
)
598 if(!child
) return E_INVALIDARG
;
603 child_node
= get_node_obj(child
);
604 if(!child_node
) return E_FAIL
;
606 if(child_node
->node
->parent
!= This
->node
)
608 WARN("childNode %p is not a child of %p\n", child
, This
);
612 xmlUnlinkNode(child_node
->node
);
613 child_node
->parent
= NULL
;
614 xmldoc_add_orphan(child_node
->node
->doc
, child_node
->node
);
618 IXMLDOMNode_AddRef(child
);
625 HRESULT
node_append_child(xmlnode
*This
, IXMLDOMNode
*child
, IXMLDOMNode
**outChild
)
634 hr
= IXMLDOMNode_get_nodeType(child
, &type
);
635 if(FAILED(hr
) || type
== NODE_ATTRIBUTE
) {
636 if (outChild
) *outChild
= NULL
;
641 return IXMLDOMNode_insertBefore(This
->iface
, child
, var
, outChild
);
644 HRESULT
node_has_childnodes(const xmlnode
*This
, VARIANT_BOOL
*ret
)
646 if (!ret
) return E_INVALIDARG
;
648 if (!This
->node
->children
)
650 *ret
= VARIANT_FALSE
;
658 HRESULT
node_get_owner_doc(const xmlnode
*This
, IXMLDOMDocument
**doc
)
662 return get_domdoc_from_xmldoc(This
->node
->doc
, (IXMLDOMDocument3
**)doc
);
665 HRESULT
node_clone(xmlnode
*This
, VARIANT_BOOL deep
, IXMLDOMNode
**cloneNode
)
670 if(!cloneNode
) return E_INVALIDARG
;
672 clone
= xmlCopyNode(This
->node
, deep
? 1 : 2);
675 xmlSetTreeDoc(clone
, This
->node
->doc
);
676 xmldoc_add_orphan(clone
->doc
, clone
);
678 node
= create_node(clone
);
681 ERR("Copy failed\n");
682 xmldoc_remove_orphan(clone
->doc
, clone
);
691 ERR("Copy failed\n");
698 static xmlChar
* do_get_text(xmlNodePtr node
, BOOL trim
, DWORD
*first
, DWORD
*last
, BOOL
*trail_ig_ws
)
702 BOOL preserving
= is_preserving_whitespace(node
);
709 str
= xmlNodeGetContent(node
);
710 *trail_ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
717 str
= xmlStrdup(BAD_CAST
"");
719 if (node
->type
!= XML_DOCUMENT_NODE
)
720 ig_ws
= *(DWORD
*)&node
->_private
& NODE_PRIV_CHILD_IGNORABLE_WS
;
721 *trail_ig_ws
= FALSE
;
723 for (child
= node
->children
; child
!= NULL
; child
= child
->next
)
727 case XML_ELEMENT_NODE
: {
728 DWORD node_first
, node_last
;
730 tmp
= do_get_text(child
, FALSE
, &node_first
, &node_last
, trail_ig_ws
);
732 if (node_first
!=-1 && pos
+node_first
<*first
)
733 *first
= pos
+node_first
;
734 if (node_last
&& pos
+node_last
>*last
)
735 *last
= pos
+node_last
;
739 tmp
= xmlNodeGetContent(child
);
740 if (!preserving
&& tmp
[0])
744 for (beg
= tmp
; *beg
; beg
++)
745 if (!isspace(*beg
)) break;
755 case XML_CDATA_SECTION_NODE
:
756 case XML_ENTITY_REF_NODE
:
757 case XML_ENTITY_NODE
:
758 tmp
= xmlNodeGetContent(child
);
765 if ((tmp
&& *tmp
) || child
->type
==XML_CDATA_SECTION_NODE
)
769 str
= xmlStrcat(str
, BAD_CAST
" ");
772 if (tmp
&& *tmp
) str
= xmlStrcat(str
, tmp
);
773 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
<*first
)
775 if (tmp
&& *tmp
) pos
+= xmlStrlen(tmp
);
776 if (child
->type
==XML_CDATA_SECTION_NODE
&& pos
>*last
)
780 if (tmp
) xmlFree(tmp
);
784 ig_ws
= *(DWORD
*)&child
->_private
& NODE_PRIV_TRAILING_IGNORABLE_WS
;
787 ig_ws
= *trail_ig_ws
;
788 *trail_ig_ws
= FALSE
;
791 *trail_ig_ws
= ig_ws
;
796 case XML_ELEMENT_NODE
:
798 case XML_ENTITY_REF_NODE
:
799 case XML_ENTITY_NODE
:
800 case XML_DOCUMENT_NODE
:
801 case XML_DOCUMENT_FRAG_NODE
:
802 if (trim
&& !preserving
)
810 for (ret
= str
; *ret
&& isspace(*ret
) && (*first
)--; ret
++)
811 if (*last
) (*last
)--;
812 for (len
= xmlStrlen(ret
)-1; len
>= 0 && len
>= *last
; len
--)
813 if(!isspace(ret
[len
])) break;
815 ret
= xmlStrndup(ret
, len
+1);
828 HRESULT
node_get_text(const xmlnode
*This
, BSTR
*text
)
835 if (!text
) return E_INVALIDARG
;
837 content
= do_get_text(This
->node
, TRUE
, &first
, &last
, &tmp
);
840 str
= bstr_from_xmlChar(content
);
844 /* Always return a string. */
845 if (!str
) str
= SysAllocStringLen( NULL
, 0 );
847 TRACE("%p %s\n", This
, debugstr_w(str
) );
853 HRESULT
node_put_text(xmlnode
*This
, BSTR text
)
857 TRACE("(%p)->(%s)\n", This
, debugstr_w(text
));
859 str
= xmlchar_from_wchar(text
);
861 /* Escape the string. */
862 str2
= xmlEncodeEntitiesReentrant(This
->node
->doc
, str
);
865 xmlNodeSetContent(This
->node
, str2
);
871 BSTR
EnsureCorrectEOL(BSTR sInput
)
878 nLen
= SysStringLen(sInput
);
879 /* Count line endings */
880 for(i
=0; i
< nLen
; i
++)
882 if(sInput
[i
] == '\n')
886 TRACE("len=%d, num=%d\n", nLen
, nNum
);
888 /* Add linefeed as needed */
892 sNew
= SysAllocStringLen(NULL
, nLen
+ nNum
);
893 for(i
=0; i
< nLen
; i
++)
895 if(sInput
[i
] == '\n')
897 sNew
[i
+nPlace
] = '\r';
900 sNew
[i
+nPlace
] = sInput
[i
];
903 SysFreeString(sInput
);
910 TRACE("len %d\n", SysStringLen(sNew
));
916 * We are trying to replicate the same behaviour as msxml by converting
917 * line endings to \r\n and using indents as \t. The problem is that msxml
918 * only formats nodes that have a line ending. Using libxml we cannot
919 * reproduce behaviour exactly.
922 HRESULT
node_get_xml(xmlnode
*This
, BOOL ensure_eol
, BSTR
*ret
)
924 xmlBufferPtr xml_buf
;
933 xml_buf
= xmlBufferCreate();
935 return E_OUTOFMEMORY
;
937 xmldecl
= xmldoc_unlink_xmldecl( This
->node
->doc
);
939 size
= xmlNodeDump(xml_buf
, This
->node
->doc
, This
->node
, 0, 1);
941 const xmlChar
*buf_content
;
944 /* Attribute Nodes return a space in front of their name */
945 buf_content
= xmlBufferContent(xml_buf
);
947 content
= bstr_from_xmlChar(buf_content
+ (buf_content
[0] == ' ' ? 1 : 0));
949 content
= EnsureCorrectEOL(content
);
953 *ret
= SysAllocStringLen(NULL
, 0);
956 xmlBufferFree(xml_buf
);
957 xmldoc_link_xmldecl( This
->node
->doc
, xmldecl
);
958 return *ret
? S_OK
: E_OUTOFMEMORY
;
961 /* duplicates xmlBufferWriteQuotedString() logic */
962 static void xml_write_quotedstring(xmlOutputBufferPtr buf
, const xmlChar
*string
)
964 const xmlChar
*cur
, *base
;
966 if (xmlStrchr(string
, '\"'))
968 if (xmlStrchr(string
, '\''))
970 xmlOutputBufferWrite(buf
, 1, "\"");
978 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
979 xmlOutputBufferWrite(buf
, 6, """);
987 xmlOutputBufferWrite(buf
, cur
-base
, (const char*)base
);
988 xmlOutputBufferWrite(buf
, 1, "\"");
992 xmlOutputBufferWrite(buf
, 1, "\'");
993 xmlOutputBufferWriteString(buf
, (const char*)string
);
994 xmlOutputBufferWrite(buf
, 1, "\'");
999 xmlOutputBufferWrite(buf
, 1, "\"");
1000 xmlOutputBufferWriteString(buf
, (const char*)string
);
1001 xmlOutputBufferWrite(buf
, 1, "\"");
1005 static int XMLCALL
transform_to_stream_write(void *context
, const char *buffer
, int len
)
1008 HRESULT hr
= ISequentialStream_Write((ISequentialStream
*)context
, buffer
, len
, &written
);
1009 return hr
== S_OK
? written
: -1;
1012 /* Output for method "text" */
1013 static void transform_write_text(xmlDocPtr result
, xsltStylesheetPtr style
, xmlOutputBufferPtr output
)
1015 xmlNodePtr cur
= result
->children
;
1018 if (cur
->type
== XML_TEXT_NODE
)
1019 xmlOutputBufferWriteString(output
, (const char*)cur
->content
);
1021 /* skip to next node */
1024 if ((cur
->children
->type
!= XML_ENTITY_DECL
) &&
1025 (cur
->children
->type
!= XML_ENTITY_REF_NODE
) &&
1026 (cur
->children
->type
!= XML_ENTITY_NODE
))
1028 cur
= cur
->children
;
1043 if (cur
== (xmlNodePtr
) style
->doc
) {
1055 #undef XSLT_GET_IMPORT_PTR
1056 #define XSLT_GET_IMPORT_PTR(res, style, name) { \
1057 xsltStylesheetPtr st = style; \
1059 while (st != NULL) { \
1060 if (st->name != NULL) { res = st->name; break; } \
1061 st = xsltNextImport(st); \
1064 #undef XSLT_GET_IMPORT_INT
1065 #define XSLT_GET_IMPORT_INT(res, style, name) { \
1066 xsltStylesheetPtr st = style; \
1068 while (st != NULL) { \
1069 if (st->name != -1) { res = st->name; break; } \
1070 st = xsltNextImport(st); \
1073 static void transform_write_xmldecl(xmlDocPtr result
, xsltStylesheetPtr style
, BOOL omit_encoding
, xmlOutputBufferPtr output
)
1075 int omit_xmldecl
, standalone
;
1077 XSLT_GET_IMPORT_INT(omit_xmldecl
, style
, omitXmlDeclaration
);
1078 if (omit_xmldecl
== 1) return;
1080 XSLT_GET_IMPORT_INT(standalone
, style
, standalone
);
1082 xmlOutputBufferWriteString(output
, "<?xml version=");
1083 if (result
->version
)
1085 xmlOutputBufferWriteString(output
, "\"");
1086 xmlOutputBufferWriteString(output
, (const char *)result
->version
);
1087 xmlOutputBufferWriteString(output
, "\"");
1090 xmlOutputBufferWriteString(output
, "\"1.0\"");
1094 const xmlChar
*encoding
;
1096 /* default encoding is UTF-16 */
1097 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1098 xmlOutputBufferWriteString(output
, " encoding=");
1099 xmlOutputBufferWriteString(output
, "\"");
1100 xmlOutputBufferWriteString(output
, encoding
? (const char *)encoding
: "UTF-16");
1101 xmlOutputBufferWriteString(output
, "\"");
1104 /* standalone attribute */
1105 if (standalone
!= -1)
1106 xmlOutputBufferWriteString(output
, standalone
== 0 ? " standalone=\"no\"" : " standalone=\"yes\"");
1108 xmlOutputBufferWriteString(output
, "?>");
1111 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
)
1113 xmlDtdPtr cur
= doc
->intSubset
;
1115 xmlOutputBufferWriteString(buf
, "<!DOCTYPE ");
1116 xmlOutputBufferWriteString(buf
, (const char *)cur
->name
);
1117 if (cur
->ExternalID
)
1119 xmlOutputBufferWriteString(buf
, " PUBLIC ");
1120 xml_write_quotedstring(buf
, cur
->ExternalID
);
1123 xmlOutputBufferWriteString(buf
, " ");
1124 xml_write_quotedstring(buf
, cur
->SystemID
);
1127 else if (cur
->SystemID
)
1129 xmlOutputBufferWriteString(buf
, " SYSTEM ");
1130 xml_write_quotedstring(buf
, cur
->SystemID
);
1132 xmlOutputBufferWriteString(buf
, ">\n");
1135 /* Duplicates htmlDocContentDumpFormatOutput() the way we need it - doesn't add trailing newline. */
1136 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf
, xmlDocPtr doc
, const char *encoding
, int format
)
1138 xmlElementType type
;
1140 /* force HTML output */
1142 doc
->type
= XML_HTML_DOCUMENT_NODE
;
1144 htmldtd_dumpcontent(buf
, doc
);
1145 if (doc
->children
) {
1146 xmlNodePtr cur
= doc
->children
;
1148 htmlNodeDumpFormatOutput(buf
, doc
, cur
, encoding
, format
);
1155 static inline BOOL
transform_is_empty_resultdoc(xmlDocPtr result
)
1157 return !result
->children
|| ((result
->children
->type
== XML_DTD_NODE
) && !result
->children
->next
);
1160 static inline BOOL
transform_is_valid_method(xsltStylesheetPtr style
)
1162 return !style
->methodURI
|| !(style
->method
&& xmlStrEqual(style
->method
, (const xmlChar
*)"xhtml"));
1165 /* Helper to write transformation result to specified output buffer. */
1166 static HRESULT
node_transform_write(xsltStylesheetPtr style
, xmlDocPtr result
, BOOL omit_encoding
, const char *encoding
, xmlOutputBufferPtr output
)
1168 const xmlChar
*method
;
1171 if (!transform_is_valid_method(style
))
1173 ERR("unknown output method\n");
1177 XSLT_GET_IMPORT_PTR(method
, style
, method
)
1178 XSLT_GET_IMPORT_INT(indent
, style
, indent
);
1180 if (!method
&& (result
->type
== XML_HTML_DOCUMENT_NODE
))
1181 method
= (const xmlChar
*) "html";
1183 if (method
&& xmlStrEqual(method
, (const xmlChar
*)"html"))
1185 htmlSetMetaEncoding(result
, (const xmlChar
*)encoding
);
1188 htmldoc_dumpcontent(output
, result
, encoding
, indent
);
1190 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"xhtml"))
1192 htmlSetMetaEncoding(result
, (const xmlChar
*) encoding
);
1193 htmlDocContentDumpOutput(output
, result
, encoding
);
1195 else if (method
&& xmlStrEqual(method
, (const xmlChar
*)"text"))
1196 transform_write_text(result
, style
, output
);
1199 transform_write_xmldecl(result
, style
, omit_encoding
, output
);
1201 if (result
->children
)
1203 xmlNodePtr child
= result
->children
;
1207 xmlNodeDumpOutput(output
, result
, child
, 0, indent
== 1, encoding
);
1208 if (indent
&& ((child
->type
== XML_DTD_NODE
) || ((child
->type
== XML_COMMENT_NODE
) && child
->next
)))
1209 xmlOutputBufferWriteString(output
, "\r\n");
1210 child
= child
->next
;
1215 xmlOutputBufferFlush(output
);
1219 /* For BSTR output is always UTF-16, without 'encoding' attribute */
1220 static HRESULT
node_transform_write_to_bstr(xsltStylesheetPtr style
, xmlDocPtr result
, BSTR
*str
)
1224 if (transform_is_empty_resultdoc(result
))
1225 *str
= SysAllocStringLen(NULL
, 0);
1228 xmlOutputBufferPtr output
= xmlAllocOutputBuffer(xmlFindCharEncodingHandler("UTF-16"));
1229 const xmlChar
*content
;
1234 return E_OUTOFMEMORY
;
1236 hr
= node_transform_write(style
, result
, TRUE
, "UTF-16", output
);
1237 content
= xmlBufContent(output
->conv
);
1238 len
= xmlBufUse(output
->conv
);
1239 /* UTF-16 encoder places UTF-16 bom, we don't need it for BSTR */
1240 content
+= sizeof(WCHAR
);
1241 *str
= SysAllocStringLen((WCHAR
*)content
, len
/sizeof(WCHAR
) - 1);
1242 xmlOutputBufferClose(output
);
1245 return *str
? hr
: E_OUTOFMEMORY
;
1248 static HRESULT
node_transform_write_to_stream(xsltStylesheetPtr style
, xmlDocPtr result
, ISequentialStream
*stream
)
1250 static const xmlChar
*utf16
= (const xmlChar
*)"UTF-16";
1251 xmlOutputBufferPtr output
;
1252 const xmlChar
*encoding
;
1255 if (transform_is_empty_resultdoc(result
))
1257 WARN("empty result document\n");
1261 if (style
->methodURI
&& (!style
->method
|| !xmlStrEqual(style
->method
, (const xmlChar
*) "xhtml")))
1263 ERR("unknown output method\n");
1267 /* default encoding is UTF-16 */
1268 XSLT_GET_IMPORT_PTR(encoding
, style
, encoding
);
1272 output
= xmlOutputBufferCreateIO(transform_to_stream_write
, NULL
, stream
, xmlFindCharEncodingHandler((const char*)encoding
));
1274 return E_OUTOFMEMORY
;
1276 hr
= node_transform_write(style
, result
, FALSE
, (const char*)encoding
, output
);
1277 xmlOutputBufferClose(output
);
1281 struct import_buffer
1288 static int XMLCALL
import_loader_io_read(void *context
, char *out
, int len
)
1290 struct import_buffer
*buffer
= (struct import_buffer
*)context
;
1292 TRACE("%p, %p, %d\n", context
, out
, len
);
1294 if (buffer
->cur
== buffer
->len
)
1297 len
= min(len
, buffer
->len
- buffer
->cur
);
1298 memcpy(out
, &buffer
->data
[buffer
->cur
], len
);
1301 TRACE("read %d\n", len
);
1306 static int XMLCALL
import_loader_io_close(void * context
)
1308 struct import_buffer
*buffer
= (struct import_buffer
*)context
;
1310 TRACE("%p\n", context
);
1312 heap_free(buffer
->data
);
1317 static HRESULT
import_loader_onDataAvailable(void *ctxt
, char *ptr
, DWORD len
)
1319 xmlParserInputPtr
*input
= (xmlParserInputPtr
*)ctxt
;
1320 xmlParserInputBufferPtr inputbuffer
;
1321 struct import_buffer
*buffer
;
1323 buffer
= heap_alloc(sizeof(*buffer
));
1325 buffer
->data
= heap_alloc(len
);
1326 memcpy(buffer
->data
, ptr
, len
);
1330 inputbuffer
= xmlParserInputBufferCreateIO(import_loader_io_read
, import_loader_io_close
, buffer
,
1331 XML_CHAR_ENCODING_NONE
);
1332 *input
= xmlNewIOInputStream(NULL
, inputbuffer
, XML_CHAR_ENCODING_NONE
);
1334 xmlFreeParserInputBuffer(inputbuffer
);
1336 return *input
? S_OK
: E_FAIL
;
1339 static HRESULT
xslt_doc_get_uri(const xmlChar
*uri
, void *_ctxt
, xsltLoadType type
, IUri
**doc_uri
)
1341 xsltStylesheetPtr style
= (xsltStylesheetPtr
)_ctxt
;
1348 uriW
= bstr_from_xmlChar(uri
);
1349 hr
= CreateUri(uriW
, Uri_CREATE_ALLOW_RELATIVE
| Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &href_uri
);
1350 SysFreeString(uriW
);
1353 WARN("Failed to create href uri, %#x.\n", hr
);
1357 if (type
== XSLT_LOAD_STYLESHEET
&& style
->doc
&& style
->doc
->name
)
1362 baseuriW
= bstr_from_xmlChar((xmlChar
*)style
->doc
->name
);
1363 hr
= CreateUri(baseuriW
, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME
, 0, &base_uri
);
1364 SysFreeString(baseuriW
);
1367 WARN("Failed to create base uri, %#x.\n", hr
);
1371 hr
= CoInternetCombineIUri(base_uri
, href_uri
, 0, doc_uri
, 0);
1372 IUri_Release(base_uri
);
1374 WARN("Failed to combine uris, %#x.\n", hr
);
1378 *doc_uri
= href_uri
;
1379 IUri_AddRef(*doc_uri
);
1382 IUri_Release(href_uri
);
1387 xmlDocPtr
xslt_doc_default_loader(const xmlChar
*uri
, xmlDictPtr dict
, int options
,
1388 void *_ctxt
, xsltLoadType type
)
1390 IUri
*import_uri
= NULL
;
1391 xmlParserInputPtr input
;
1392 xmlParserCtxtPtr pctxt
;
1393 xmlDocPtr doc
= NULL
;
1399 TRACE("%s, %p, %#x, %p, %d\n", debugstr_a((const char *)uri
), dict
, options
, _ctxt
, type
);
1401 pctxt
= xmlNewParserCtxt();
1405 if (dict
&& pctxt
->dict
)
1407 xmlDictFree(pctxt
->dict
);
1414 xmlDictReference(pctxt
->dict
);
1417 xmlCtxtUseOptions(pctxt
, options
);
1419 hr
= xslt_doc_get_uri(uri
, _ctxt
, type
, &import_uri
);
1423 hr
= CreateURLMonikerEx2(NULL
, import_uri
, &moniker
, 0);
1427 hr
= bind_url(moniker
, import_loader_onDataAvailable
, &input
, &bsc
);
1428 IMoniker_Release(moniker
);
1432 if (FAILED(detach_bsc(bsc
)))
1438 inputPush(pctxt
, input
);
1439 xmlParseDocument(pctxt
);
1441 if (pctxt
->wellFormed
)
1444 /* Set imported uri, to give nested imports a chance. */
1445 if (IUri_GetPropertyBSTR(import_uri
, Uri_PROPERTY_ABSOLUTE_URI
, &uriW
, 0) == S_OK
)
1447 doc
->name
= (char *)xmlchar_from_wcharn(uriW
, SysStringLen(uriW
), TRUE
);
1448 SysFreeString(uriW
);
1454 xmlFreeDoc(pctxt
->myDoc
);
1455 pctxt
->myDoc
= NULL
;
1459 xmlFreeParserCtxt(pctxt
);
1461 IUri_Release(import_uri
);
1466 HRESULT
node_transform_node_params(const xmlnode
*This
, IXMLDOMNode
*stylesheet
, BSTR
*p
,
1467 ISequentialStream
*stream
, const struct xslprocessor_params
*params
)
1469 xsltStylesheetPtr xsltSS
;
1470 xmlDocPtr sheet_doc
;
1474 if (!stylesheet
|| (!p
&& !stream
)) return E_INVALIDARG
;
1478 sheet
= get_node_obj(stylesheet
);
1479 if(!sheet
) return E_FAIL
;
1481 sheet_doc
= xmlCopyDoc(sheet
->node
->doc
, 1);
1482 xsltSS
= xsltParseStylesheetDoc(sheet_doc
);
1485 const char **xslparams
= NULL
;
1489 /* convert our parameter list to libxml2 format */
1490 if (params
&& params
->count
)
1492 struct xslprocessor_par
*par
;
1495 xslparams
= heap_alloc((params
->count
*2 + 1)*sizeof(char*));
1496 LIST_FOR_EACH_ENTRY(par
, ¶ms
->list
, struct xslprocessor_par
, entry
)
1498 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->name
);
1499 xslparams
[i
++] = (char*)xmlchar_from_wchar(par
->value
);
1501 xslparams
[i
] = NULL
;
1506 xsltTransformContextPtr ctxt
= xsltNewTransformContext(xsltSS
, This
->node
->doc
);
1508 /* push parameters to user context */
1509 xsltQuoteUserParams(ctxt
, xslparams
);
1510 result
= xsltApplyStylesheetUser(xsltSS
, This
->node
->doc
, NULL
, NULL
, NULL
, ctxt
);
1511 xsltFreeTransformContext(ctxt
);
1513 for (i
= 0; i
< params
->count
*2; i
++)
1514 heap_free((char*)xslparams
[i
]);
1515 heap_free(xslparams
);
1518 result
= xsltApplyStylesheet(xsltSS
, This
->node
->doc
, NULL
);
1523 hr
= node_transform_write_to_stream(xsltSS
, result
, stream
);
1525 hr
= node_transform_write_to_bstr(xsltSS
, result
, p
);
1529 xsltFreeStylesheet(xsltSS
);
1532 xmlFreeDoc(sheet_doc
);
1534 if (p
&& !*p
) *p
= SysAllocStringLen(NULL
, 0);
1539 HRESULT
node_transform_node(const xmlnode
*node
, IXMLDOMNode
*stylesheet
, BSTR
*p
)
1541 return node_transform_node_params(node
, stylesheet
, p
, NULL
, NULL
);
1544 HRESULT
node_select_nodes(const xmlnode
*This
, BSTR query
, IXMLDOMNodeList
**nodes
)
1549 if (!query
|| !nodes
) return E_INVALIDARG
;
1551 str
= xmlchar_from_wchar(query
);
1552 hr
= create_selection(This
->node
, str
, nodes
);
1558 HRESULT
node_select_singlenode(const xmlnode
*This
, BSTR query
, IXMLDOMNode
**node
)
1560 IXMLDOMNodeList
*list
;
1563 hr
= node_select_nodes(This
, query
, &list
);
1566 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1567 IXMLDOMNodeList_Release(list
);
1572 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1574 xmlNsPtr ns
= This
->node
->ns
;
1577 return E_INVALIDARG
;
1579 *namespaceURI
= NULL
;
1582 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1584 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1586 return *namespaceURI
? S_OK
: S_FALSE
;
1589 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1591 xmlNsPtr ns
= This
->node
->ns
;
1593 if (!prefix
) return E_INVALIDARG
;
1597 if (ns
&& ns
->prefix
)
1598 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1600 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1602 return *prefix
? S_OK
: S_FALSE
;
1605 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1607 if (!name
) return E_INVALIDARG
;
1609 *name
= bstr_from_xmlChar(This
->node
->name
);
1610 if (!*name
) return E_OUTOFMEMORY
;
1612 TRACE("returning %s\n", debugstr_w(*name
));
1617 void destroy_xmlnode(xmlnode
*This
)
1621 xmlnode_release(This
->node
);
1622 xmldoc_release(This
->node
->doc
);
1626 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1630 xmlnode_add_ref(node
);
1631 xmldoc_add_ref(node
->doc
);
1635 This
->iface
= node_iface
;
1636 This
->parent
= NULL
;
1638 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1643 IXMLDOMNode IXMLDOMNode_iface
;
1647 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1649 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1652 static HRESULT WINAPI
unknode_QueryInterface(
1657 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1659 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1661 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1663 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1664 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1665 *ppvObject
= &This
->IXMLDOMNode_iface
;
1666 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1667 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1669 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1671 return E_NOINTERFACE
;
1674 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1678 static ULONG WINAPI
unknode_AddRef(
1679 IXMLDOMNode
*iface
)
1681 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1683 return InterlockedIncrement(&This
->ref
);
1686 static ULONG WINAPI
unknode_Release(
1687 IXMLDOMNode
*iface
)
1689 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1692 ref
= InterlockedDecrement( &This
->ref
);
1694 destroy_xmlnode(&This
->node
);
1701 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1705 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1707 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1714 static HRESULT WINAPI
unknode_GetTypeInfo(
1718 ITypeInfo
** ppTInfo
)
1720 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1723 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
1725 hr
= get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1730 static HRESULT WINAPI
unknode_GetIDsOfNames(
1733 LPOLESTR
* rgszNames
,
1738 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1740 ITypeInfo
*typeinfo
;
1743 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
1746 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1747 return E_INVALIDARG
;
1749 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1752 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1753 ITypeInfo_Release(typeinfo
);
1759 static HRESULT WINAPI
unknode_Invoke(
1761 DISPID dispIdMember
,
1765 DISPPARAMS
* pDispParams
,
1766 VARIANT
* pVarResult
,
1767 EXCEPINFO
* pExcepInfo
,
1770 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1771 ITypeInfo
*typeinfo
;
1774 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
1775 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1777 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1780 hr
= ITypeInfo_Invoke(typeinfo
, &This
->IXMLDOMNode_iface
, dispIdMember
, wFlags
, pDispParams
,
1781 pVarResult
, pExcepInfo
, puArgErr
);
1782 ITypeInfo_Release(typeinfo
);
1788 static HRESULT WINAPI
unknode_get_nodeName(
1792 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1794 FIXME("(%p)->(%p)\n", This
, p
);
1796 return node_get_nodeName(&This
->node
, p
);
1799 static HRESULT WINAPI
unknode_get_nodeValue(
1803 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1805 FIXME("(%p)->(%p)\n", This
, value
);
1808 return E_INVALIDARG
;
1810 V_VT(value
) = VT_NULL
;
1814 static HRESULT WINAPI
unknode_put_nodeValue(
1818 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1819 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1823 static HRESULT WINAPI
unknode_get_nodeType(
1825 DOMNodeType
* domNodeType
)
1827 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1829 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1831 switch (This
->node
.node
->type
)
1833 case XML_ELEMENT_NODE
:
1834 case XML_ATTRIBUTE_NODE
:
1836 case XML_CDATA_SECTION_NODE
:
1837 case XML_ENTITY_REF_NODE
:
1838 case XML_ENTITY_NODE
:
1840 case XML_COMMENT_NODE
:
1841 case XML_DOCUMENT_NODE
:
1842 case XML_DOCUMENT_TYPE_NODE
:
1843 case XML_DOCUMENT_FRAG_NODE
:
1844 case XML_NOTATION_NODE
:
1845 /* we only care about this set of types, libxml2 type values are
1846 exactly what we need */
1847 *domNodeType
= (DOMNodeType
)This
->node
.node
->type
;
1850 *domNodeType
= NODE_INVALID
;
1857 static HRESULT WINAPI
unknode_get_parentNode(
1859 IXMLDOMNode
** parent
)
1861 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1862 FIXME("(%p)->(%p)\n", This
, parent
);
1863 if (!parent
) return E_INVALIDARG
;
1868 static HRESULT WINAPI
unknode_get_childNodes(
1870 IXMLDOMNodeList
** outList
)
1872 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1874 TRACE("(%p)->(%p)\n", This
, outList
);
1876 return node_get_child_nodes(&This
->node
, outList
);
1879 static HRESULT WINAPI
unknode_get_firstChild(
1881 IXMLDOMNode
** domNode
)
1883 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1885 TRACE("(%p)->(%p)\n", This
, domNode
);
1887 return node_get_first_child(&This
->node
, domNode
);
1890 static HRESULT WINAPI
unknode_get_lastChild(
1892 IXMLDOMNode
** domNode
)
1894 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1896 TRACE("(%p)->(%p)\n", This
, domNode
);
1898 return node_get_last_child(&This
->node
, domNode
);
1901 static HRESULT WINAPI
unknode_get_previousSibling(
1903 IXMLDOMNode
** domNode
)
1905 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1907 TRACE("(%p)->(%p)\n", This
, domNode
);
1909 return node_get_previous_sibling(&This
->node
, domNode
);
1912 static HRESULT WINAPI
unknode_get_nextSibling(
1914 IXMLDOMNode
** domNode
)
1916 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1918 TRACE("(%p)->(%p)\n", This
, domNode
);
1920 return node_get_next_sibling(&This
->node
, domNode
);
1923 static HRESULT WINAPI
unknode_get_attributes(
1925 IXMLDOMNamedNodeMap
** attributeMap
)
1927 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1929 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1931 return return_null_ptr((void**)attributeMap
);
1934 static HRESULT WINAPI
unknode_insertBefore(
1936 IXMLDOMNode
* newNode
, VARIANT refChild
,
1937 IXMLDOMNode
** outOldNode
)
1939 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1941 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1943 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1946 static HRESULT WINAPI
unknode_replaceChild(
1948 IXMLDOMNode
* newNode
,
1949 IXMLDOMNode
* oldNode
,
1950 IXMLDOMNode
** outOldNode
)
1952 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1954 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1956 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1959 static HRESULT WINAPI
unknode_removeChild(
1961 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1963 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1964 return node_remove_child(&This
->node
, domNode
, oldNode
);
1967 static HRESULT WINAPI
unknode_appendChild(
1969 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1971 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1972 return node_append_child(&This
->node
, newNode
, outNewNode
);
1975 static HRESULT WINAPI
unknode_hasChildNodes(
1977 VARIANT_BOOL
* pbool
)
1979 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1980 return node_has_childnodes(&This
->node
, pbool
);
1983 static HRESULT WINAPI
unknode_get_ownerDocument(
1985 IXMLDOMDocument
** domDocument
)
1987 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1988 return node_get_owner_doc(&This
->node
, domDocument
);
1991 static HRESULT WINAPI
unknode_cloneNode(
1993 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1995 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1996 return node_clone(&This
->node
, pbool
, outNode
);
1999 static HRESULT WINAPI
unknode_get_nodeTypeString(
2003 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2005 FIXME("(%p)->(%p)\n", This
, p
);
2007 return node_get_nodeName(&This
->node
, p
);
2010 static HRESULT WINAPI
unknode_get_text(
2014 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2015 return node_get_text(&This
->node
, p
);
2018 static HRESULT WINAPI
unknode_put_text(
2022 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2023 return node_put_text(&This
->node
, p
);
2026 static HRESULT WINAPI
unknode_get_specified(
2028 VARIANT_BOOL
* isSpecified
)
2030 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2031 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
2032 *isSpecified
= VARIANT_TRUE
;
2036 static HRESULT WINAPI
unknode_get_definition(
2038 IXMLDOMNode
** definitionNode
)
2040 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2041 FIXME("(%p)->(%p)\n", This
, definitionNode
);
2045 static HRESULT WINAPI
unknode_get_nodeTypedValue(
2049 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2050 FIXME("(%p)->(%p)\n", This
, var1
);
2051 return return_null_var(var1
);
2054 static HRESULT WINAPI
unknode_put_nodeTypedValue(
2058 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2059 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
2063 static HRESULT WINAPI
unknode_get_dataType(
2067 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2068 TRACE("(%p)->(%p)\n", This
, var1
);
2069 return return_null_var(var1
);
2072 static HRESULT WINAPI
unknode_put_dataType(
2076 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2078 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
2081 return E_INVALIDARG
;
2086 static HRESULT WINAPI
unknode_get_xml(
2090 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2092 FIXME("(%p)->(%p)\n", This
, p
);
2094 return node_get_xml(&This
->node
, FALSE
, p
);
2097 static HRESULT WINAPI
unknode_transformNode(
2099 IXMLDOMNode
* domNode
, BSTR
* p
)
2101 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2102 return node_transform_node(&This
->node
, domNode
, p
);
2105 static HRESULT WINAPI
unknode_selectNodes(
2107 BSTR p
, IXMLDOMNodeList
** outList
)
2109 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2110 return node_select_nodes(&This
->node
, p
, outList
);
2113 static HRESULT WINAPI
unknode_selectSingleNode(
2115 BSTR p
, IXMLDOMNode
** outNode
)
2117 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2118 return node_select_singlenode(&This
->node
, p
, outNode
);
2121 static HRESULT WINAPI
unknode_get_parsed(
2123 VARIANT_BOOL
* isParsed
)
2125 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2126 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
2127 *isParsed
= VARIANT_TRUE
;
2131 static HRESULT WINAPI
unknode_get_namespaceURI(
2135 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2136 TRACE("(%p)->(%p)\n", This
, p
);
2137 return node_get_namespaceURI(&This
->node
, p
);
2140 static HRESULT WINAPI
unknode_get_prefix(
2144 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2145 return node_get_prefix(&This
->node
, p
);
2148 static HRESULT WINAPI
unknode_get_baseName(
2152 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2153 return node_get_base_name(&This
->node
, p
);
2156 static HRESULT WINAPI
unknode_transformNodeToObject(
2158 IXMLDOMNode
* domNode
, VARIANT var1
)
2160 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2161 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
2165 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
2167 unknode_QueryInterface
,
2170 unknode_GetTypeInfoCount
,
2171 unknode_GetTypeInfo
,
2172 unknode_GetIDsOfNames
,
2174 unknode_get_nodeName
,
2175 unknode_get_nodeValue
,
2176 unknode_put_nodeValue
,
2177 unknode_get_nodeType
,
2178 unknode_get_parentNode
,
2179 unknode_get_childNodes
,
2180 unknode_get_firstChild
,
2181 unknode_get_lastChild
,
2182 unknode_get_previousSibling
,
2183 unknode_get_nextSibling
,
2184 unknode_get_attributes
,
2185 unknode_insertBefore
,
2186 unknode_replaceChild
,
2187 unknode_removeChild
,
2188 unknode_appendChild
,
2189 unknode_hasChildNodes
,
2190 unknode_get_ownerDocument
,
2192 unknode_get_nodeTypeString
,
2195 unknode_get_specified
,
2196 unknode_get_definition
,
2197 unknode_get_nodeTypedValue
,
2198 unknode_put_nodeTypedValue
,
2199 unknode_get_dataType
,
2200 unknode_put_dataType
,
2202 unknode_transformNode
,
2203 unknode_selectNodes
,
2204 unknode_selectSingleNode
,
2206 unknode_get_namespaceURI
,
2208 unknode_get_baseName
,
2209 unknode_transformNodeToObject
2212 IXMLDOMNode
*create_node( xmlNodePtr node
)
2221 TRACE("type %d\n", node
->type
);
2224 case XML_ELEMENT_NODE
:
2225 pUnk
= create_element( node
);
2227 case XML_ATTRIBUTE_NODE
:
2228 pUnk
= create_attribute( node
, FALSE
);
2231 pUnk
= create_text( node
);
2233 case XML_CDATA_SECTION_NODE
:
2234 pUnk
= create_cdata( node
);
2236 case XML_ENTITY_REF_NODE
:
2237 pUnk
= create_doc_entity_ref( node
);
2240 pUnk
= create_pi( node
);
2242 case XML_COMMENT_NODE
:
2243 pUnk
= create_comment( node
);
2245 case XML_DOCUMENT_NODE
:
2246 pUnk
= create_domdoc( node
);
2248 case XML_DOCUMENT_FRAG_NODE
:
2249 pUnk
= create_doc_fragment( node
);
2252 case XML_DOCUMENT_TYPE_NODE
:
2253 pUnk
= create_doc_type( node
);
2255 case XML_ENTITY_NODE
:
2256 case XML_NOTATION_NODE
: {
2259 FIXME("only creating basic node for type %d\n", node
->type
);
2261 new_node
= heap_alloc(sizeof(unknode
));
2265 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
2267 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
2268 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
2272 ERR("Called for unsupported node type %d\n", node
->type
);
2276 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
2277 IUnknown_Release(pUnk
);
2278 if(FAILED(hr
)) return NULL
;