wineconsole: Avoid an empty for loop.
[wine.git] / dlls / msxml3 / node.c
blob4c03571e06c4f5965d069cfca5a949150eec3a42
1 /*
2 * Node implementation
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
21 #include "config.h"
23 #define COBJMACROS
25 #include <stdarg.h>
27 #ifdef HAVE_LIBXML2
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>
34 # endif
35 # ifdef HAVE_LIBXSLT_TRANSFORM_H
36 # include <libxslt/transform.h>
37 # endif
38 # include <libxslt/xsltutils.h>
39 # include <libxslt/xsltInternals.h>
40 # endif
41 #endif
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winuser.h"
46 #include "winnls.h"
47 #include "ole2.h"
48 #include "msxml6.h"
50 #include "msxml_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
56 #ifdef HAVE_LIBXML2
58 #ifdef SONAME_LIBXSLT
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);
65 # undef MAKE_FUNCPTR
66 #endif
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 )
72 xmlnode *This;
74 if ( !iface )
75 return NULL;
76 This = get_node_obj( iface );
77 if ( !This || !This->node )
78 return NULL;
79 if ( type && This->node->type != type )
80 return NULL;
81 return This->node;
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);
88 *ppv = This;
89 return TRUE;
92 return dispex_query_interface(&This->dispex, riid, ppv);
95 /* common ISupportErrorInfo implementation */
96 typedef struct {
97 ISupportErrorInfo ISupportErrorInfo_iface;
98 LONG ref;
100 const tid_t* iids;
101 } SupportErrorInfo;
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);
113 *obj = NULL;
115 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISupportErrorInfo)) {
116 *obj = iface;
117 ISupportErrorInfo_AddRef(iface);
118 return S_OK;
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 );
129 return 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);
139 if (ref == 0)
140 heap_free(This);
142 return 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));
152 tid = This->iids;
153 while (*tid != NULL_tid)
155 if (IsEqualGUID(riid, get_riid_from_tid(*tid)))
156 return S_OK;
157 tid++;
160 return S_FALSE;
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;
178 This->ref = 1;
179 This->iids = iids;
181 *obj = &This->ISupportErrorInfo_iface;
183 return S_OK;
186 xmlnode *get_node_obj(IXMLDOMNode *node)
188 xmlnode *obj = NULL;
189 HRESULT hres;
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)
198 BSTR prefix, base;
199 HRESULT hr;
201 if (!name)
202 return E_INVALIDARG;
204 hr = node_get_base_name(This, &base);
205 if (hr != S_OK) return hr;
207 hr = node_get_prefix(This, &prefix);
208 if (hr == S_OK)
210 static const WCHAR colW = ':';
211 WCHAR *ptr;
213 /* +1 for ':' */
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));
220 SysFreeString(base);
221 SysFreeString(prefix);
223 else
224 *name = base;
226 return S_OK;
229 HRESULT node_get_content(xmlnode *This, VARIANT *value)
231 xmlChar *content;
233 if(!value)
234 return E_INVALIDARG;
236 content = xmlNodeGetContent(This->node);
237 V_VT(value) = VT_BSTR;
238 V_BSTR(value) = bstr_from_xmlChar( content );
239 xmlFree(content);
241 TRACE("%p returned %s\n", This, debugstr_w(V_BSTR(value)));
242 return S_OK;
245 HRESULT node_set_content(xmlnode *This, LPCWSTR value)
247 xmlChar *str;
249 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
250 str = xmlchar_from_wchar(value);
251 if(!str)
252 return E_OUTOFMEMORY;
254 xmlNodeSetContent(This->node, str);
255 heap_free(str);
256 return S_OK;
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);
265 if(!str)
266 return E_OUTOFMEMORY;
268 escaped = xmlEncodeSpecialChars(NULL, str);
269 if(!escaped)
271 heap_free(str);
272 return E_OUTOFMEMORY;
275 xmlNodeSetContent(This->node, escaped);
277 heap_free(str);
278 xmlFree(escaped);
280 return S_OK;
283 HRESULT node_put_value(xmlnode *This, VARIANT *value)
285 HRESULT hr;
287 if (V_VT(value) != VT_BSTR)
289 VARIANT string_value;
291 VariantInit(&string_value);
292 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
293 if(FAILED(hr)) {
294 WARN("Couldn't convert to VT_BSTR\n");
295 return hr;
298 hr = node_set_content(This, V_BSTR(&string_value));
299 VariantClear(&string_value);
301 else
302 hr = node_set_content(This, V_BSTR(value));
304 return hr;
307 HRESULT node_put_value_escaped(xmlnode *This, VARIANT *value)
309 HRESULT hr;
311 if (V_VT(value) != VT_BSTR)
313 VARIANT string_value;
315 VariantInit(&string_value);
316 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
317 if(FAILED(hr)) {
318 WARN("Couldn't convert to VT_BSTR\n");
319 return hr;
322 hr = node_set_content_escaped(This, V_BSTR(&string_value));
323 VariantClear(&string_value);
325 else
326 hr = node_set_content_escaped(This, V_BSTR(value));
328 return hr;
331 static HRESULT get_node(
332 xmlnode *This,
333 const char *name,
334 xmlNodePtr node,
335 IXMLDOMNode **out )
337 TRACE("(%p)->(%s %p %p)\n", This, name, node, out );
339 if ( !out )
340 return E_INVALIDARG;
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 );
347 if (!*out)
348 return S_FALSE;
349 return S_OK;
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)
359 if(!ret)
360 return E_INVALIDARG;
362 *ret = create_children_nodelist(This->node);
363 if(!*ret)
364 return E_OUTOFMEMORY;
366 return S_OK;
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;
392 xmlNodePtr child;
394 /* add attribute counts */
395 if (node->type == XML_ELEMENT_NODE)
397 xmlAttrPtr prop = node->properties;
399 while (prop)
401 ret += node_get_inst_cnt((xmlNodePtr)prop);
402 prop = prop->next;
406 /* add children counts */
407 child = node->children;
408 while (child)
410 ret += node_get_inst_cnt(child);
411 child = child->next;
414 return ret;
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,
423 IXMLDOMNode **ret)
425 IXMLDOMNode *before = NULL;
426 xmlnode *node_obj;
427 int refcount = 0;
428 xmlDocPtr doc;
429 HRESULT hr;
431 if(!new_child)
432 return E_INVALIDARG;
434 node_obj = get_node_obj(new_child);
435 if(!node_obj) return E_FAIL;
437 switch(V_VT(ref_child))
439 case VT_EMPTY:
440 case VT_NULL:
441 break;
443 case VT_UNKNOWN:
444 case VT_DISPATCH:
445 if (V_UNKNOWN(ref_child))
447 hr = IUnknown_QueryInterface(V_UNKNOWN(ref_child), &IID_IXMLDOMNode, (void**)&before);
448 if(FAILED(hr)) return hr;
450 break;
452 default:
453 FIXME("refChild var type %x\n", V_VT(ref_child));
454 return E_FAIL;
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);
465 if(before)
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 */
472 if(node_obj->parent)
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;
489 else
491 /* unlink from current parent first */
492 if(node_obj->parent)
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;
510 if(ret)
512 IXMLDOMNode_AddRef(new_child);
513 *ret = new_child;
516 TRACE("ret S_OK\n");
517 return S_OK;
520 HRESULT node_replace_child(xmlnode *This, IXMLDOMNode *newChild, IXMLDOMNode *oldChild,
521 IXMLDOMNode **ret)
523 xmlnode *old_child, *new_child;
524 xmlDocPtr leaving_doc;
525 xmlNode *my_ancestor;
526 int refcount = 0;
528 /* Do not believe any documentation telling that newChild == NULL
529 means removal. It does certainly *not* apply to msxml3! */
530 if(!newChild || !oldChild)
531 return E_INVALIDARG;
533 if(ret)
534 *ret = NULL;
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);
542 return E_INVALIDARG;
545 new_child = get_node_obj(newChild);
546 if(!new_child) return E_FAIL;
548 my_ancestor = This->node;
549 while(my_ancestor)
551 if(my_ancestor == new_child->node)
553 WARN("tried to create loop\n");
554 return E_FAIL;
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);
576 if(ret)
578 IXMLDOMNode_AddRef(oldChild);
579 *ret = oldChild;
582 return S_OK;
585 HRESULT node_remove_child(xmlnode *This, IXMLDOMNode* child, IXMLDOMNode** oldChild)
587 xmlnode *child_node;
589 if(!child) return E_INVALIDARG;
591 if(oldChild)
592 *oldChild = NULL;
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);
600 return E_INVALIDARG;
603 xmlUnlinkNode(child_node->node);
604 child_node->parent = NULL;
605 xmldoc_add_orphan(child_node->node->doc, child_node->node);
607 if(oldChild)
609 IXMLDOMNode_AddRef(child);
610 *oldChild = child;
613 return S_OK;
616 HRESULT node_append_child(xmlnode *This, IXMLDOMNode *child, IXMLDOMNode **outChild)
618 DOMNodeType type;
619 VARIANT var;
620 HRESULT hr;
622 hr = IXMLDOMNode_get_nodeType(child, &type);
623 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
624 if (outChild) *outChild = NULL;
625 return E_FAIL;
628 VariantInit(&var);
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;
639 return S_FALSE;
642 *ret = VARIANT_TRUE;
643 return S_OK;
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)
653 IXMLDOMNode *node;
654 xmlNodePtr clone;
656 if(!cloneNode) return E_INVALIDARG;
658 clone = xmlCopyNode(This->node, deep ? 1 : 2);
659 if (clone)
661 xmlSetTreeDoc(clone, This->node->doc);
662 xmldoc_add_orphan(clone->doc, clone);
664 node = create_node(clone);
665 if (!node)
667 ERR("Copy failed\n");
668 xmldoc_remove_orphan(clone->doc, clone);
669 xmlFreeNode(clone);
670 return E_FAIL;
673 *cloneNode = node;
675 else
677 ERR("Copy failed\n");
678 return E_FAIL;
681 return S_OK;
684 static inline xmlChar* trim_whitespace(xmlChar* str)
686 xmlChar* ret = str;
687 int len;
689 if (!str)
690 return NULL;
692 while (*ret && isspace(*ret))
693 ++ret;
694 len = xmlStrlen(ret);
695 if (len)
696 while (isspace(ret[len-1])) --len;
698 ret = xmlStrndup(ret, len);
699 xmlFree(str);
700 return ret;
703 static xmlChar* do_get_text(xmlNodePtr node)
705 xmlNodePtr child;
706 xmlChar* str;
707 BOOL preserving = is_preserving_whitespace(node);
709 if (!node->children)
711 str = xmlNodeGetContent(node);
713 else
715 xmlElementType prev_type = XML_TEXT_NODE;
716 xmlChar* tmp;
717 str = xmlStrdup(BAD_CAST "");
718 for (child = node->children; child != NULL; child = child->next)
720 switch (child->type)
722 case XML_ELEMENT_NODE:
723 tmp = do_get_text(child);
724 break;
725 case XML_TEXT_NODE:
726 case XML_CDATA_SECTION_NODE:
727 case XML_ENTITY_REF_NODE:
728 case XML_ENTITY_NODE:
729 tmp = xmlNodeGetContent(child);
730 break;
731 default:
732 tmp = NULL;
733 break;
736 if (tmp)
738 if (*tmp)
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;
745 xmlFree(tmp);
750 switch (node->type)
752 case XML_ELEMENT_NODE:
753 case XML_TEXT_NODE:
754 case XML_ENTITY_REF_NODE:
755 case XML_ENTITY_NODE:
756 case XML_DOCUMENT_NODE:
757 case XML_DOCUMENT_FRAG_NODE:
758 if (!preserving)
759 str = trim_whitespace(str);
760 break;
761 default:
762 break;
765 return str;
768 HRESULT node_get_text(const xmlnode *This, BSTR *text)
770 BSTR str = NULL;
771 xmlChar *content;
773 if (!text) return E_INVALIDARG;
775 content = do_get_text(This->node);
776 if (content)
778 str = bstr_from_xmlChar(content);
779 xmlFree(content);
782 /* Always return a string. */
783 if (!str) str = SysAllocStringLen( NULL, 0 );
785 TRACE("%p %s\n", This, debugstr_w(str) );
786 *text = str;
788 return S_OK;
791 HRESULT node_put_text(xmlnode *This, BSTR text)
793 xmlChar *str, *str2;
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);
801 heap_free(str);
803 xmlNodeSetContent(This->node, str2);
804 xmlFree(str2);
806 return S_OK;
809 BSTR EnsureCorrectEOL(BSTR sInput)
811 int nNum = 0;
812 BSTR sNew;
813 int nLen;
814 int i;
816 nLen = SysStringLen(sInput);
817 /* Count line endings */
818 for(i=0; i < nLen; i++)
820 if(sInput[i] == '\n')
821 nNum++;
824 TRACE("len=%d, num=%d\n", nLen, nNum);
826 /* Add linefeed as needed */
827 if(nNum > 0)
829 int nPlace = 0;
830 sNew = SysAllocStringLen(NULL, nLen + nNum);
831 for(i=0; i < nLen; i++)
833 if(sInput[i] == '\n')
835 sNew[i+nPlace] = '\r';
836 nPlace++;
838 sNew[i+nPlace] = sInput[i];
841 SysFreeString(sInput);
843 else
845 sNew = sInput;
848 TRACE("len %d\n", SysStringLen(sNew));
850 return 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;
863 xmlNodePtr xmldecl;
864 int size;
866 if(!ret)
867 return E_INVALIDARG;
869 *ret = NULL;
871 xml_buf = xmlBufferCreate();
872 if(!xml_buf)
873 return E_OUTOFMEMORY;
875 xmldecl = xmldoc_unlink_xmldecl( This->node->doc );
877 size = xmlNodeDump(xml_buf, This->node->doc, This->node, 0, 1);
878 if(size > 0) {
879 const xmlChar *buf_content;
880 BSTR 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));
886 if(ensure_eol)
887 content = EnsureCorrectEOL(content);
889 *ret = content;
890 }else {
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 /* duplicates xmlBufferWriteQuotedString() logic */
900 static void xml_write_quotedstring(xmlOutputBufferPtr buf, const xmlChar *string)
902 const xmlChar *cur, *base;
904 if (xmlStrchr(string, '\"'))
906 if (xmlStrchr(string, '\''))
908 xmlOutputBufferWrite(buf, 1, "\"");
909 base = cur = string;
911 while (*cur)
913 if (*cur == '"')
915 if (base != cur)
916 xmlOutputBufferWrite(buf, cur-base, (const char*)base);
917 xmlOutputBufferWrite(buf, 6, "&quot;");
918 cur++;
919 base = cur;
921 else
922 cur++;
924 if (base != cur)
925 xmlOutputBufferWrite(buf, cur-base, (const char*)base);
926 xmlOutputBufferWrite(buf, 1, "\"");
928 else
930 xmlOutputBufferWrite(buf, 1, "\'");
931 xmlOutputBufferWriteString(buf, (const char*)string);
932 xmlOutputBufferWrite(buf, 1, "\'");
935 else
937 xmlOutputBufferWrite(buf, 1, "\"");
938 xmlOutputBufferWriteString(buf, (const char*)string);
939 xmlOutputBufferWrite(buf, 1, "\"");
943 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
945 xmlDtdPtr cur = doc->intSubset;
947 xmlOutputBufferWriteString(buf, "<!DOCTYPE ");
948 xmlOutputBufferWriteString(buf, (const char *)cur->name);
949 if (cur->ExternalID)
951 xmlOutputBufferWriteString(buf, " PUBLIC ");
952 xml_write_quotedstring(buf, cur->ExternalID);
953 if (cur->SystemID)
955 xmlOutputBufferWriteString(buf, " ");
956 xml_write_quotedstring(buf, cur->SystemID);
959 else if (cur->SystemID)
961 xmlOutputBufferWriteString(buf, " SYSTEM ");
962 xml_write_quotedstring(buf, cur->SystemID);
964 xmlOutputBufferWriteString(buf, ">\n");
967 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
969 xmlElementType type;
971 /* force HTML output */
972 type = doc->type;
973 doc->type = XML_HTML_DOCUMENT_NODE;
974 if (doc->intSubset)
975 htmldtd_dumpcontent(buf, doc);
976 if (doc->children)
978 xmlNodePtr cur = doc->children;
980 while (cur)
982 htmlNodeDumpFormatOutput(buf, doc, cur, NULL, 1);
983 cur = cur->next;
987 doc->type = type;
990 static const xmlChar *get_output_buffer_content(xmlOutputBufferPtr output)
992 #ifdef LIBXML2_NEW_BUFFER
993 return xmlOutputBufferGetContent(output);
994 #else
995 return xmlBufferContent(output->buffer);
996 #endif
999 HRESULT node_transform_node(const xmlnode *This, IXMLDOMNode *stylesheet, BSTR *p)
1001 #ifdef SONAME_LIBXSLT
1002 xsltStylesheetPtr xsltSS;
1003 xmlnode *sheet;
1005 if (!libxslt_handle) return E_NOTIMPL;
1006 if (!stylesheet || !p) return E_INVALIDARG;
1008 *p = NULL;
1010 sheet = get_node_obj(stylesheet);
1011 if(!sheet) return E_FAIL;
1013 xsltSS = pxsltParseStylesheetDoc(sheet->node->doc);
1014 if(xsltSS)
1016 xmlDocPtr result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
1017 if(result)
1019 const xmlChar *content;
1021 if(result->type == XML_HTML_DOCUMENT_NODE)
1023 xmlOutputBufferPtr output = xmlAllocOutputBuffer(NULL);
1024 if (output)
1026 htmldoc_dumpcontent(output, result->doc);
1027 content = get_output_buffer_content(output);
1028 *p = bstr_from_xmlChar(content);
1029 xmlOutputBufferClose(output);
1032 else
1034 xmlBufferPtr buf = xmlBufferCreate();
1035 if (buf)
1037 int size = xmlNodeDump(buf, NULL, (xmlNodePtr)result, 0, 0);
1038 if(size > 0)
1040 content = xmlBufferContent(buf);
1041 *p = bstr_from_xmlChar(content);
1043 xmlBufferFree(buf);
1046 xmlFreeDoc(result);
1048 /* libxslt "helpfully" frees the XML document the stylesheet was
1049 generated from, too */
1050 xsltSS->doc = NULL;
1051 pxsltFreeStylesheet(xsltSS);
1054 if(!*p) *p = SysAllocStringLen(NULL, 0);
1056 return S_OK;
1057 #else
1058 FIXME("libxslt headers were not found at compile time\n");
1059 return E_NOTIMPL;
1060 #endif
1063 HRESULT node_select_nodes(const xmlnode *This, BSTR query, IXMLDOMNodeList **nodes)
1065 xmlChar* str;
1066 HRESULT hr;
1068 if (!query || !nodes) return E_INVALIDARG;
1070 str = xmlchar_from_wchar(query);
1071 hr = create_selection(This->node, str, nodes);
1072 heap_free(str);
1074 return hr;
1077 HRESULT node_select_singlenode(const xmlnode *This, BSTR query, IXMLDOMNode **node)
1079 IXMLDOMNodeList *list;
1080 HRESULT hr;
1082 hr = node_select_nodes(This, query, &list);
1083 if (hr == S_OK)
1085 hr = IXMLDOMNodeList_nextNode(list, node);
1086 IXMLDOMNodeList_Release(list);
1088 return hr;
1091 HRESULT node_get_namespaceURI(xmlnode *This, BSTR *namespaceURI)
1093 xmlNsPtr ns = This->node->ns;
1095 if(!namespaceURI)
1096 return E_INVALIDARG;
1098 *namespaceURI = NULL;
1100 if (ns && ns->href)
1101 *namespaceURI = bstr_from_xmlChar(ns->href);
1103 TRACE("uri: %s\n", debugstr_w(*namespaceURI));
1105 return *namespaceURI ? S_OK : S_FALSE;
1108 HRESULT node_get_prefix(xmlnode *This, BSTR *prefix)
1110 xmlNsPtr ns = This->node->ns;
1112 if (!prefix) return E_INVALIDARG;
1114 *prefix = NULL;
1116 if (ns && ns->prefix)
1117 *prefix = bstr_from_xmlChar(ns->prefix);
1119 TRACE("prefix: %s\n", debugstr_w(*prefix));
1121 return *prefix ? S_OK : S_FALSE;
1124 HRESULT node_get_base_name(xmlnode *This, BSTR *name)
1126 if (!name) return E_INVALIDARG;
1128 *name = bstr_from_xmlChar(This->node->name);
1129 if (!*name) return E_OUTOFMEMORY;
1131 TRACE("returning %s\n", debugstr_w(*name));
1133 return S_OK;
1136 /* _private field holds a number of COM instances spawned from this libxml2 node */
1137 static void xmlnode_add_ref(xmlNodePtr node)
1139 if (node->type == XML_DOCUMENT_NODE) return;
1140 InterlockedIncrement((LONG*)&node->_private);
1143 static void xmlnode_release(xmlNodePtr node)
1145 if (node->type == XML_DOCUMENT_NODE) return;
1146 InterlockedDecrement((LONG*)&node->_private);
1149 void destroy_xmlnode(xmlnode *This)
1151 if(This->node)
1153 xmlnode_release(This->node);
1154 xmldoc_release(This->node->doc);
1156 release_dispex(&This->dispex);
1159 void init_xmlnode(xmlnode *This, xmlNodePtr node, IXMLDOMNode *node_iface, dispex_static_data_t *dispex_data)
1161 if(node)
1163 xmlnode_add_ref(node);
1164 xmldoc_add_ref(node->doc);
1167 This->node = node;
1168 This->iface = node_iface;
1169 This->parent = NULL;
1171 init_dispex(&This->dispex, (IUnknown*)This->iface, dispex_data);
1174 typedef struct {
1175 xmlnode node;
1176 IXMLDOMNode IXMLDOMNode_iface;
1177 LONG ref;
1178 } unknode;
1180 static inline unknode *unknode_from_IXMLDOMNode(IXMLDOMNode *iface)
1182 return CONTAINING_RECORD(iface, unknode, IXMLDOMNode_iface);
1185 static HRESULT WINAPI unknode_QueryInterface(
1186 IXMLDOMNode *iface,
1187 REFIID riid,
1188 void** ppvObject )
1190 unknode *This = unknode_from_IXMLDOMNode( iface );
1192 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
1194 if (IsEqualGUID(riid, &IID_IUnknown)) {
1195 *ppvObject = iface;
1196 }else if (IsEqualGUID( riid, &IID_IDispatch) ||
1197 IsEqualGUID( riid, &IID_IXMLDOMNode)) {
1198 *ppvObject = &This->IXMLDOMNode_iface;
1199 }else if(node_query_interface(&This->node, riid, ppvObject)) {
1200 return *ppvObject ? S_OK : E_NOINTERFACE;
1201 }else {
1202 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1203 *ppvObject = NULL;
1204 return E_NOINTERFACE;
1207 IUnknown_AddRef((IUnknown*)*ppvObject);
1208 return S_OK;
1211 static ULONG WINAPI unknode_AddRef(
1212 IXMLDOMNode *iface )
1214 unknode *This = unknode_from_IXMLDOMNode( iface );
1216 return InterlockedIncrement(&This->ref);
1219 static ULONG WINAPI unknode_Release(
1220 IXMLDOMNode *iface )
1222 unknode *This = unknode_from_IXMLDOMNode( iface );
1223 LONG ref;
1225 ref = InterlockedDecrement( &This->ref );
1226 if(!ref) {
1227 destroy_xmlnode(&This->node);
1228 heap_free(This);
1231 return ref;
1234 static HRESULT WINAPI unknode_GetTypeInfoCount(
1235 IXMLDOMNode *iface,
1236 UINT* pctinfo )
1238 unknode *This = unknode_from_IXMLDOMNode( iface );
1240 TRACE("(%p)->(%p)\n", This, pctinfo);
1242 *pctinfo = 1;
1244 return S_OK;
1247 static HRESULT WINAPI unknode_GetTypeInfo(
1248 IXMLDOMNode *iface,
1249 UINT iTInfo,
1250 LCID lcid,
1251 ITypeInfo** ppTInfo )
1253 unknode *This = unknode_from_IXMLDOMNode( iface );
1254 HRESULT hr;
1256 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1258 hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo);
1260 return hr;
1263 static HRESULT WINAPI unknode_GetIDsOfNames(
1264 IXMLDOMNode *iface,
1265 REFIID riid,
1266 LPOLESTR* rgszNames,
1267 UINT cNames,
1268 LCID lcid,
1269 DISPID* rgDispId )
1271 unknode *This = unknode_from_IXMLDOMNode( iface );
1273 ITypeInfo *typeinfo;
1274 HRESULT hr;
1276 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1277 lcid, rgDispId);
1279 if(!rgszNames || cNames == 0 || !rgDispId)
1280 return E_INVALIDARG;
1282 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1283 if(SUCCEEDED(hr))
1285 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1286 ITypeInfo_Release(typeinfo);
1289 return hr;
1292 static HRESULT WINAPI unknode_Invoke(
1293 IXMLDOMNode *iface,
1294 DISPID dispIdMember,
1295 REFIID riid,
1296 LCID lcid,
1297 WORD wFlags,
1298 DISPPARAMS* pDispParams,
1299 VARIANT* pVarResult,
1300 EXCEPINFO* pExcepInfo,
1301 UINT* puArgErr )
1303 unknode *This = unknode_from_IXMLDOMNode( iface );
1304 ITypeInfo *typeinfo;
1305 HRESULT hr;
1307 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1308 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1310 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1311 if(SUCCEEDED(hr))
1313 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNode_iface, dispIdMember, wFlags, pDispParams,
1314 pVarResult, pExcepInfo, puArgErr);
1315 ITypeInfo_Release(typeinfo);
1318 return hr;
1321 static HRESULT WINAPI unknode_get_nodeName(
1322 IXMLDOMNode *iface,
1323 BSTR* p )
1325 unknode *This = unknode_from_IXMLDOMNode( iface );
1327 FIXME("(%p)->(%p)\n", This, p);
1329 return node_get_nodeName(&This->node, p);
1332 static HRESULT WINAPI unknode_get_nodeValue(
1333 IXMLDOMNode *iface,
1334 VARIANT* value)
1336 unknode *This = unknode_from_IXMLDOMNode( iface );
1338 FIXME("(%p)->(%p)\n", This, value);
1340 if(!value)
1341 return E_INVALIDARG;
1343 V_VT(value) = VT_NULL;
1344 return S_FALSE;
1347 static HRESULT WINAPI unknode_put_nodeValue(
1348 IXMLDOMNode *iface,
1349 VARIANT value)
1351 unknode *This = unknode_from_IXMLDOMNode( iface );
1352 FIXME("(%p)->(v%d)\n", This, V_VT(&value));
1353 return E_FAIL;
1356 static HRESULT WINAPI unknode_get_nodeType(
1357 IXMLDOMNode *iface,
1358 DOMNodeType* domNodeType )
1360 unknode *This = unknode_from_IXMLDOMNode( iface );
1362 FIXME("(%p)->(%p)\n", This, domNodeType);
1364 *domNodeType = This->node.node->type;
1365 return S_OK;
1368 static HRESULT WINAPI unknode_get_parentNode(
1369 IXMLDOMNode *iface,
1370 IXMLDOMNode** parent )
1372 unknode *This = unknode_from_IXMLDOMNode( iface );
1373 FIXME("(%p)->(%p)\n", This, parent);
1374 if (!parent) return E_INVALIDARG;
1375 *parent = NULL;
1376 return S_FALSE;
1379 static HRESULT WINAPI unknode_get_childNodes(
1380 IXMLDOMNode *iface,
1381 IXMLDOMNodeList** outList)
1383 unknode *This = unknode_from_IXMLDOMNode( iface );
1385 TRACE("(%p)->(%p)\n", This, outList);
1387 return node_get_child_nodes(&This->node, outList);
1390 static HRESULT WINAPI unknode_get_firstChild(
1391 IXMLDOMNode *iface,
1392 IXMLDOMNode** domNode)
1394 unknode *This = unknode_from_IXMLDOMNode( iface );
1396 TRACE("(%p)->(%p)\n", This, domNode);
1398 return node_get_first_child(&This->node, domNode);
1401 static HRESULT WINAPI unknode_get_lastChild(
1402 IXMLDOMNode *iface,
1403 IXMLDOMNode** domNode)
1405 unknode *This = unknode_from_IXMLDOMNode( iface );
1407 TRACE("(%p)->(%p)\n", This, domNode);
1409 return node_get_last_child(&This->node, domNode);
1412 static HRESULT WINAPI unknode_get_previousSibling(
1413 IXMLDOMNode *iface,
1414 IXMLDOMNode** domNode)
1416 unknode *This = unknode_from_IXMLDOMNode( iface );
1418 TRACE("(%p)->(%p)\n", This, domNode);
1420 return node_get_previous_sibling(&This->node, domNode);
1423 static HRESULT WINAPI unknode_get_nextSibling(
1424 IXMLDOMNode *iface,
1425 IXMLDOMNode** domNode)
1427 unknode *This = unknode_from_IXMLDOMNode( iface );
1429 TRACE("(%p)->(%p)\n", This, domNode);
1431 return node_get_next_sibling(&This->node, domNode);
1434 static HRESULT WINAPI unknode_get_attributes(
1435 IXMLDOMNode *iface,
1436 IXMLDOMNamedNodeMap** attributeMap)
1438 unknode *This = unknode_from_IXMLDOMNode( iface );
1440 FIXME("(%p)->(%p)\n", This, attributeMap);
1442 return return_null_ptr((void**)attributeMap);
1445 static HRESULT WINAPI unknode_insertBefore(
1446 IXMLDOMNode *iface,
1447 IXMLDOMNode* newNode, VARIANT refChild,
1448 IXMLDOMNode** outOldNode)
1450 unknode *This = unknode_from_IXMLDOMNode( iface );
1452 FIXME("(%p)->(%p x%d %p)\n", This, newNode, V_VT(&refChild), outOldNode);
1454 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
1457 static HRESULT WINAPI unknode_replaceChild(
1458 IXMLDOMNode *iface,
1459 IXMLDOMNode* newNode,
1460 IXMLDOMNode* oldNode,
1461 IXMLDOMNode** outOldNode)
1463 unknode *This = unknode_from_IXMLDOMNode( iface );
1465 FIXME("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
1467 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
1470 static HRESULT WINAPI unknode_removeChild(
1471 IXMLDOMNode *iface,
1472 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
1474 unknode *This = unknode_from_IXMLDOMNode( iface );
1475 return node_remove_child(&This->node, domNode, oldNode);
1478 static HRESULT WINAPI unknode_appendChild(
1479 IXMLDOMNode *iface,
1480 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
1482 unknode *This = unknode_from_IXMLDOMNode( iface );
1483 return node_append_child(&This->node, newNode, outNewNode);
1486 static HRESULT WINAPI unknode_hasChildNodes(
1487 IXMLDOMNode *iface,
1488 VARIANT_BOOL* pbool)
1490 unknode *This = unknode_from_IXMLDOMNode( iface );
1491 return node_has_childnodes(&This->node, pbool);
1494 static HRESULT WINAPI unknode_get_ownerDocument(
1495 IXMLDOMNode *iface,
1496 IXMLDOMDocument** domDocument)
1498 unknode *This = unknode_from_IXMLDOMNode( iface );
1499 return node_get_owner_doc(&This->node, domDocument);
1502 static HRESULT WINAPI unknode_cloneNode(
1503 IXMLDOMNode *iface,
1504 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
1506 unknode *This = unknode_from_IXMLDOMNode( iface );
1507 return node_clone(&This->node, pbool, outNode );
1510 static HRESULT WINAPI unknode_get_nodeTypeString(
1511 IXMLDOMNode *iface,
1512 BSTR* p)
1514 unknode *This = unknode_from_IXMLDOMNode( iface );
1516 FIXME("(%p)->(%p)\n", This, p);
1518 return node_get_nodeName(&This->node, p);
1521 static HRESULT WINAPI unknode_get_text(
1522 IXMLDOMNode *iface,
1523 BSTR* p)
1525 unknode *This = unknode_from_IXMLDOMNode( iface );
1526 return node_get_text(&This->node, p);
1529 static HRESULT WINAPI unknode_put_text(
1530 IXMLDOMNode *iface,
1531 BSTR p)
1533 unknode *This = unknode_from_IXMLDOMNode( iface );
1534 return node_put_text(&This->node, p);
1537 static HRESULT WINAPI unknode_get_specified(
1538 IXMLDOMNode *iface,
1539 VARIANT_BOOL* isSpecified)
1541 unknode *This = unknode_from_IXMLDOMNode( iface );
1542 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
1543 *isSpecified = VARIANT_TRUE;
1544 return S_OK;
1547 static HRESULT WINAPI unknode_get_definition(
1548 IXMLDOMNode *iface,
1549 IXMLDOMNode** definitionNode)
1551 unknode *This = unknode_from_IXMLDOMNode( iface );
1552 FIXME("(%p)->(%p)\n", This, definitionNode);
1553 return E_NOTIMPL;
1556 static HRESULT WINAPI unknode_get_nodeTypedValue(
1557 IXMLDOMNode *iface,
1558 VARIANT* var1)
1560 unknode *This = unknode_from_IXMLDOMNode( iface );
1561 FIXME("(%p)->(%p)\n", This, var1);
1562 return return_null_var(var1);
1565 static HRESULT WINAPI unknode_put_nodeTypedValue(
1566 IXMLDOMNode *iface,
1567 VARIANT typedValue)
1569 unknode *This = unknode_from_IXMLDOMNode( iface );
1570 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
1571 return E_NOTIMPL;
1574 static HRESULT WINAPI unknode_get_dataType(
1575 IXMLDOMNode *iface,
1576 VARIANT* var1)
1578 unknode *This = unknode_from_IXMLDOMNode( iface );
1579 TRACE("(%p)->(%p)\n", This, var1);
1580 return return_null_var(var1);
1583 static HRESULT WINAPI unknode_put_dataType(
1584 IXMLDOMNode *iface,
1585 BSTR p)
1587 unknode *This = unknode_from_IXMLDOMNode( iface );
1589 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
1591 if(!p)
1592 return E_INVALIDARG;
1594 return E_FAIL;
1597 static HRESULT WINAPI unknode_get_xml(
1598 IXMLDOMNode *iface,
1599 BSTR* p)
1601 unknode *This = unknode_from_IXMLDOMNode( iface );
1603 FIXME("(%p)->(%p)\n", This, p);
1605 return node_get_xml(&This->node, FALSE, p);
1608 static HRESULT WINAPI unknode_transformNode(
1609 IXMLDOMNode *iface,
1610 IXMLDOMNode* domNode, BSTR* p)
1612 unknode *This = unknode_from_IXMLDOMNode( iface );
1613 return node_transform_node(&This->node, domNode, p);
1616 static HRESULT WINAPI unknode_selectNodes(
1617 IXMLDOMNode *iface,
1618 BSTR p, IXMLDOMNodeList** outList)
1620 unknode *This = unknode_from_IXMLDOMNode( iface );
1621 return node_select_nodes(&This->node, p, outList);
1624 static HRESULT WINAPI unknode_selectSingleNode(
1625 IXMLDOMNode *iface,
1626 BSTR p, IXMLDOMNode** outNode)
1628 unknode *This = unknode_from_IXMLDOMNode( iface );
1629 return node_select_singlenode(&This->node, p, outNode);
1632 static HRESULT WINAPI unknode_get_parsed(
1633 IXMLDOMNode *iface,
1634 VARIANT_BOOL* isParsed)
1636 unknode *This = unknode_from_IXMLDOMNode( iface );
1637 FIXME("(%p)->(%p) stub!\n", This, isParsed);
1638 *isParsed = VARIANT_TRUE;
1639 return S_OK;
1642 static HRESULT WINAPI unknode_get_namespaceURI(
1643 IXMLDOMNode *iface,
1644 BSTR* p)
1646 unknode *This = unknode_from_IXMLDOMNode( iface );
1647 TRACE("(%p)->(%p)\n", This, p);
1648 return node_get_namespaceURI(&This->node, p);
1651 static HRESULT WINAPI unknode_get_prefix(
1652 IXMLDOMNode *iface,
1653 BSTR* p)
1655 unknode *This = unknode_from_IXMLDOMNode( iface );
1656 return node_get_prefix(&This->node, p);
1659 static HRESULT WINAPI unknode_get_baseName(
1660 IXMLDOMNode *iface,
1661 BSTR* p)
1663 unknode *This = unknode_from_IXMLDOMNode( iface );
1664 return node_get_base_name(&This->node, p);
1667 static HRESULT WINAPI unknode_transformNodeToObject(
1668 IXMLDOMNode *iface,
1669 IXMLDOMNode* domNode, VARIANT var1)
1671 unknode *This = unknode_from_IXMLDOMNode( iface );
1672 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1673 return E_NOTIMPL;
1676 static const struct IXMLDOMNodeVtbl unknode_vtbl =
1678 unknode_QueryInterface,
1679 unknode_AddRef,
1680 unknode_Release,
1681 unknode_GetTypeInfoCount,
1682 unknode_GetTypeInfo,
1683 unknode_GetIDsOfNames,
1684 unknode_Invoke,
1685 unknode_get_nodeName,
1686 unknode_get_nodeValue,
1687 unknode_put_nodeValue,
1688 unknode_get_nodeType,
1689 unknode_get_parentNode,
1690 unknode_get_childNodes,
1691 unknode_get_firstChild,
1692 unknode_get_lastChild,
1693 unknode_get_previousSibling,
1694 unknode_get_nextSibling,
1695 unknode_get_attributes,
1696 unknode_insertBefore,
1697 unknode_replaceChild,
1698 unknode_removeChild,
1699 unknode_appendChild,
1700 unknode_hasChildNodes,
1701 unknode_get_ownerDocument,
1702 unknode_cloneNode,
1703 unknode_get_nodeTypeString,
1704 unknode_get_text,
1705 unknode_put_text,
1706 unknode_get_specified,
1707 unknode_get_definition,
1708 unknode_get_nodeTypedValue,
1709 unknode_put_nodeTypedValue,
1710 unknode_get_dataType,
1711 unknode_put_dataType,
1712 unknode_get_xml,
1713 unknode_transformNode,
1714 unknode_selectNodes,
1715 unknode_selectSingleNode,
1716 unknode_get_parsed,
1717 unknode_get_namespaceURI,
1718 unknode_get_prefix,
1719 unknode_get_baseName,
1720 unknode_transformNodeToObject
1723 IXMLDOMNode *create_node( xmlNodePtr node )
1725 IUnknown *pUnk;
1726 IXMLDOMNode *ret;
1727 HRESULT hr;
1729 if ( !node )
1730 return NULL;
1732 TRACE("type %d\n", node->type);
1733 switch(node->type)
1735 case XML_ELEMENT_NODE:
1736 pUnk = create_element( node );
1737 break;
1738 case XML_ATTRIBUTE_NODE:
1739 pUnk = create_attribute( node );
1740 break;
1741 case XML_TEXT_NODE:
1742 pUnk = create_text( node );
1743 break;
1744 case XML_CDATA_SECTION_NODE:
1745 pUnk = create_cdata( node );
1746 break;
1747 case XML_ENTITY_REF_NODE:
1748 pUnk = create_doc_entity_ref( node );
1749 break;
1750 case XML_PI_NODE:
1751 pUnk = create_pi( node );
1752 break;
1753 case XML_COMMENT_NODE:
1754 pUnk = create_comment( node );
1755 break;
1756 case XML_DOCUMENT_NODE:
1757 pUnk = create_domdoc( node );
1758 break;
1759 case XML_DOCUMENT_FRAG_NODE:
1760 pUnk = create_doc_fragment( node );
1761 break;
1762 case XML_DTD_NODE:
1763 pUnk = create_doc_type( node );
1764 break;
1765 default: {
1766 unknode *new_node;
1768 FIXME("only creating basic node for type %d\n", node->type);
1770 new_node = heap_alloc(sizeof(unknode));
1771 if(!new_node)
1772 return NULL;
1774 new_node->IXMLDOMNode_iface.lpVtbl = &unknode_vtbl;
1775 new_node->ref = 1;
1776 init_xmlnode(&new_node->node, node, &new_node->IXMLDOMNode_iface, NULL);
1777 pUnk = (IUnknown*)&new_node->IXMLDOMNode_iface;
1781 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1782 IUnknown_Release(pUnk);
1783 if(FAILED(hr)) return NULL;
1784 return ret;
1786 #endif