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, refcount %ld.\n", iface
, 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, refcount %ld.\n", iface
, 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, %#lx.\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, %#lx.\n", hr
);
1371 hr
= CoInternetCombineIUri(base_uri
, href_uri
, 0, doc_uri
, 0);
1372 IUri_Release(base_uri
);
1374 WARN("Failed to combine uris, hr %#lx.\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
;
1566 hr
= node_select_nodes(This
, query
, &list
);
1569 hr
= IXMLDOMNodeList_nextNode(list
, node
);
1570 IXMLDOMNodeList_Release(list
);
1575 HRESULT
node_get_namespaceURI(xmlnode
*This
, BSTR
*namespaceURI
)
1577 xmlNsPtr ns
= This
->node
->ns
;
1580 return E_INVALIDARG
;
1582 *namespaceURI
= NULL
;
1585 *namespaceURI
= bstr_from_xmlChar(ns
->href
);
1587 TRACE("uri: %s\n", debugstr_w(*namespaceURI
));
1589 return *namespaceURI
? S_OK
: S_FALSE
;
1592 HRESULT
node_get_prefix(xmlnode
*This
, BSTR
*prefix
)
1594 xmlNsPtr ns
= This
->node
->ns
;
1596 if (!prefix
) return E_INVALIDARG
;
1600 if (ns
&& ns
->prefix
)
1601 *prefix
= bstr_from_xmlChar(ns
->prefix
);
1603 TRACE("prefix: %s\n", debugstr_w(*prefix
));
1605 return *prefix
? S_OK
: S_FALSE
;
1608 HRESULT
node_get_base_name(xmlnode
*This
, BSTR
*name
)
1610 if (!name
) return E_INVALIDARG
;
1612 *name
= bstr_from_xmlChar(This
->node
->name
);
1613 if (!*name
) return E_OUTOFMEMORY
;
1615 TRACE("returning %s\n", debugstr_w(*name
));
1620 void destroy_xmlnode(xmlnode
*This
)
1624 xmlnode_release(This
->node
);
1625 xmldoc_release(This
->node
->doc
);
1629 void init_xmlnode(xmlnode
*This
, xmlNodePtr node
, IXMLDOMNode
*node_iface
, dispex_static_data_t
*dispex_data
)
1633 xmlnode_add_ref(node
);
1634 xmldoc_add_ref(node
->doc
);
1638 This
->iface
= node_iface
;
1639 This
->parent
= NULL
;
1641 init_dispex(&This
->dispex
, (IUnknown
*)This
->iface
, dispex_data
);
1646 IXMLDOMNode IXMLDOMNode_iface
;
1650 static inline unknode
*unknode_from_IXMLDOMNode(IXMLDOMNode
*iface
)
1652 return CONTAINING_RECORD(iface
, unknode
, IXMLDOMNode_iface
);
1655 static HRESULT WINAPI
unknode_QueryInterface(
1660 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1662 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppvObject
);
1664 if (IsEqualGUID(riid
, &IID_IUnknown
)) {
1666 }else if (IsEqualGUID( riid
, &IID_IDispatch
) ||
1667 IsEqualGUID( riid
, &IID_IXMLDOMNode
)) {
1668 *ppvObject
= &This
->IXMLDOMNode_iface
;
1669 }else if(node_query_interface(&This
->node
, riid
, ppvObject
)) {
1670 return *ppvObject
? S_OK
: E_NOINTERFACE
;
1672 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
1674 return E_NOINTERFACE
;
1677 IUnknown_AddRef((IUnknown
*)*ppvObject
);
1681 static ULONG WINAPI
unknode_AddRef(
1682 IXMLDOMNode
*iface
)
1684 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1686 return InterlockedIncrement(&This
->ref
);
1689 static ULONG WINAPI
unknode_Release(
1690 IXMLDOMNode
*iface
)
1692 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1695 ref
= InterlockedDecrement( &This
->ref
);
1697 destroy_xmlnode(&This
->node
);
1704 static HRESULT WINAPI
unknode_GetTypeInfoCount(
1708 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1710 TRACE("(%p)->(%p)\n", This
, pctinfo
);
1717 static HRESULT WINAPI
unknode_GetTypeInfo(
1721 ITypeInfo
** ppTInfo
)
1723 TRACE("%p, %u, %lx, %p.\n", iface
, iTInfo
, lcid
, ppTInfo
);
1725 return get_typeinfo(IXMLDOMNode_tid
, ppTInfo
);
1728 static HRESULT WINAPI
unknode_GetIDsOfNames(
1731 LPOLESTR
* rgszNames
,
1736 ITypeInfo
*typeinfo
;
1739 TRACE("%p, %s, %p, %u, %lx, %p.\n", iface
, debugstr_guid(riid
), rgszNames
, cNames
,
1742 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
1743 return E_INVALIDARG
;
1745 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1748 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
1749 ITypeInfo_Release(typeinfo
);
1755 static HRESULT WINAPI
unknode_Invoke(
1757 DISPID dispIdMember
,
1761 DISPPARAMS
* pDispParams
,
1762 VARIANT
* pVarResult
,
1763 EXCEPINFO
* pExcepInfo
,
1766 ITypeInfo
*typeinfo
;
1769 TRACE("%p, %ld, %s, %lx, %d, %p, %p, %p, %p.\n", iface
, dispIdMember
, debugstr_guid(riid
),
1770 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1772 hr
= get_typeinfo(IXMLDOMNode_tid
, &typeinfo
);
1775 hr
= ITypeInfo_Invoke(typeinfo
, iface
, dispIdMember
, wFlags
, pDispParams
,
1776 pVarResult
, pExcepInfo
, puArgErr
);
1777 ITypeInfo_Release(typeinfo
);
1783 static HRESULT WINAPI
unknode_get_nodeName(
1787 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1789 FIXME("(%p)->(%p)\n", This
, p
);
1791 return node_get_nodeName(&This
->node
, p
);
1794 static HRESULT WINAPI
unknode_get_nodeValue(
1798 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1800 FIXME("(%p)->(%p)\n", This
, value
);
1803 return E_INVALIDARG
;
1805 V_VT(value
) = VT_NULL
;
1809 static HRESULT WINAPI
unknode_put_nodeValue(
1813 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1814 FIXME("(%p)->(v%d)\n", This
, V_VT(&value
));
1818 static HRESULT WINAPI
unknode_get_nodeType(
1820 DOMNodeType
* domNodeType
)
1822 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1824 FIXME("(%p)->(%p)\n", This
, domNodeType
);
1826 switch (This
->node
.node
->type
)
1828 case XML_ELEMENT_NODE
:
1829 case XML_ATTRIBUTE_NODE
:
1831 case XML_CDATA_SECTION_NODE
:
1832 case XML_ENTITY_REF_NODE
:
1833 case XML_ENTITY_NODE
:
1835 case XML_COMMENT_NODE
:
1836 case XML_DOCUMENT_NODE
:
1837 case XML_DOCUMENT_TYPE_NODE
:
1838 case XML_DOCUMENT_FRAG_NODE
:
1839 case XML_NOTATION_NODE
:
1840 /* we only care about this set of types, libxml2 type values are
1841 exactly what we need */
1842 *domNodeType
= (DOMNodeType
)This
->node
.node
->type
;
1845 *domNodeType
= NODE_INVALID
;
1852 static HRESULT WINAPI
unknode_get_parentNode(
1854 IXMLDOMNode
** parent
)
1856 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1857 FIXME("(%p)->(%p)\n", This
, parent
);
1858 if (!parent
) return E_INVALIDARG
;
1863 static HRESULT WINAPI
unknode_get_childNodes(
1865 IXMLDOMNodeList
** outList
)
1867 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1869 TRACE("(%p)->(%p)\n", This
, outList
);
1871 return node_get_child_nodes(&This
->node
, outList
);
1874 static HRESULT WINAPI
unknode_get_firstChild(
1876 IXMLDOMNode
** domNode
)
1878 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1880 TRACE("(%p)->(%p)\n", This
, domNode
);
1882 return node_get_first_child(&This
->node
, domNode
);
1885 static HRESULT WINAPI
unknode_get_lastChild(
1887 IXMLDOMNode
** domNode
)
1889 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1891 TRACE("(%p)->(%p)\n", This
, domNode
);
1893 return node_get_last_child(&This
->node
, domNode
);
1896 static HRESULT WINAPI
unknode_get_previousSibling(
1898 IXMLDOMNode
** domNode
)
1900 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1902 TRACE("(%p)->(%p)\n", This
, domNode
);
1904 return node_get_previous_sibling(&This
->node
, domNode
);
1907 static HRESULT WINAPI
unknode_get_nextSibling(
1909 IXMLDOMNode
** domNode
)
1911 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1913 TRACE("(%p)->(%p)\n", This
, domNode
);
1915 return node_get_next_sibling(&This
->node
, domNode
);
1918 static HRESULT WINAPI
unknode_get_attributes(
1920 IXMLDOMNamedNodeMap
** attributeMap
)
1922 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1924 FIXME("(%p)->(%p)\n", This
, attributeMap
);
1926 return return_null_ptr((void**)attributeMap
);
1929 static HRESULT WINAPI
unknode_insertBefore(
1931 IXMLDOMNode
* newNode
, VARIANT refChild
,
1932 IXMLDOMNode
** outOldNode
)
1934 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1936 FIXME("(%p)->(%p x%d %p)\n", This
, newNode
, V_VT(&refChild
), outOldNode
);
1938 return node_insert_before(&This
->node
, newNode
, &refChild
, outOldNode
);
1941 static HRESULT WINAPI
unknode_replaceChild(
1943 IXMLDOMNode
* newNode
,
1944 IXMLDOMNode
* oldNode
,
1945 IXMLDOMNode
** outOldNode
)
1947 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1949 FIXME("(%p)->(%p %p %p)\n", This
, newNode
, oldNode
, outOldNode
);
1951 return node_replace_child(&This
->node
, newNode
, oldNode
, outOldNode
);
1954 static HRESULT WINAPI
unknode_removeChild(
1956 IXMLDOMNode
* domNode
, IXMLDOMNode
** oldNode
)
1958 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1959 return node_remove_child(&This
->node
, domNode
, oldNode
);
1962 static HRESULT WINAPI
unknode_appendChild(
1964 IXMLDOMNode
* newNode
, IXMLDOMNode
** outNewNode
)
1966 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1967 return node_append_child(&This
->node
, newNode
, outNewNode
);
1970 static HRESULT WINAPI
unknode_hasChildNodes(
1972 VARIANT_BOOL
* pbool
)
1974 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1975 return node_has_childnodes(&This
->node
, pbool
);
1978 static HRESULT WINAPI
unknode_get_ownerDocument(
1980 IXMLDOMDocument
** domDocument
)
1982 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1983 return node_get_owner_doc(&This
->node
, domDocument
);
1986 static HRESULT WINAPI
unknode_cloneNode(
1988 VARIANT_BOOL pbool
, IXMLDOMNode
** outNode
)
1990 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
1991 return node_clone(&This
->node
, pbool
, outNode
);
1994 static HRESULT WINAPI
unknode_get_nodeTypeString(
1998 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2000 FIXME("(%p)->(%p)\n", This
, p
);
2002 return node_get_nodeName(&This
->node
, p
);
2005 static HRESULT WINAPI
unknode_get_text(
2009 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2010 return node_get_text(&This
->node
, p
);
2013 static HRESULT WINAPI
unknode_put_text(
2017 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2018 return node_put_text(&This
->node
, p
);
2021 static HRESULT WINAPI
unknode_get_specified(
2023 VARIANT_BOOL
* isSpecified
)
2025 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2026 FIXME("(%p)->(%p) stub!\n", This
, isSpecified
);
2027 *isSpecified
= VARIANT_TRUE
;
2031 static HRESULT WINAPI
unknode_get_definition(
2033 IXMLDOMNode
** definitionNode
)
2035 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2036 FIXME("(%p)->(%p)\n", This
, definitionNode
);
2040 static HRESULT WINAPI
unknode_get_nodeTypedValue(
2044 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2045 FIXME("(%p)->(%p)\n", This
, var1
);
2046 return return_null_var(var1
);
2049 static HRESULT WINAPI
unknode_put_nodeTypedValue(
2053 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2054 FIXME("(%p)->(%s)\n", This
, debugstr_variant(&typedValue
));
2058 static HRESULT WINAPI
unknode_get_dataType(
2062 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2063 TRACE("(%p)->(%p)\n", This
, var1
);
2064 return return_null_var(var1
);
2067 static HRESULT WINAPI
unknode_put_dataType(
2071 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2073 FIXME("(%p)->(%s)\n", This
, debugstr_w(p
));
2076 return E_INVALIDARG
;
2081 static HRESULT WINAPI
unknode_get_xml(
2085 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2087 FIXME("(%p)->(%p)\n", This
, p
);
2089 return node_get_xml(&This
->node
, FALSE
, p
);
2092 static HRESULT WINAPI
unknode_transformNode(
2094 IXMLDOMNode
* domNode
, BSTR
* p
)
2096 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2097 return node_transform_node(&This
->node
, domNode
, p
);
2100 static HRESULT WINAPI
unknode_selectNodes(
2102 BSTR p
, IXMLDOMNodeList
** outList
)
2104 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2105 return node_select_nodes(&This
->node
, p
, outList
);
2108 static HRESULT WINAPI
unknode_selectSingleNode(
2110 BSTR p
, IXMLDOMNode
** outNode
)
2112 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2113 return node_select_singlenode(&This
->node
, p
, outNode
);
2116 static HRESULT WINAPI
unknode_get_parsed(
2118 VARIANT_BOOL
* isParsed
)
2120 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2121 FIXME("(%p)->(%p) stub!\n", This
, isParsed
);
2122 *isParsed
= VARIANT_TRUE
;
2126 static HRESULT WINAPI
unknode_get_namespaceURI(
2130 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2131 TRACE("(%p)->(%p)\n", This
, p
);
2132 return node_get_namespaceURI(&This
->node
, p
);
2135 static HRESULT WINAPI
unknode_get_prefix(
2139 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2140 return node_get_prefix(&This
->node
, p
);
2143 static HRESULT WINAPI
unknode_get_baseName(
2147 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2148 return node_get_base_name(&This
->node
, p
);
2151 static HRESULT WINAPI
unknode_transformNodeToObject(
2153 IXMLDOMNode
* domNode
, VARIANT var1
)
2155 unknode
*This
= unknode_from_IXMLDOMNode( iface
);
2156 FIXME("(%p)->(%p %s)\n", This
, domNode
, debugstr_variant(&var1
));
2160 static const struct IXMLDOMNodeVtbl unknode_vtbl
=
2162 unknode_QueryInterface
,
2165 unknode_GetTypeInfoCount
,
2166 unknode_GetTypeInfo
,
2167 unknode_GetIDsOfNames
,
2169 unknode_get_nodeName
,
2170 unknode_get_nodeValue
,
2171 unknode_put_nodeValue
,
2172 unknode_get_nodeType
,
2173 unknode_get_parentNode
,
2174 unknode_get_childNodes
,
2175 unknode_get_firstChild
,
2176 unknode_get_lastChild
,
2177 unknode_get_previousSibling
,
2178 unknode_get_nextSibling
,
2179 unknode_get_attributes
,
2180 unknode_insertBefore
,
2181 unknode_replaceChild
,
2182 unknode_removeChild
,
2183 unknode_appendChild
,
2184 unknode_hasChildNodes
,
2185 unknode_get_ownerDocument
,
2187 unknode_get_nodeTypeString
,
2190 unknode_get_specified
,
2191 unknode_get_definition
,
2192 unknode_get_nodeTypedValue
,
2193 unknode_put_nodeTypedValue
,
2194 unknode_get_dataType
,
2195 unknode_put_dataType
,
2197 unknode_transformNode
,
2198 unknode_selectNodes
,
2199 unknode_selectSingleNode
,
2201 unknode_get_namespaceURI
,
2203 unknode_get_baseName
,
2204 unknode_transformNodeToObject
2207 IXMLDOMNode
*create_node( xmlNodePtr node
)
2216 TRACE("type %d\n", node
->type
);
2219 case XML_ELEMENT_NODE
:
2220 pUnk
= create_element( node
);
2222 case XML_ATTRIBUTE_NODE
:
2223 pUnk
= create_attribute( node
, FALSE
);
2226 pUnk
= create_text( node
);
2228 case XML_CDATA_SECTION_NODE
:
2229 pUnk
= create_cdata( node
);
2231 case XML_ENTITY_REF_NODE
:
2232 pUnk
= create_doc_entity_ref( node
);
2235 pUnk
= create_pi( node
);
2237 case XML_COMMENT_NODE
:
2238 pUnk
= create_comment( node
);
2240 case XML_DOCUMENT_NODE
:
2241 pUnk
= create_domdoc( node
);
2243 case XML_DOCUMENT_FRAG_NODE
:
2244 pUnk
= create_doc_fragment( node
);
2247 case XML_DOCUMENT_TYPE_NODE
:
2248 pUnk
= create_doc_type( node
);
2250 case XML_ENTITY_NODE
:
2251 case XML_NOTATION_NODE
: {
2254 FIXME("only creating basic node for type %d\n", node
->type
);
2256 new_node
= heap_alloc(sizeof(unknode
));
2260 new_node
->IXMLDOMNode_iface
.lpVtbl
= &unknode_vtbl
;
2262 init_xmlnode(&new_node
->node
, node
, &new_node
->IXMLDOMNode_iface
, NULL
);
2263 pUnk
= (IUnknown
*)&new_node
->IXMLDOMNode_iface
;
2267 ERR("Called for unsupported node type %d\n", node
->type
);
2271 hr
= IUnknown_QueryInterface(pUnk
, &IID_IXMLDOMNode
, (LPVOID
*)&ret
);
2272 IUnknown_Release(pUnk
);
2273 if(FAILED(hr
)) return NULL
;