4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 # include <libxml/HTMLtree.h>
31 # ifdef SONAME_LIBXSLT
32 # ifdef HAVE_LIBXSLT_PATTERN_H
33 # include <libxslt/pattern.h>
35 # ifdef HAVE_LIBXSLT_TRANSFORM_H
36 # include <libxslt/transform.h>
38 # include <libxslt/xsltutils.h>
39 # include <libxslt/xsltInternals.h>
50 #include "msxml_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
59 extern void* libxslt_handle;
60 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
61 MAKE_FUNCPTR(xsltApplyStylesheet);
62 MAKE_FUNCPTR(xsltCleanupGlobals);
63 MAKE_FUNCPTR(xsltFreeStylesheet);
64 MAKE_FUNCPTR(xsltParseStylesheetDoc);
68 static const IID IID_xmlnode = {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
70 xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type )
76 This = get_node_obj( iface );
77 if ( !This || !This->node )
79 if ( type && This->node->type != type )
84 BOOL node_query_interface(xmlnode *This, REFIID riid, void **ppv)
86 if(IsEqualGUID(&IID_xmlnode, riid)) {
87 TRACE("(%p)->(IID_xmlnode %p)\n", This, ppv);
92 return dispex_query_interface(&This->dispex, riid, ppv);
95 /* common ISupportErrorInfo implementation */
97 ISupportErrorInfo ISupportErrorInfo_iface;
103 static inline SupportErrorInfo *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
105 return CONTAINING_RECORD(iface, SupportErrorInfo, ISupportErrorInfo_iface);
108 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **obj)
110 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
111 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
115 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISupportErrorInfo)) {
117 ISupportErrorInfo_AddRef(iface);
121 return E_NOINTERFACE;
124 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
126 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
127 ULONG ref = InterlockedIncrement(&This->ref);
128 TRACE("(%p)->(%d)\n", This, ref );
132 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
134 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
135 LONG ref = InterlockedDecrement(&This->ref);
137 TRACE("(%p)->(%d)\n", This, ref);
145 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
147 SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
148 enum tid_t const *tid;
150 TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
155 if (IsEqualGUID(riid, get_riid_from_tid(*tid)))
163 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
164 SupportErrorInfo_QueryInterface,
165 SupportErrorInfo_AddRef,
166 SupportErrorInfo_Release,
167 SupportErrorInfo_InterfaceSupportsErrorInfo
170 HRESULT node_create_supporterrorinfo(enum tid_t const *iids, void **obj)
172 SupportErrorInfo *This;
174 This = heap_alloc(sizeof(*This));
175 if (!This) return E_OUTOFMEMORY;
177 This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
181 *obj = &This->ISupportErrorInfo_iface;
186 xmlnode *get_node_obj(IXMLDOMNode *node)
191 hres = IXMLDOMNode_QueryInterface(node, &IID_xmlnode, (void**)&obj);
192 if (!obj) WARN("node is not our IXMLDOMNode implementation\n");
193 return SUCCEEDED(hres) ? obj : NULL;
196 HRESULT node_get_nodeName(xmlnode *This, BSTR *name)
204 hr = node_get_base_name(This, &base);
205 if (hr != S_OK) return hr;
207 hr = node_get_prefix(This, &prefix);
210 static const WCHAR colW = ':';
214 ptr = *name = SysAllocStringLen(NULL, SysStringLen(base) + SysStringLen(prefix) + 1);
215 memcpy(ptr, prefix, SysStringByteLen(prefix));
216 ptr += SysStringLen(prefix);
217 memcpy(ptr++, &colW, sizeof(WCHAR));
218 memcpy(ptr, base, SysStringByteLen(base));
221 SysFreeString(prefix);
229 HRESULT node_get_content(xmlnode *This, VARIANT *value)
236 content = xmlNodeGetContent(This->node);
237 V_VT(value) = VT_BSTR;
238 V_BSTR(value) = bstr_from_xmlChar( content );
241 TRACE("%p returned %s\n", This, debugstr_w(V_BSTR(value)));
245 HRESULT node_set_content(xmlnode *This, LPCWSTR value)
249 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
250 str = xmlchar_from_wchar(value);
252 return E_OUTOFMEMORY;
254 xmlNodeSetContent(This->node, str);
259 static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
261 xmlChar *str, *escaped;
263 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
264 str = xmlchar_from_wchar(value);
266 return E_OUTOFMEMORY;
268 escaped = xmlEncodeSpecialChars(NULL, str);
272 return E_OUTOFMEMORY;
275 xmlNodeSetContent(This->node, escaped);
283 HRESULT node_put_value(xmlnode *This, VARIANT *value)
287 if (V_VT(value) != VT_BSTR)
289 VARIANT string_value;
291 VariantInit(&string_value);
292 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
294 WARN("Couldn't convert to VT_BSTR\n");
298 hr = node_set_content(This, V_BSTR(&string_value));
299 VariantClear(&string_value);
302 hr = node_set_content(This, V_BSTR(value));
307 HRESULT node_put_value_escaped(xmlnode *This, VARIANT *value)
311 if (V_VT(value) != VT_BSTR)
313 VARIANT string_value;
315 VariantInit(&string_value);
316 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
318 WARN("Couldn't convert to VT_BSTR\n");
322 hr = node_set_content_escaped(This, V_BSTR(&string_value));
323 VariantClear(&string_value);
326 hr = node_set_content_escaped(This, V_BSTR(value));
331 static HRESULT get_node(
337 TRACE("(%p)->(%s %p %p)\n", This, name, node, out );
342 /* if we don't have a doc, use our parent. */
343 if(node && !node->doc && node->parent)
344 node->doc = node->parent->doc;
346 *out = create_node( node );
352 HRESULT node_get_parent(xmlnode *This, IXMLDOMNode **parent)
354 return get_node( This, "parent", This->node->parent, parent );
357 HRESULT node_get_child_nodes(xmlnode *This, IXMLDOMNodeList **ret)
362 *ret = create_children_nodelist(This->node);
364 return E_OUTOFMEMORY;
369 HRESULT node_get_first_child(xmlnode *This, IXMLDOMNode **ret)
371 return get_node(This, "firstChild", This->node->children, ret);
374 HRESULT node_get_last_child(xmlnode *This, IXMLDOMNode **ret)
376 return get_node(This, "lastChild", This->node->last, ret);
379 HRESULT node_get_previous_sibling(xmlnode *This, IXMLDOMNode **ret)
381 return get_node(This, "previous", This->node->prev, ret);
384 HRESULT node_get_next_sibling(xmlnode *This, IXMLDOMNode **ret)
386 return get_node(This, "next", This->node->next, ret);
389 static int node_get_inst_cnt(xmlNodePtr node)
391 int ret = *(LONG *)&node->_private;
394 /* add attribute counts */
395 if (node->type == XML_ELEMENT_NODE)
397 xmlAttrPtr prop = node->properties;
401 ret += node_get_inst_cnt((xmlNodePtr)prop);
406 /* add children counts */
407 child = node->children;
410 ret += node_get_inst_cnt(child);
417 int xmlnode_get_inst_cnt(xmlnode *node)
419 return node_get_inst_cnt(node->node);
422 HRESULT node_insert_before(xmlnode *This, IXMLDOMNode *new_child, const VARIANT *ref_child,
425 IXMLDOMNode *before = NULL;
434 node_obj = get_node_obj(new_child);
435 if(!node_obj) return E_FAIL;
437 switch(V_VT(ref_child))
445 if (V_UNKNOWN(ref_child))
447 hr = IUnknown_QueryInterface(V_UNKNOWN(ref_child), &IID_IXMLDOMNode, (void**)&before);
448 if(FAILED(hr)) return hr;
453 FIXME("refChild var type %x\n", V_VT(ref_child));
457 TRACE("new child %p, This->node %p\n", node_obj->node, This->node);
459 if(!node_obj->node->parent)
460 if(xmldoc_remove_orphan(node_obj->node->doc, node_obj->node) != S_OK)
461 WARN("%p is not an orphan of %p\n", node_obj->node, node_obj->node->doc);
463 refcount = xmlnode_get_inst_cnt(node_obj);
467 xmlnode *before_node_obj = get_node_obj(before);
468 IXMLDOMNode_Release(before);
469 if(!before_node_obj) return E_FAIL;
471 /* unlink from current parent first */
474 hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
475 if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
478 doc = node_obj->node->doc;
480 /* refs count including subtree */
481 if (doc != before_node_obj->node->doc)
482 refcount = xmlnode_get_inst_cnt(node_obj);
484 if (refcount) xmldoc_add_refs(before_node_obj->node->doc, refcount);
485 xmlAddPrevSibling(before_node_obj->node, node_obj->node);
486 if (refcount) xmldoc_release_refs(doc, refcount);
487 node_obj->parent = This->parent;
491 /* unlink from current parent first */
494 hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
495 if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
497 doc = node_obj->node->doc;
499 if (doc != This->node->doc)
500 refcount = xmlnode_get_inst_cnt(node_obj);
502 if (refcount) xmldoc_add_refs(This->node->doc, refcount);
503 /* xmlAddChild doesn't unlink node from previous parent */
504 xmlUnlinkNode(node_obj->node);
505 xmlAddChild(This->node, node_obj->node);
506 if (refcount) xmldoc_release_refs(doc, refcount);
507 node_obj->parent = This->iface;
512 IXMLDOMNode_AddRef(new_child);
520 HRESULT node_replace_child(xmlnode *This, IXMLDOMNode *newChild, IXMLDOMNode *oldChild,
523 xmlnode *old_child, *new_child;
524 xmlDocPtr leaving_doc;
525 xmlNode *my_ancestor;
528 /* Do not believe any documentation telling that newChild == NULL
529 means removal. It does certainly *not* apply to msxml3! */
530 if(!newChild || !oldChild)
536 old_child = get_node_obj(oldChild);
537 if(!old_child) return E_FAIL;
539 if(old_child->node->parent != This->node)
541 WARN("childNode %p is not a child of %p\n", oldChild, This);
545 new_child = get_node_obj(newChild);
546 if(!new_child) return E_FAIL;
548 my_ancestor = This->node;
551 if(my_ancestor == new_child->node)
553 WARN("tried to create loop\n");
556 my_ancestor = my_ancestor->parent;
559 if(!new_child->node->parent)
560 if(xmldoc_remove_orphan(new_child->node->doc, new_child->node) != S_OK)
561 WARN("%p is not an orphan of %p\n", new_child->node, new_child->node->doc);
563 leaving_doc = new_child->node->doc;
565 if (leaving_doc != old_child->node->doc)
566 refcount = xmlnode_get_inst_cnt(new_child);
568 if (refcount) xmldoc_add_refs(old_child->node->doc, refcount);
569 xmlReplaceNode(old_child->node, new_child->node);
570 if (refcount) xmldoc_release_refs(leaving_doc, refcount);
571 new_child->parent = old_child->parent;
572 old_child->parent = NULL;
574 xmldoc_add_orphan(old_child->node->doc, old_child->node);
578 IXMLDOMNode_AddRef(oldChild);
585 HRESULT node_remove_child(xmlnode *This, IXMLDOMNode* child, IXMLDOMNode** oldChild)
589 if(!child) return E_INVALIDARG;
594 child_node = get_node_obj(child);
595 if(!child_node) return E_FAIL;
597 if(child_node->node->parent != This->node)
599 WARN("childNode %p is not a child of %p\n", child, This);
603 xmlUnlinkNode(child_node->node);
604 child_node->parent = NULL;
605 xmldoc_add_orphan(child_node->node->doc, child_node->node);
609 IXMLDOMNode_AddRef(child);
616 HRESULT node_append_child(xmlnode *This, IXMLDOMNode *child, IXMLDOMNode **outChild)
622 hr = IXMLDOMNode_get_nodeType(child, &type);
623 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
624 if (outChild) *outChild = NULL;
629 return IXMLDOMNode_insertBefore(This->iface, child, var, outChild);
632 HRESULT node_has_childnodes(const xmlnode *This, VARIANT_BOOL *ret)
634 if (!ret) return E_INVALIDARG;
636 if (!This->node->children)
638 *ret = VARIANT_FALSE;
646 HRESULT node_get_owner_doc(const xmlnode *This, IXMLDOMDocument **doc)
648 return get_domdoc_from_xmldoc(This->node->doc, (IXMLDOMDocument3**)doc);
651 HRESULT node_clone(xmlnode *This, VARIANT_BOOL deep, IXMLDOMNode **cloneNode)
656 if(!cloneNode) return E_INVALIDARG;
658 clone = xmlCopyNode(This->node, deep ? 1 : 2);
661 xmlSetTreeDoc(clone, This->node->doc);
662 xmldoc_add_orphan(clone->doc, clone);
664 node = create_node(clone);
667 ERR("Copy failed\n");
668 xmldoc_remove_orphan(clone->doc, clone);
677 ERR("Copy failed\n");
684 static inline xmlChar* trim_whitespace(xmlChar* str)
692 while (*ret && isspace(*ret))
694 len = xmlStrlen(ret);
696 while (isspace(ret[len-1])) --len;
698 ret = xmlStrndup(ret, len);
703 static xmlChar* do_get_text(xmlNodePtr node)
707 BOOL preserving = is_preserving_whitespace(node);
711 str = xmlNodeGetContent(node);
715 xmlElementType prev_type = XML_TEXT_NODE;
717 str = xmlStrdup(BAD_CAST "");
718 for (child = node->children; child != NULL; child = child->next)
722 case XML_ELEMENT_NODE:
723 tmp = do_get_text(child);
726 case XML_CDATA_SECTION_NODE:
727 case XML_ENTITY_REF_NODE:
728 case XML_ENTITY_NODE:
729 tmp = xmlNodeGetContent(child);
740 if (prev_type == XML_ELEMENT_NODE && child->type == XML_ELEMENT_NODE)
741 str = xmlStrcat(str, BAD_CAST " ");
742 str = xmlStrcat(str, tmp);
743 prev_type = child->type;
752 case XML_ELEMENT_NODE:
754 case XML_ENTITY_REF_NODE:
755 case XML_ENTITY_NODE:
756 case XML_DOCUMENT_NODE:
757 case XML_DOCUMENT_FRAG_NODE:
759 str = trim_whitespace(str);
768 HRESULT node_get_text(const xmlnode *This, BSTR *text)
773 if (!text) return E_INVALIDARG;
775 content = do_get_text(This->node);
778 str = bstr_from_xmlChar(content);
782 /* Always return a string. */
783 if (!str) str = SysAllocStringLen( NULL, 0 );
785 TRACE("%p %s\n", This, debugstr_w(str) );
791 HRESULT node_put_text(xmlnode *This, BSTR text)
795 TRACE("(%p)->(%s)\n", This, debugstr_w(text));
797 str = xmlchar_from_wchar(text);
799 /* Escape the string. */
800 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
803 xmlNodeSetContent(This->node, str2);
809 BSTR EnsureCorrectEOL(BSTR sInput)
816 nLen = SysStringLen(sInput);
817 /* Count line endings */
818 for(i=0; i < nLen; i++)
820 if(sInput[i] == '\n')
824 TRACE("len=%d, num=%d\n", nLen, nNum);
826 /* Add linefeed as needed */
830 sNew = SysAllocStringLen(NULL, nLen + nNum);
831 for(i=0; i < nLen; i++)
833 if(sInput[i] == '\n')
835 sNew[i+nPlace] = '\r';
838 sNew[i+nPlace] = sInput[i];
841 SysFreeString(sInput);
848 TRACE("len %d\n", SysStringLen(sNew));
854 * We are trying to replicate the same behaviour as msxml by converting
855 * line endings to \r\n and using indents as \t. The problem is that msxml
856 * only formats nodes that have a line ending. Using libxml we cannot
857 * reproduce behaviour exactly.
860 HRESULT node_get_xml(xmlnode *This, BOOL ensure_eol, BSTR *ret)
862 xmlBufferPtr xml_buf;
871 xml_buf = xmlBufferCreate();
873 return E_OUTOFMEMORY;
875 xmldecl = xmldoc_unlink_xmldecl( This->node->doc );
877 size = xmlNodeDump(xml_buf, This->node->doc, This->node, 0, 1);
879 const xmlChar *buf_content;
882 /* Attribute Nodes return a space in front of their name */
883 buf_content = xmlBufferContent(xml_buf);
885 content = bstr_from_xmlChar(buf_content + (buf_content[0] == ' ' ? 1 : 0));
887 content = EnsureCorrectEOL(content);
891 *ret = SysAllocStringLen(NULL, 0);
894 xmlBufferFree(xml_buf);
895 xmldoc_link_xmldecl( This->node->doc, xmldecl );
896 return *ret ? S_OK : E_OUTOFMEMORY;
899 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
901 xmlDtdPtr cur = doc->intSubset;
903 xmlOutputBufferWriteString(buf, "<!DOCTYPE ");
904 xmlOutputBufferWriteString(buf, (const char *)cur->name);
907 xmlOutputBufferWriteString(buf, " PUBLIC ");
908 xmlBufferWriteQuotedString(buf->buffer, cur->ExternalID);
911 xmlOutputBufferWriteString(buf, " ");
912 xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
915 else if (cur->SystemID)
917 xmlOutputBufferWriteString(buf, " SYSTEM ");
918 xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
920 xmlOutputBufferWriteString(buf, ">\n");
923 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
927 /* force HTML output */
929 doc->type = XML_HTML_DOCUMENT_NODE;
931 htmldtd_dumpcontent(buf, doc);
934 xmlNodePtr cur = doc->children;
938 htmlNodeDumpFormatOutput(buf, doc, cur, NULL, 1);
946 HRESULT node_transform_node(const xmlnode *This, IXMLDOMNode *stylesheet, BSTR *p)
948 #ifdef SONAME_LIBXSLT
949 xsltStylesheetPtr xsltSS;
952 if (!libxslt_handle) return E_NOTIMPL;
953 if (!stylesheet || !p) return E_INVALIDARG;
957 sheet = get_node_obj(stylesheet);
958 if(!sheet) return E_FAIL;
960 xsltSS = pxsltParseStylesheetDoc(sheet->node->doc);
963 xmlDocPtr result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
966 const xmlChar *content;
968 if(result->type == XML_HTML_DOCUMENT_NODE)
970 xmlOutputBufferPtr output = xmlAllocOutputBuffer(NULL);
973 htmldoc_dumpcontent(output, result->doc);
974 content = xmlBufferContent(output->buffer);
975 *p = bstr_from_xmlChar(content);
976 xmlOutputBufferClose(output);
981 xmlBufferPtr buf = xmlBufferCreate();
984 int size = xmlNodeDump(buf, NULL, (xmlNodePtr)result, 0, 0);
987 content = xmlBufferContent(buf);
988 *p = bstr_from_xmlChar(content);
995 /* libxslt "helpfully" frees the XML document the stylesheet was
996 generated from, too */
998 pxsltFreeStylesheet(xsltSS);
1001 if(!*p) *p = SysAllocStringLen(NULL, 0);
1005 FIXME("libxslt headers were not found at compile time\n");
1010 HRESULT node_select_nodes(const xmlnode *This, BSTR query, IXMLDOMNodeList **nodes)
1015 if (!query || !nodes) return E_INVALIDARG;
1017 str = xmlchar_from_wchar(query);
1018 hr = create_selection(This->node, str, nodes);
1024 HRESULT node_select_singlenode(const xmlnode *This, BSTR query, IXMLDOMNode **node)
1026 IXMLDOMNodeList *list;
1029 hr = node_select_nodes(This, query, &list);
1032 hr = IXMLDOMNodeList_nextNode(list, node);
1033 IXMLDOMNodeList_Release(list);
1038 HRESULT node_get_namespaceURI(xmlnode *This, BSTR *namespaceURI)
1040 xmlNsPtr ns = This->node->ns;
1043 return E_INVALIDARG;
1045 *namespaceURI = NULL;
1048 *namespaceURI = bstr_from_xmlChar(ns->href);
1050 TRACE("uri: %s\n", debugstr_w(*namespaceURI));
1052 return *namespaceURI ? S_OK : S_FALSE;
1055 HRESULT node_get_prefix(xmlnode *This, BSTR *prefix)
1057 xmlNsPtr ns = This->node->ns;
1059 if (!prefix) return E_INVALIDARG;
1063 if (ns && ns->prefix)
1064 *prefix = bstr_from_xmlChar(ns->prefix);
1066 TRACE("prefix: %s\n", debugstr_w(*prefix));
1068 return *prefix ? S_OK : S_FALSE;
1071 HRESULT node_get_base_name(xmlnode *This, BSTR *name)
1073 if (!name) return E_INVALIDARG;
1075 *name = bstr_from_xmlChar(This->node->name);
1076 if (!*name) return E_OUTOFMEMORY;
1078 TRACE("returning %s\n", debugstr_w(*name));
1083 /* _private field holds a number of COM instances spawned from this libxml2 node */
1084 static void xmlnode_add_ref(xmlNodePtr node)
1086 if (node->type == XML_DOCUMENT_NODE) return;
1087 InterlockedIncrement((LONG*)&node->_private);
1090 static void xmlnode_release(xmlNodePtr node)
1092 if (node->type == XML_DOCUMENT_NODE) return;
1093 InterlockedDecrement((LONG*)&node->_private);
1096 void destroy_xmlnode(xmlnode *This)
1100 xmlnode_release(This->node);
1101 xmldoc_release(This->node->doc);
1103 release_dispex(&This->dispex);
1106 void init_xmlnode(xmlnode *This, xmlNodePtr node, IXMLDOMNode *node_iface, dispex_static_data_t *dispex_data)
1110 xmlnode_add_ref(node);
1111 xmldoc_add_ref(node->doc);
1115 This->iface = node_iface;
1116 This->parent = NULL;
1118 init_dispex(&This->dispex, (IUnknown*)This->iface, dispex_data);
1123 IXMLDOMNode IXMLDOMNode_iface;
1127 static inline unknode *unknode_from_IXMLDOMNode(IXMLDOMNode *iface)
1129 return CONTAINING_RECORD(iface, unknode, IXMLDOMNode_iface);
1132 static HRESULT WINAPI unknode_QueryInterface(
1137 unknode *This = unknode_from_IXMLDOMNode( iface );
1139 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
1141 if (IsEqualGUID(riid, &IID_IUnknown)) {
1143 }else if (IsEqualGUID( riid, &IID_IDispatch) ||
1144 IsEqualGUID( riid, &IID_IXMLDOMNode)) {
1145 *ppvObject = &This->IXMLDOMNode_iface;
1146 }else if(node_query_interface(&This->node, riid, ppvObject)) {
1147 return *ppvObject ? S_OK : E_NOINTERFACE;
1149 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1151 return E_NOINTERFACE;
1154 IUnknown_AddRef((IUnknown*)*ppvObject);
1158 static ULONG WINAPI unknode_AddRef(
1159 IXMLDOMNode *iface )
1161 unknode *This = unknode_from_IXMLDOMNode( iface );
1163 return InterlockedIncrement(&This->ref);
1166 static ULONG WINAPI unknode_Release(
1167 IXMLDOMNode *iface )
1169 unknode *This = unknode_from_IXMLDOMNode( iface );
1172 ref = InterlockedDecrement( &This->ref );
1174 destroy_xmlnode(&This->node);
1181 static HRESULT WINAPI unknode_GetTypeInfoCount(
1185 unknode *This = unknode_from_IXMLDOMNode( iface );
1187 TRACE("(%p)->(%p)\n", This, pctinfo);
1194 static HRESULT WINAPI unknode_GetTypeInfo(
1198 ITypeInfo** ppTInfo )
1200 unknode *This = unknode_from_IXMLDOMNode( iface );
1203 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1205 hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo);
1210 static HRESULT WINAPI unknode_GetIDsOfNames(
1213 LPOLESTR* rgszNames,
1218 unknode *This = unknode_from_IXMLDOMNode( iface );
1220 ITypeInfo *typeinfo;
1223 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1226 if(!rgszNames || cNames == 0 || !rgDispId)
1227 return E_INVALIDARG;
1229 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1232 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1233 ITypeInfo_Release(typeinfo);
1239 static HRESULT WINAPI unknode_Invoke(
1241 DISPID dispIdMember,
1245 DISPPARAMS* pDispParams,
1246 VARIANT* pVarResult,
1247 EXCEPINFO* pExcepInfo,
1250 unknode *This = unknode_from_IXMLDOMNode( iface );
1251 ITypeInfo *typeinfo;
1254 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1255 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1257 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1260 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNode_iface, dispIdMember, wFlags, pDispParams,
1261 pVarResult, pExcepInfo, puArgErr);
1262 ITypeInfo_Release(typeinfo);
1268 static HRESULT WINAPI unknode_get_nodeName(
1272 unknode *This = unknode_from_IXMLDOMNode( iface );
1274 FIXME("(%p)->(%p)\n", This, p);
1276 return node_get_nodeName(&This->node, p);
1279 static HRESULT WINAPI unknode_get_nodeValue(
1283 unknode *This = unknode_from_IXMLDOMNode( iface );
1285 FIXME("(%p)->(%p)\n", This, value);
1288 return E_INVALIDARG;
1290 V_VT(value) = VT_NULL;
1294 static HRESULT WINAPI unknode_put_nodeValue(
1298 unknode *This = unknode_from_IXMLDOMNode( iface );
1299 FIXME("(%p)->(v%d)\n", This, V_VT(&value));
1303 static HRESULT WINAPI unknode_get_nodeType(
1305 DOMNodeType* domNodeType )
1307 unknode *This = unknode_from_IXMLDOMNode( iface );
1309 FIXME("(%p)->(%p)\n", This, domNodeType);
1311 *domNodeType = This->node.node->type;
1315 static HRESULT WINAPI unknode_get_parentNode(
1317 IXMLDOMNode** parent )
1319 unknode *This = unknode_from_IXMLDOMNode( iface );
1320 FIXME("(%p)->(%p)\n", This, parent);
1321 if (!parent) return E_INVALIDARG;
1326 static HRESULT WINAPI unknode_get_childNodes(
1328 IXMLDOMNodeList** outList)
1330 unknode *This = unknode_from_IXMLDOMNode( iface );
1332 TRACE("(%p)->(%p)\n", This, outList);
1334 return node_get_child_nodes(&This->node, outList);
1337 static HRESULT WINAPI unknode_get_firstChild(
1339 IXMLDOMNode** domNode)
1341 unknode *This = unknode_from_IXMLDOMNode( iface );
1343 TRACE("(%p)->(%p)\n", This, domNode);
1345 return node_get_first_child(&This->node, domNode);
1348 static HRESULT WINAPI unknode_get_lastChild(
1350 IXMLDOMNode** domNode)
1352 unknode *This = unknode_from_IXMLDOMNode( iface );
1354 TRACE("(%p)->(%p)\n", This, domNode);
1356 return node_get_last_child(&This->node, domNode);
1359 static HRESULT WINAPI unknode_get_previousSibling(
1361 IXMLDOMNode** domNode)
1363 unknode *This = unknode_from_IXMLDOMNode( iface );
1365 TRACE("(%p)->(%p)\n", This, domNode);
1367 return node_get_previous_sibling(&This->node, domNode);
1370 static HRESULT WINAPI unknode_get_nextSibling(
1372 IXMLDOMNode** domNode)
1374 unknode *This = unknode_from_IXMLDOMNode( iface );
1376 TRACE("(%p)->(%p)\n", This, domNode);
1378 return node_get_next_sibling(&This->node, domNode);
1381 static HRESULT WINAPI unknode_get_attributes(
1383 IXMLDOMNamedNodeMap** attributeMap)
1385 unknode *This = unknode_from_IXMLDOMNode( iface );
1387 FIXME("(%p)->(%p)\n", This, attributeMap);
1389 return return_null_ptr((void**)attributeMap);
1392 static HRESULT WINAPI unknode_insertBefore(
1394 IXMLDOMNode* newNode, VARIANT refChild,
1395 IXMLDOMNode** outOldNode)
1397 unknode *This = unknode_from_IXMLDOMNode( iface );
1399 FIXME("(%p)->(%p x%d %p)\n", This, newNode, V_VT(&refChild), outOldNode);
1401 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
1404 static HRESULT WINAPI unknode_replaceChild(
1406 IXMLDOMNode* newNode,
1407 IXMLDOMNode* oldNode,
1408 IXMLDOMNode** outOldNode)
1410 unknode *This = unknode_from_IXMLDOMNode( iface );
1412 FIXME("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
1414 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
1417 static HRESULT WINAPI unknode_removeChild(
1419 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
1421 unknode *This = unknode_from_IXMLDOMNode( iface );
1422 return node_remove_child(&This->node, domNode, oldNode);
1425 static HRESULT WINAPI unknode_appendChild(
1427 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
1429 unknode *This = unknode_from_IXMLDOMNode( iface );
1430 return node_append_child(&This->node, newNode, outNewNode);
1433 static HRESULT WINAPI unknode_hasChildNodes(
1435 VARIANT_BOOL* pbool)
1437 unknode *This = unknode_from_IXMLDOMNode( iface );
1438 return node_has_childnodes(&This->node, pbool);
1441 static HRESULT WINAPI unknode_get_ownerDocument(
1443 IXMLDOMDocument** domDocument)
1445 unknode *This = unknode_from_IXMLDOMNode( iface );
1446 return node_get_owner_doc(&This->node, domDocument);
1449 static HRESULT WINAPI unknode_cloneNode(
1451 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
1453 unknode *This = unknode_from_IXMLDOMNode( iface );
1454 return node_clone(&This->node, pbool, outNode );
1457 static HRESULT WINAPI unknode_get_nodeTypeString(
1461 unknode *This = unknode_from_IXMLDOMNode( iface );
1463 FIXME("(%p)->(%p)\n", This, p);
1465 return node_get_nodeName(&This->node, p);
1468 static HRESULT WINAPI unknode_get_text(
1472 unknode *This = unknode_from_IXMLDOMNode( iface );
1473 return node_get_text(&This->node, p);
1476 static HRESULT WINAPI unknode_put_text(
1480 unknode *This = unknode_from_IXMLDOMNode( iface );
1481 return node_put_text(&This->node, p);
1484 static HRESULT WINAPI unknode_get_specified(
1486 VARIANT_BOOL* isSpecified)
1488 unknode *This = unknode_from_IXMLDOMNode( iface );
1489 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
1490 *isSpecified = VARIANT_TRUE;
1494 static HRESULT WINAPI unknode_get_definition(
1496 IXMLDOMNode** definitionNode)
1498 unknode *This = unknode_from_IXMLDOMNode( iface );
1499 FIXME("(%p)->(%p)\n", This, definitionNode);
1503 static HRESULT WINAPI unknode_get_nodeTypedValue(
1507 unknode *This = unknode_from_IXMLDOMNode( iface );
1508 FIXME("(%p)->(%p)\n", This, var1);
1509 return return_null_var(var1);
1512 static HRESULT WINAPI unknode_put_nodeTypedValue(
1516 unknode *This = unknode_from_IXMLDOMNode( iface );
1517 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
1521 static HRESULT WINAPI unknode_get_dataType(
1525 unknode *This = unknode_from_IXMLDOMNode( iface );
1526 TRACE("(%p)->(%p)\n", This, var1);
1527 return return_null_var(var1);
1530 static HRESULT WINAPI unknode_put_dataType(
1534 unknode *This = unknode_from_IXMLDOMNode( iface );
1536 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
1539 return E_INVALIDARG;
1544 static HRESULT WINAPI unknode_get_xml(
1548 unknode *This = unknode_from_IXMLDOMNode( iface );
1550 FIXME("(%p)->(%p)\n", This, p);
1552 return node_get_xml(&This->node, FALSE, p);
1555 static HRESULT WINAPI unknode_transformNode(
1557 IXMLDOMNode* domNode, BSTR* p)
1559 unknode *This = unknode_from_IXMLDOMNode( iface );
1560 return node_transform_node(&This->node, domNode, p);
1563 static HRESULT WINAPI unknode_selectNodes(
1565 BSTR p, IXMLDOMNodeList** outList)
1567 unknode *This = unknode_from_IXMLDOMNode( iface );
1568 return node_select_nodes(&This->node, p, outList);
1571 static HRESULT WINAPI unknode_selectSingleNode(
1573 BSTR p, IXMLDOMNode** outNode)
1575 unknode *This = unknode_from_IXMLDOMNode( iface );
1576 return node_select_singlenode(&This->node, p, outNode);
1579 static HRESULT WINAPI unknode_get_parsed(
1581 VARIANT_BOOL* isParsed)
1583 unknode *This = unknode_from_IXMLDOMNode( iface );
1584 FIXME("(%p)->(%p) stub!\n", This, isParsed);
1585 *isParsed = VARIANT_TRUE;
1589 static HRESULT WINAPI unknode_get_namespaceURI(
1593 unknode *This = unknode_from_IXMLDOMNode( iface );
1594 TRACE("(%p)->(%p)\n", This, p);
1595 return node_get_namespaceURI(&This->node, p);
1598 static HRESULT WINAPI unknode_get_prefix(
1602 unknode *This = unknode_from_IXMLDOMNode( iface );
1603 return node_get_prefix(&This->node, p);
1606 static HRESULT WINAPI unknode_get_baseName(
1610 unknode *This = unknode_from_IXMLDOMNode( iface );
1611 return node_get_base_name(&This->node, p);
1614 static HRESULT WINAPI unknode_transformNodeToObject(
1616 IXMLDOMNode* domNode, VARIANT var1)
1618 unknode *This = unknode_from_IXMLDOMNode( iface );
1619 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1623 static const struct IXMLDOMNodeVtbl unknode_vtbl =
1625 unknode_QueryInterface,
1628 unknode_GetTypeInfoCount,
1629 unknode_GetTypeInfo,
1630 unknode_GetIDsOfNames,
1632 unknode_get_nodeName,
1633 unknode_get_nodeValue,
1634 unknode_put_nodeValue,
1635 unknode_get_nodeType,
1636 unknode_get_parentNode,
1637 unknode_get_childNodes,
1638 unknode_get_firstChild,
1639 unknode_get_lastChild,
1640 unknode_get_previousSibling,
1641 unknode_get_nextSibling,
1642 unknode_get_attributes,
1643 unknode_insertBefore,
1644 unknode_replaceChild,
1645 unknode_removeChild,
1646 unknode_appendChild,
1647 unknode_hasChildNodes,
1648 unknode_get_ownerDocument,
1650 unknode_get_nodeTypeString,
1653 unknode_get_specified,
1654 unknode_get_definition,
1655 unknode_get_nodeTypedValue,
1656 unknode_put_nodeTypedValue,
1657 unknode_get_dataType,
1658 unknode_put_dataType,
1660 unknode_transformNode,
1661 unknode_selectNodes,
1662 unknode_selectSingleNode,
1664 unknode_get_namespaceURI,
1666 unknode_get_baseName,
1667 unknode_transformNodeToObject
1670 IXMLDOMNode *create_node( xmlNodePtr node )
1679 TRACE("type %d\n", node->type);
1682 case XML_ELEMENT_NODE:
1683 pUnk = create_element( node );
1685 case XML_ATTRIBUTE_NODE:
1686 pUnk = create_attribute( node );
1689 pUnk = create_text( node );
1691 case XML_CDATA_SECTION_NODE:
1692 pUnk = create_cdata( node );
1694 case XML_ENTITY_REF_NODE:
1695 pUnk = create_doc_entity_ref( node );
1698 pUnk = create_pi( node );
1700 case XML_COMMENT_NODE:
1701 pUnk = create_comment( node );
1703 case XML_DOCUMENT_NODE:
1704 pUnk = create_domdoc( node );
1706 case XML_DOCUMENT_FRAG_NODE:
1707 pUnk = create_doc_fragment( node );
1710 pUnk = create_doc_type( node );
1715 FIXME("only creating basic node for type %d\n", node->type);
1717 new_node = heap_alloc(sizeof(unknode));
1721 new_node->IXMLDOMNode_iface.lpVtbl = &unknode_vtbl;
1723 init_xmlnode(&new_node->node, node, &new_node->IXMLDOMNode_iface, NULL);
1724 pUnk = (IUnknown*)&new_node->IXMLDOMNode_iface;
1728 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1729 IUnknown_Release(pUnk);
1730 if(FAILED(hr)) return NULL;