netstat: Initial implementation.
[wine] / dlls / msxml3 / node.c
1 /*
2  *    Node implementation
3  *
4  * Copyright 2005 Mike McCormack
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #define COBJMACROS
24
25 #include <stdarg.h>
26
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
42
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winuser.h"
46 #include "winnls.h"
47 #include "ole2.h"
48 #include "msxml6.h"
49
50 #include "msxml_private.h"
51
52 #include "wine/debug.h"
53
54 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
55
56 #ifdef HAVE_LIBXML2
57
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
67
68 static const IID IID_xmlnode = {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
69
70 xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type )
71 {
72     xmlnode *This;
73
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;
82 }
83
84 BOOL node_query_interface(xmlnode *This, REFIID riid, void **ppv)
85 {
86     if(IsEqualGUID(&IID_xmlnode, riid)) {
87         TRACE("(%p)->(IID_xmlnode %p)\n", This, ppv);
88         *ppv = This;
89         return TRUE;
90     }
91
92     return dispex_query_interface(&This->dispex, riid, ppv);
93 }
94
95 /* common ISupportErrorInfo implementation */
96 typedef struct {
97    ISupportErrorInfo ISupportErrorInfo_iface;
98    LONG ref;
99
100    const tid_t* iids;
101 } SupportErrorInfo;
102
103 static inline SupportErrorInfo *impl_from_ISupportErrorInfo(ISupportErrorInfo *iface)
104 {
105     return CONTAINING_RECORD(iface, SupportErrorInfo, ISupportErrorInfo_iface);
106 }
107
108 static HRESULT WINAPI SupportErrorInfo_QueryInterface(ISupportErrorInfo *iface, REFIID riid, void **obj)
109 {
110     SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
111     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
112
113     *obj = NULL;
114
115     if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISupportErrorInfo)) {
116         *obj = iface;
117         ISupportErrorInfo_AddRef(iface);
118         return S_OK;
119     }
120
121     return E_NOINTERFACE;
122 }
123
124 static ULONG WINAPI SupportErrorInfo_AddRef(ISupportErrorInfo *iface)
125 {
126     SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
127     ULONG ref = InterlockedIncrement(&This->ref);
128     TRACE("(%p)->(%d)\n", This, ref );
129     return ref;
130 }
131
132 static ULONG WINAPI SupportErrorInfo_Release(ISupportErrorInfo *iface)
133 {
134     SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
135     LONG ref = InterlockedDecrement(&This->ref);
136
137     TRACE("(%p)->(%d)\n", This, ref);
138
139     if (ref == 0)
140         heap_free(This);
141
142     return ref;
143 }
144
145 static HRESULT WINAPI SupportErrorInfo_InterfaceSupportsErrorInfo(ISupportErrorInfo *iface, REFIID riid)
146 {
147     SupportErrorInfo *This = impl_from_ISupportErrorInfo(iface);
148     enum tid_t const *tid;
149
150     TRACE("(%p)->(%s)\n", This, debugstr_guid(riid));
151
152     tid = This->iids;
153     while (*tid)
154     {
155         if (IsEqualGUID(riid, get_riid_from_tid(*tid)))
156             return S_OK;
157         tid++;
158     }
159
160     return S_FALSE;
161 }
162
163 static const struct ISupportErrorInfoVtbl SupportErrorInfoVtbl = {
164     SupportErrorInfo_QueryInterface,
165     SupportErrorInfo_AddRef,
166     SupportErrorInfo_Release,
167     SupportErrorInfo_InterfaceSupportsErrorInfo
168 };
169
170 HRESULT node_create_supporterrorinfo(enum tid_t const *iids, void **obj)
171 {
172     SupportErrorInfo *This;
173
174     This = heap_alloc(sizeof(*This));
175     if (!This) return E_OUTOFMEMORY;
176
177     This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
178     This->ref = 1;
179     This->iids = iids;
180
181     *obj = &This->ISupportErrorInfo_iface;
182
183     return S_OK;
184 }
185
186 xmlnode *get_node_obj(IXMLDOMNode *node)
187 {
188     xmlnode *obj = NULL;
189     HRESULT hres;
190
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;
194 }
195
196 HRESULT node_get_nodeName(xmlnode *This, BSTR *name)
197 {
198     BSTR prefix, base;
199     HRESULT hr;
200
201     if (!name)
202         return E_INVALIDARG;
203
204     hr = node_get_base_name(This, &base);
205     if (hr != S_OK) return hr;
206
207     hr = node_get_prefix(This, &prefix);
208     if (hr == S_OK)
209     {
210         static const WCHAR colW = ':';
211         WCHAR *ptr;
212
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));
219
220         SysFreeString(base);
221         SysFreeString(prefix);
222     }
223     else
224         *name = base;
225
226     return S_OK;
227 }
228
229 HRESULT node_get_content(xmlnode *This, VARIANT *value)
230 {
231     xmlChar *content;
232
233     if(!value)
234         return E_INVALIDARG;
235
236     content = xmlNodeGetContent(This->node);
237     V_VT(value) = VT_BSTR;
238     V_BSTR(value) = bstr_from_xmlChar( content );
239     xmlFree(content);
240
241     TRACE("%p returned %s\n", This, debugstr_w(V_BSTR(value)));
242     return S_OK;
243 }
244
245 HRESULT node_set_content(xmlnode *This, LPCWSTR value)
246 {
247     xmlChar *str;
248
249     TRACE("(%p)->(%s)\n", This, debugstr_w(value));
250     str = xmlchar_from_wchar(value);
251     if(!str)
252         return E_OUTOFMEMORY;
253
254     xmlNodeSetContent(This->node, str);
255     heap_free(str);
256     return S_OK;
257 }
258
259 static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
260 {
261     xmlChar *str, *escaped;
262
263     TRACE("(%p)->(%s)\n", This, debugstr_w(value));
264     str = xmlchar_from_wchar(value);
265     if(!str)
266         return E_OUTOFMEMORY;
267
268     escaped = xmlEncodeSpecialChars(NULL, str);
269     if(!escaped)
270     {
271         heap_free(str);
272         return E_OUTOFMEMORY;
273     }
274
275     xmlNodeSetContent(This->node, escaped);
276
277     heap_free(str);
278     xmlFree(escaped);
279
280     return S_OK;
281 }
282
283 HRESULT node_put_value(xmlnode *This, VARIANT *value)
284 {
285     VARIANT string_value;
286     HRESULT hr;
287
288     VariantInit(&string_value);
289     hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
290     if(FAILED(hr)) {
291         WARN("Couldn't convert to VT_BSTR\n");
292         return hr;
293     }
294
295     hr = node_set_content(This, V_BSTR(&string_value));
296     VariantClear(&string_value);
297
298     return hr;
299 }
300
301 HRESULT node_put_value_escaped(xmlnode *This, VARIANT *value)
302 {
303     VARIANT string_value;
304     HRESULT hr;
305
306     VariantInit(&string_value);
307     hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
308     if(FAILED(hr)) {
309         WARN("Couldn't convert to VT_BSTR\n");
310         return hr;
311     }
312
313     hr = node_set_content_escaped(This, V_BSTR(&string_value));
314     VariantClear(&string_value);
315
316     return hr;
317 }
318
319 static HRESULT get_node(
320     xmlnode *This,
321     const char *name,
322     xmlNodePtr node,
323     IXMLDOMNode **out )
324 {
325     TRACE("(%p)->(%s %p %p)\n", This, name, node, out );
326
327     if ( !out )
328         return E_INVALIDARG;
329
330     /* if we don't have a doc, use our parent. */
331     if(node && !node->doc && node->parent)
332         node->doc = node->parent->doc;
333
334     *out = create_node( node );
335     if (!*out)
336         return S_FALSE;
337     return S_OK;
338 }
339
340 HRESULT node_get_parent(xmlnode *This, IXMLDOMNode **parent)
341 {
342     return get_node( This, "parent", This->node->parent, parent );
343 }
344
345 HRESULT node_get_child_nodes(xmlnode *This, IXMLDOMNodeList **ret)
346 {
347     if(!ret)
348         return E_INVALIDARG;
349
350     *ret = create_children_nodelist(This->node);
351     if(!*ret)
352         return E_OUTOFMEMORY;
353
354     return S_OK;
355 }
356
357 HRESULT node_get_first_child(xmlnode *This, IXMLDOMNode **ret)
358 {
359     return get_node(This, "firstChild", This->node->children, ret);
360 }
361
362 HRESULT node_get_last_child(xmlnode *This, IXMLDOMNode **ret)
363 {
364     return get_node(This, "lastChild", This->node->last, ret);
365 }
366
367 HRESULT node_get_previous_sibling(xmlnode *This, IXMLDOMNode **ret)
368 {
369     return get_node(This, "previous", This->node->prev, ret);
370 }
371
372 HRESULT node_get_next_sibling(xmlnode *This, IXMLDOMNode **ret)
373 {
374     return get_node(This, "next", This->node->next, ret);
375 }
376
377 HRESULT node_insert_before(xmlnode *This, IXMLDOMNode *new_child, const VARIANT *ref_child,
378         IXMLDOMNode **ret)
379 {
380     IXMLDOMNode *before = NULL;
381     xmlnode *node_obj;
382     xmlDocPtr doc;
383     HRESULT hr;
384
385     if(!new_child)
386         return E_INVALIDARG;
387
388     node_obj = get_node_obj(new_child);
389     if(!node_obj) return E_FAIL;
390
391     switch(V_VT(ref_child))
392     {
393     case VT_EMPTY:
394     case VT_NULL:
395         break;
396
397     case VT_UNKNOWN:
398     case VT_DISPATCH:
399         if (V_UNKNOWN(ref_child))
400         {
401             hr = IUnknown_QueryInterface(V_UNKNOWN(ref_child), &IID_IXMLDOMNode, (void**)&before);
402             if(FAILED(hr)) return hr;
403         }
404         break;
405
406     default:
407         FIXME("refChild var type %x\n", V_VT(ref_child));
408         return E_FAIL;
409     }
410
411     TRACE("new child %p, This->node %p\n", node_obj->node, This->node);
412
413     if(!node_obj->node->parent)
414         if(xmldoc_remove_orphan(node_obj->node->doc, node_obj->node) != S_OK)
415             WARN("%p is not an orphan of %p\n", node_obj->node, node_obj->node->doc);
416
417     if(before)
418     {
419         xmlnode *before_node_obj = get_node_obj(before);
420         IXMLDOMNode_Release(before);
421         if(!before_node_obj) return E_FAIL;
422
423         /* unlink from current parent first */
424         if(node_obj->parent)
425         {
426             hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
427             if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
428         }
429         doc = node_obj->node->doc;
430         xmldoc_add_ref(before_node_obj->node->doc);
431         xmlAddPrevSibling(before_node_obj->node, node_obj->node);
432         xmldoc_release(doc);
433         node_obj->parent = This->parent;
434     }
435     else
436     {
437         /* unlink from current parent first */
438         if(node_obj->parent)
439         {
440             hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
441             if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
442         }
443         doc = node_obj->node->doc;
444         xmldoc_add_ref(This->node->doc);
445         /* xmlAddChild doesn't unlink node from previous parent */
446         xmlUnlinkNode(node_obj->node);
447         xmlAddChild(This->node, node_obj->node);
448         xmldoc_release(doc);
449         node_obj->parent = This->iface;
450     }
451
452     if(ret)
453     {
454         IXMLDOMNode_AddRef(new_child);
455         *ret = new_child;
456     }
457
458     TRACE("ret S_OK\n");
459     return S_OK;
460 }
461
462 HRESULT node_replace_child(xmlnode *This, IXMLDOMNode *newChild, IXMLDOMNode *oldChild,
463         IXMLDOMNode **ret)
464 {
465     xmlnode *old_child, *new_child;
466     xmlDocPtr leaving_doc;
467     xmlNode *my_ancestor;
468
469     /* Do not believe any documentation telling that newChild == NULL
470        means removal. It does certainly *not* apply to msxml3! */
471     if(!newChild || !oldChild)
472         return E_INVALIDARG;
473
474     if(ret)
475         *ret = NULL;
476
477     old_child = get_node_obj(oldChild);
478     if(!old_child) return E_FAIL;
479
480     if(old_child->node->parent != This->node)
481     {
482         WARN("childNode %p is not a child of %p\n", oldChild, This);
483         return E_INVALIDARG;
484     }
485
486     new_child = get_node_obj(newChild);
487     if(!new_child) return E_FAIL;
488
489     my_ancestor = This->node;
490     while(my_ancestor)
491     {
492         if(my_ancestor == new_child->node)
493         {
494             WARN("tried to create loop\n");
495             return E_FAIL;
496         }
497         my_ancestor = my_ancestor->parent;
498     }
499
500     if(!new_child->node->parent)
501         if(xmldoc_remove_orphan(new_child->node->doc, new_child->node) != S_OK)
502             WARN("%p is not an orphan of %p\n", new_child->node, new_child->node->doc);
503
504     leaving_doc = new_child->node->doc;
505     xmldoc_add_ref(old_child->node->doc);
506     xmlReplaceNode(old_child->node, new_child->node);
507     xmldoc_release(leaving_doc);
508     new_child->parent = old_child->parent;
509     old_child->parent = NULL;
510
511     xmldoc_add_orphan(old_child->node->doc, old_child->node);
512
513     if(ret)
514     {
515         IXMLDOMNode_AddRef(oldChild);
516         *ret = oldChild;
517     }
518
519     return S_OK;
520 }
521
522 HRESULT node_remove_child(xmlnode *This, IXMLDOMNode* child, IXMLDOMNode** oldChild)
523 {
524     xmlnode *child_node;
525
526     if(!child) return E_INVALIDARG;
527
528     if(oldChild)
529         *oldChild = NULL;
530
531     child_node = get_node_obj(child);
532     if(!child_node) return E_FAIL;
533
534     if(child_node->node->parent != This->node)
535     {
536         WARN("childNode %p is not a child of %p\n", child, This);
537         return E_INVALIDARG;
538     }
539
540     xmlUnlinkNode(child_node->node);
541     child_node->parent = NULL;
542     xmldoc_add_orphan(child_node->node->doc, child_node->node);
543
544     if(oldChild)
545     {
546         IXMLDOMNode_AddRef(child);
547         *oldChild = child;
548     }
549
550     return S_OK;
551 }
552
553 HRESULT node_append_child(xmlnode *This, IXMLDOMNode *child, IXMLDOMNode **outChild)
554 {
555     DOMNodeType type;
556     VARIANT var;
557     HRESULT hr;
558
559     hr = IXMLDOMNode_get_nodeType(child, &type);
560     if(FAILED(hr) || type == NODE_ATTRIBUTE) {
561         if (outChild) *outChild = NULL;
562         return E_FAIL;
563     }
564
565     VariantInit(&var);
566     return IXMLDOMNode_insertBefore(This->iface, child, var, outChild);
567 }
568
569 HRESULT node_has_childnodes(const xmlnode *This, VARIANT_BOOL *ret)
570 {
571     if (!ret) return E_INVALIDARG;
572
573     if (!This->node->children)
574     {
575         *ret = VARIANT_FALSE;
576         return S_FALSE;
577     }
578
579     *ret = VARIANT_TRUE;
580     return S_OK;
581 }
582
583 HRESULT node_get_owner_doc(const xmlnode *This, IXMLDOMDocument **doc)
584 {
585     return get_domdoc_from_xmldoc(This->node->doc, (IXMLDOMDocument3**)doc);
586 }
587
588 HRESULT node_clone(xmlnode *This, VARIANT_BOOL deep, IXMLDOMNode **cloneNode)
589 {
590     IXMLDOMNode *node;
591     xmlNodePtr clone;
592
593     if(!cloneNode) return E_INVALIDARG;
594
595     clone = xmlCopyNode(This->node, deep ? 1 : 2);
596     if (clone)
597     {
598         xmlSetTreeDoc(clone, This->node->doc);
599         xmldoc_add_orphan(clone->doc, clone);
600
601         node = create_node(clone);
602         if (!node)
603         {
604             ERR("Copy failed\n");
605             xmldoc_remove_orphan(clone->doc, clone);
606             xmlFreeNode(clone);
607             return E_FAIL;
608         }
609
610         *cloneNode = node;
611     }
612     else
613     {
614         ERR("Copy failed\n");
615         return E_FAIL;
616     }
617
618     return S_OK;
619 }
620
621 static inline xmlChar* trim_whitespace(xmlChar* str)
622 {
623     xmlChar* ret = str;
624     int len;
625
626     if (!str)
627         return NULL;
628
629     while (*ret && isspace(*ret))
630         ++ret;
631     len = xmlStrlen(ret);
632     if (len)
633         while (isspace(ret[len-1])) --len;
634
635     ret = xmlStrndup(ret, len);
636     xmlFree(str);
637     return ret;
638 }
639
640 static xmlChar* do_get_text(xmlNodePtr node)
641 {
642     xmlNodePtr child;
643     xmlChar* str;
644     BOOL preserving = is_preserving_whitespace(node);
645
646     if (!node->children)
647     {
648         str = xmlNodeGetContent(node);
649     }
650     else
651     {
652         xmlElementType prev_type = XML_TEXT_NODE;
653         xmlChar* tmp;
654         str = xmlStrdup(BAD_CAST "");
655         for (child = node->children; child != NULL; child = child->next)
656         {
657             switch (child->type)
658             {
659             case XML_ELEMENT_NODE:
660                 tmp = do_get_text(child);
661                 break;
662             case XML_TEXT_NODE:
663             case XML_CDATA_SECTION_NODE:
664             case XML_ENTITY_REF_NODE:
665             case XML_ENTITY_NODE:
666                 tmp = xmlNodeGetContent(child);
667                 break;
668             default:
669                 tmp = NULL;
670                 break;
671             }
672
673             if (tmp)
674             {
675                 if (*tmp)
676                 {
677                     if (prev_type == XML_ELEMENT_NODE && child->type == XML_ELEMENT_NODE)
678                         str = xmlStrcat(str, BAD_CAST " ");
679                     str = xmlStrcat(str, tmp);
680                     prev_type = child->type;
681                 }
682                 xmlFree(tmp);
683             }
684         }
685     }
686
687     switch (node->type)
688     {
689     case XML_ELEMENT_NODE:
690     case XML_TEXT_NODE:
691     case XML_ENTITY_REF_NODE:
692     case XML_ENTITY_NODE:
693     case XML_DOCUMENT_NODE:
694     case XML_DOCUMENT_FRAG_NODE:
695         if (!preserving)
696             str = trim_whitespace(str);
697         break;
698     default:
699         break;
700     }
701
702     return str;
703 }
704
705 HRESULT node_get_text(const xmlnode *This, BSTR *text)
706 {
707     BSTR str = NULL;
708     xmlChar *content;
709
710     if (!text) return E_INVALIDARG;
711
712     content = do_get_text(This->node);
713     if (content)
714     {
715         str = bstr_from_xmlChar(content);
716         xmlFree(content);
717     }
718
719     /* Always return a string. */
720     if (!str) str = SysAllocStringLen( NULL, 0 );
721
722     TRACE("%p %s\n", This, debugstr_w(str) );
723     *text = str;
724  
725     return S_OK;
726 }
727
728 HRESULT node_put_text(xmlnode *This, BSTR text)
729 {
730     xmlChar *str, *str2;
731
732     TRACE("(%p)->(%s)\n", This, debugstr_w(text));
733
734     str = xmlchar_from_wchar(text);
735
736     /* Escape the string. */
737     str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
738     heap_free(str);
739
740     xmlNodeSetContent(This->node, str2);
741     xmlFree(str2);
742
743     return S_OK;
744 }
745
746 BSTR EnsureCorrectEOL(BSTR sInput)
747 {
748     int nNum = 0;
749     BSTR sNew;
750     int nLen;
751     int i;
752
753     nLen = SysStringLen(sInput);
754     /* Count line endings */
755     for(i=0; i < nLen; i++)
756     {
757         if(sInput[i] == '\n')
758             nNum++;
759     }
760
761     TRACE("len=%d, num=%d\n", nLen, nNum);
762
763     /* Add linefeed as needed */
764     if(nNum > 0)
765     {
766         int nPlace = 0;
767         sNew = SysAllocStringLen(NULL, nLen + nNum);
768         for(i=0; i < nLen; i++)
769         {
770             if(sInput[i] == '\n')
771             {
772                 sNew[i+nPlace] = '\r';
773                 nPlace++;
774             }
775             sNew[i+nPlace] = sInput[i];
776         }
777
778         SysFreeString(sInput);
779     }
780     else
781     {
782         sNew = sInput;
783     }
784
785     TRACE("len %d\n", SysStringLen(sNew));
786
787     return sNew;
788 }
789
790 /*
791  * We are trying to replicate the same behaviour as msxml by converting
792  * line endings to \r\n and using indents as \t. The problem is that msxml
793  * only formats nodes that have a line ending. Using libxml we cannot
794  * reproduce behaviour exactly.
795  *
796  */
797 HRESULT node_get_xml(xmlnode *This, BOOL ensure_eol, BSTR *ret)
798 {
799     xmlBufferPtr xml_buf;
800     xmlNodePtr xmldecl;
801     int size;
802
803     if(!ret)
804         return E_INVALIDARG;
805
806     *ret = NULL;
807
808     xml_buf = xmlBufferCreate();
809     if(!xml_buf)
810         return E_OUTOFMEMORY;
811
812     xmldecl = xmldoc_unlink_xmldecl( This->node->doc );
813
814     size = xmlNodeDump(xml_buf, This->node->doc, This->node, 0, 1);
815     if(size > 0) {
816         const xmlChar *buf_content;
817         BSTR content;
818
819         /* Attribute Nodes return a space in front of their name */
820         buf_content = xmlBufferContent(xml_buf);
821
822         content = bstr_from_xmlChar(buf_content + (buf_content[0] == ' ' ? 1 : 0));
823         if(ensure_eol)
824             content = EnsureCorrectEOL(content);
825
826         *ret = content;
827     }else {
828         *ret = SysAllocStringLen(NULL, 0);
829     }
830
831     xmlBufferFree(xml_buf);
832     xmldoc_link_xmldecl( This->node->doc, xmldecl );
833     return *ret ? S_OK : E_OUTOFMEMORY;
834 }
835
836 static void htmldtd_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
837 {
838     xmlDtdPtr cur = doc->intSubset;
839
840     xmlOutputBufferWriteString(buf, "<!DOCTYPE ");
841     xmlOutputBufferWriteString(buf, (const char *)cur->name);
842     if (cur->ExternalID)
843     {
844         xmlOutputBufferWriteString(buf, " PUBLIC ");
845         xmlBufferWriteQuotedString(buf->buffer, cur->ExternalID);
846         if (cur->SystemID)
847         {
848             xmlOutputBufferWriteString(buf, " ");
849             xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
850         }
851     }
852     else if (cur->SystemID)
853     {
854         xmlOutputBufferWriteString(buf, " SYSTEM ");
855         xmlBufferWriteQuotedString(buf->buffer, cur->SystemID);
856     }
857     xmlOutputBufferWriteString(buf, ">\n");
858 }
859
860 static void htmldoc_dumpcontent(xmlOutputBufferPtr buf, xmlDocPtr doc)
861 {
862     xmlElementType type;
863
864     /* force HTML output */
865     type = doc->type;
866     doc->type = XML_HTML_DOCUMENT_NODE;
867     if (doc->intSubset)
868         htmldtd_dumpcontent(buf, doc);
869     if (doc->children)
870     {
871         xmlNodePtr cur = doc->children;
872
873         while (cur)
874         {
875             htmlNodeDumpFormatOutput(buf, doc, cur, NULL, 1);
876             cur = cur->next;
877         }
878
879     }
880     doc->type = type;
881 }
882
883 HRESULT node_transform_node(const xmlnode *This, IXMLDOMNode *stylesheet, BSTR *p)
884 {
885 #ifdef SONAME_LIBXSLT
886     xsltStylesheetPtr xsltSS;
887     xmlnode *sheet;
888
889     if (!libxslt_handle) return E_NOTIMPL;
890     if (!stylesheet || !p) return E_INVALIDARG;
891
892     *p = NULL;
893
894     sheet = get_node_obj(stylesheet);
895     if(!sheet) return E_FAIL;
896
897     xsltSS = pxsltParseStylesheetDoc(sheet->node->doc);
898     if(xsltSS)
899     {
900         xmlDocPtr result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
901         if(result)
902         {
903             const xmlChar *content;
904
905             if(result->type == XML_HTML_DOCUMENT_NODE)
906             {
907                 xmlOutputBufferPtr output = xmlAllocOutputBuffer(NULL);
908                 if (output)
909                 {
910                     htmldoc_dumpcontent(output, result->doc);
911                     content = xmlBufferContent(output->buffer);
912                     *p = bstr_from_xmlChar(content);
913                     xmlOutputBufferClose(output);
914                 }
915             }
916             else
917             {
918                 xmlBufferPtr buf = xmlBufferCreate();
919                 if (buf)
920                 {
921                     int size = xmlNodeDump(buf, NULL, (xmlNodePtr)result, 0, 0);
922                     if(size > 0)
923                     {
924                         content = xmlBufferContent(buf);
925                         *p = bstr_from_xmlChar(content);
926                     }
927                     xmlBufferFree(buf);
928                 }
929             }
930             xmlFreeDoc(result);
931         }
932         /* libxslt "helpfully" frees the XML document the stylesheet was
933            generated from, too */
934         xsltSS->doc = NULL;
935         pxsltFreeStylesheet(xsltSS);
936     }
937
938     if(!*p) *p = SysAllocStringLen(NULL, 0);
939
940     return S_OK;
941 #else
942     FIXME("libxslt headers were not found at compile time\n");
943     return E_NOTIMPL;
944 #endif
945 }
946
947 HRESULT node_select_nodes(const xmlnode *This, BSTR query, IXMLDOMNodeList **nodes)
948 {
949     xmlChar* str;
950     HRESULT hr;
951
952     if (!query || !nodes) return E_INVALIDARG;
953
954     str = xmlchar_from_wchar(query);
955     hr = create_selection(This->node, str, nodes);
956     heap_free(str);
957
958     return hr;
959 }
960
961 HRESULT node_select_singlenode(const xmlnode *This, BSTR query, IXMLDOMNode **node)
962 {
963     IXMLDOMNodeList *list;
964     HRESULT hr;
965
966     hr = node_select_nodes(This, query, &list);
967     if (hr == S_OK)
968     {
969         hr = IXMLDOMNodeList_nextNode(list, node);
970         IXMLDOMNodeList_Release(list);
971     }
972     return hr;
973 }
974
975 HRESULT node_get_namespaceURI(xmlnode *This, BSTR *namespaceURI)
976 {
977     xmlNsPtr ns = This->node->ns;
978
979     if(!namespaceURI)
980         return E_INVALIDARG;
981
982     *namespaceURI = NULL;
983
984     if (ns && ns->href)
985         *namespaceURI = bstr_from_xmlChar(ns->href);
986
987     TRACE("uri: %s\n", debugstr_w(*namespaceURI));
988
989     return *namespaceURI ? S_OK : S_FALSE;
990 }
991
992 HRESULT node_get_prefix(xmlnode *This, BSTR *prefix)
993 {
994     xmlNsPtr ns = This->node->ns;
995
996     if (!prefix) return E_INVALIDARG;
997
998     *prefix = NULL;
999
1000     if (ns && ns->prefix)
1001         *prefix = bstr_from_xmlChar(ns->prefix);
1002
1003     TRACE("prefix: %s\n", debugstr_w(*prefix));
1004
1005     return *prefix ? S_OK : S_FALSE;
1006 }
1007
1008 HRESULT node_get_base_name(xmlnode *This, BSTR *name)
1009 {
1010     if (!name) return E_INVALIDARG;
1011
1012     *name = bstr_from_xmlChar(This->node->name);
1013     if (!*name) return E_OUTOFMEMORY;
1014
1015     TRACE("returning %s\n", debugstr_w(*name));
1016
1017     return S_OK;
1018 }
1019
1020 void destroy_xmlnode(xmlnode *This)
1021 {
1022     if(This->node)
1023         xmldoc_release(This->node->doc);
1024     release_dispex(&This->dispex);
1025 }
1026
1027 void init_xmlnode(xmlnode *This, xmlNodePtr node, IXMLDOMNode *node_iface, dispex_static_data_t *dispex_data)
1028 {
1029     if(node)
1030         xmldoc_add_ref( node->doc );
1031
1032     This->node = node;
1033     This->iface = node_iface;
1034     This->parent = NULL;
1035
1036     init_dispex(&This->dispex, (IUnknown*)This->iface, dispex_data);
1037 }
1038
1039 typedef struct {
1040     xmlnode node;
1041     IXMLDOMNode IXMLDOMNode_iface;
1042     LONG ref;
1043 } unknode;
1044
1045 static inline unknode *unknode_from_IXMLDOMNode(IXMLDOMNode *iface)
1046 {
1047     return CONTAINING_RECORD(iface, unknode, IXMLDOMNode_iface);
1048 }
1049
1050 static HRESULT WINAPI unknode_QueryInterface(
1051     IXMLDOMNode *iface,
1052     REFIID riid,
1053     void** ppvObject )
1054 {
1055     unknode *This = unknode_from_IXMLDOMNode( iface );
1056
1057     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
1058
1059     if (IsEqualGUID(riid, &IID_IUnknown)) {
1060         *ppvObject = iface;
1061     }else if (IsEqualGUID( riid, &IID_IDispatch) ||
1062               IsEqualGUID( riid, &IID_IXMLDOMNode)) {
1063         *ppvObject = &This->IXMLDOMNode_iface;
1064     }else if(node_query_interface(&This->node, riid, ppvObject)) {
1065         return *ppvObject ? S_OK : E_NOINTERFACE;
1066     }else  {
1067         FIXME("interface %s not implemented\n", debugstr_guid(riid));
1068         *ppvObject = NULL;
1069         return E_NOINTERFACE;
1070     }
1071
1072     IUnknown_AddRef((IUnknown*)*ppvObject);
1073     return S_OK;
1074 }
1075
1076 static ULONG WINAPI unknode_AddRef(
1077     IXMLDOMNode *iface )
1078 {
1079     unknode *This = unknode_from_IXMLDOMNode( iface );
1080
1081     return InterlockedIncrement(&This->ref);
1082 }
1083
1084 static ULONG WINAPI unknode_Release(
1085     IXMLDOMNode *iface )
1086 {
1087     unknode *This = unknode_from_IXMLDOMNode( iface );
1088     LONG ref;
1089
1090     ref = InterlockedDecrement( &This->ref );
1091     if(!ref) {
1092         destroy_xmlnode(&This->node);
1093         heap_free(This);
1094     }
1095
1096     return ref;
1097 }
1098
1099 static HRESULT WINAPI unknode_GetTypeInfoCount(
1100     IXMLDOMNode *iface,
1101     UINT* pctinfo )
1102 {
1103     unknode *This = unknode_from_IXMLDOMNode( iface );
1104
1105     TRACE("(%p)->(%p)\n", This, pctinfo);
1106
1107     *pctinfo = 1;
1108
1109     return S_OK;
1110 }
1111
1112 static HRESULT WINAPI unknode_GetTypeInfo(
1113     IXMLDOMNode *iface,
1114     UINT iTInfo,
1115     LCID lcid,
1116     ITypeInfo** ppTInfo )
1117 {
1118     unknode *This = unknode_from_IXMLDOMNode( iface );
1119     HRESULT hr;
1120
1121     TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1122
1123     hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo);
1124
1125     return hr;
1126 }
1127
1128 static HRESULT WINAPI unknode_GetIDsOfNames(
1129     IXMLDOMNode *iface,
1130     REFIID riid,
1131     LPOLESTR* rgszNames,
1132     UINT cNames,
1133     LCID lcid,
1134     DISPID* rgDispId )
1135 {
1136     unknode *This = unknode_from_IXMLDOMNode( iface );
1137
1138     ITypeInfo *typeinfo;
1139     HRESULT hr;
1140
1141     TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1142           lcid, rgDispId);
1143
1144     if(!rgszNames || cNames == 0 || !rgDispId)
1145         return E_INVALIDARG;
1146
1147     hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1148     if(SUCCEEDED(hr))
1149     {
1150         hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1151         ITypeInfo_Release(typeinfo);
1152     }
1153
1154     return hr;
1155 }
1156
1157 static HRESULT WINAPI unknode_Invoke(
1158     IXMLDOMNode *iface,
1159     DISPID dispIdMember,
1160     REFIID riid,
1161     LCID lcid,
1162     WORD wFlags,
1163     DISPPARAMS* pDispParams,
1164     VARIANT* pVarResult,
1165     EXCEPINFO* pExcepInfo,
1166     UINT* puArgErr )
1167 {
1168     unknode *This = unknode_from_IXMLDOMNode( iface );
1169     ITypeInfo *typeinfo;
1170     HRESULT hr;
1171
1172     TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1173           lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1174
1175     hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1176     if(SUCCEEDED(hr))
1177     {
1178         hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNode_iface, dispIdMember, wFlags, pDispParams,
1179                 pVarResult, pExcepInfo, puArgErr);
1180         ITypeInfo_Release(typeinfo);
1181     }
1182
1183     return hr;
1184 }
1185
1186 static HRESULT WINAPI unknode_get_nodeName(
1187     IXMLDOMNode *iface,
1188     BSTR* p )
1189 {
1190     unknode *This = unknode_from_IXMLDOMNode( iface );
1191
1192     FIXME("(%p)->(%p)\n", This, p);
1193
1194     return node_get_nodeName(&This->node, p);
1195 }
1196
1197 static HRESULT WINAPI unknode_get_nodeValue(
1198     IXMLDOMNode *iface,
1199     VARIANT* value)
1200 {
1201     unknode *This = unknode_from_IXMLDOMNode( iface );
1202
1203     FIXME("(%p)->(%p)\n", This, value);
1204
1205     if(!value)
1206         return E_INVALIDARG;
1207
1208     V_VT(value) = VT_NULL;
1209     return S_FALSE;
1210 }
1211
1212 static HRESULT WINAPI unknode_put_nodeValue(
1213     IXMLDOMNode *iface,
1214     VARIANT value)
1215 {
1216     unknode *This = unknode_from_IXMLDOMNode( iface );
1217     FIXME("(%p)->(v%d)\n", This, V_VT(&value));
1218     return E_FAIL;
1219 }
1220
1221 static HRESULT WINAPI unknode_get_nodeType(
1222     IXMLDOMNode *iface,
1223     DOMNodeType* domNodeType )
1224 {
1225     unknode *This = unknode_from_IXMLDOMNode( iface );
1226
1227     FIXME("(%p)->(%p)\n", This, domNodeType);
1228
1229     *domNodeType = This->node.node->type;
1230     return S_OK;
1231 }
1232
1233 static HRESULT WINAPI unknode_get_parentNode(
1234     IXMLDOMNode *iface,
1235     IXMLDOMNode** parent )
1236 {
1237     unknode *This = unknode_from_IXMLDOMNode( iface );
1238     FIXME("(%p)->(%p)\n", This, parent);
1239     if (!parent) return E_INVALIDARG;
1240     *parent = NULL;
1241     return S_FALSE;
1242 }
1243
1244 static HRESULT WINAPI unknode_get_childNodes(
1245     IXMLDOMNode *iface,
1246     IXMLDOMNodeList** outList)
1247 {
1248     unknode *This = unknode_from_IXMLDOMNode( iface );
1249
1250     TRACE("(%p)->(%p)\n", This, outList);
1251
1252     return node_get_child_nodes(&This->node, outList);
1253 }
1254
1255 static HRESULT WINAPI unknode_get_firstChild(
1256     IXMLDOMNode *iface,
1257     IXMLDOMNode** domNode)
1258 {
1259     unknode *This = unknode_from_IXMLDOMNode( iface );
1260
1261     TRACE("(%p)->(%p)\n", This, domNode);
1262
1263     return node_get_first_child(&This->node, domNode);
1264 }
1265
1266 static HRESULT WINAPI unknode_get_lastChild(
1267     IXMLDOMNode *iface,
1268     IXMLDOMNode** domNode)
1269 {
1270     unknode *This = unknode_from_IXMLDOMNode( iface );
1271
1272     TRACE("(%p)->(%p)\n", This, domNode);
1273
1274     return node_get_last_child(&This->node, domNode);
1275 }
1276
1277 static HRESULT WINAPI unknode_get_previousSibling(
1278     IXMLDOMNode *iface,
1279     IXMLDOMNode** domNode)
1280 {
1281     unknode *This = unknode_from_IXMLDOMNode( iface );
1282
1283     TRACE("(%p)->(%p)\n", This, domNode);
1284
1285     return node_get_previous_sibling(&This->node, domNode);
1286 }
1287
1288 static HRESULT WINAPI unknode_get_nextSibling(
1289     IXMLDOMNode *iface,
1290     IXMLDOMNode** domNode)
1291 {
1292     unknode *This = unknode_from_IXMLDOMNode( iface );
1293
1294     TRACE("(%p)->(%p)\n", This, domNode);
1295
1296     return node_get_next_sibling(&This->node, domNode);
1297 }
1298
1299 static HRESULT WINAPI unknode_get_attributes(
1300     IXMLDOMNode *iface,
1301     IXMLDOMNamedNodeMap** attributeMap)
1302 {
1303     unknode *This = unknode_from_IXMLDOMNode( iface );
1304
1305     FIXME("(%p)->(%p)\n", This, attributeMap);
1306
1307     return return_null_ptr((void**)attributeMap);
1308 }
1309
1310 static HRESULT WINAPI unknode_insertBefore(
1311     IXMLDOMNode *iface,
1312     IXMLDOMNode* newNode, VARIANT refChild,
1313     IXMLDOMNode** outOldNode)
1314 {
1315     unknode *This = unknode_from_IXMLDOMNode( iface );
1316
1317     FIXME("(%p)->(%p x%d %p)\n", This, newNode, V_VT(&refChild), outOldNode);
1318
1319     return node_insert_before(&This->node, newNode, &refChild, outOldNode);
1320 }
1321
1322 static HRESULT WINAPI unknode_replaceChild(
1323     IXMLDOMNode *iface,
1324     IXMLDOMNode* newNode,
1325     IXMLDOMNode* oldNode,
1326     IXMLDOMNode** outOldNode)
1327 {
1328     unknode *This = unknode_from_IXMLDOMNode( iface );
1329
1330     FIXME("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
1331
1332     return node_replace_child(&This->node, newNode, oldNode, outOldNode);
1333 }
1334
1335 static HRESULT WINAPI unknode_removeChild(
1336     IXMLDOMNode *iface,
1337     IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
1338 {
1339     unknode *This = unknode_from_IXMLDOMNode( iface );
1340     return node_remove_child(&This->node, domNode, oldNode);
1341 }
1342
1343 static HRESULT WINAPI unknode_appendChild(
1344     IXMLDOMNode *iface,
1345     IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
1346 {
1347     unknode *This = unknode_from_IXMLDOMNode( iface );
1348     return node_append_child(&This->node, newNode, outNewNode);
1349 }
1350
1351 static HRESULT WINAPI unknode_hasChildNodes(
1352     IXMLDOMNode *iface,
1353     VARIANT_BOOL* pbool)
1354 {
1355     unknode *This = unknode_from_IXMLDOMNode( iface );
1356     return node_has_childnodes(&This->node, pbool);
1357 }
1358
1359 static HRESULT WINAPI unknode_get_ownerDocument(
1360     IXMLDOMNode *iface,
1361     IXMLDOMDocument** domDocument)
1362 {
1363     unknode *This = unknode_from_IXMLDOMNode( iface );
1364     return node_get_owner_doc(&This->node, domDocument);
1365 }
1366
1367 static HRESULT WINAPI unknode_cloneNode(
1368     IXMLDOMNode *iface,
1369     VARIANT_BOOL pbool, IXMLDOMNode** outNode)
1370 {
1371     unknode *This = unknode_from_IXMLDOMNode( iface );
1372     return node_clone(&This->node, pbool, outNode );
1373 }
1374
1375 static HRESULT WINAPI unknode_get_nodeTypeString(
1376     IXMLDOMNode *iface,
1377     BSTR* p)
1378 {
1379     unknode *This = unknode_from_IXMLDOMNode( iface );
1380
1381     FIXME("(%p)->(%p)\n", This, p);
1382
1383     return node_get_nodeName(&This->node, p);
1384 }
1385
1386 static HRESULT WINAPI unknode_get_text(
1387     IXMLDOMNode *iface,
1388     BSTR* p)
1389 {
1390     unknode *This = unknode_from_IXMLDOMNode( iface );
1391     return node_get_text(&This->node, p);
1392 }
1393
1394 static HRESULT WINAPI unknode_put_text(
1395     IXMLDOMNode *iface,
1396     BSTR p)
1397 {
1398     unknode *This = unknode_from_IXMLDOMNode( iface );
1399     return node_put_text(&This->node, p);
1400 }
1401
1402 static HRESULT WINAPI unknode_get_specified(
1403     IXMLDOMNode *iface,
1404     VARIANT_BOOL* isSpecified)
1405 {
1406     unknode *This = unknode_from_IXMLDOMNode( iface );
1407     FIXME("(%p)->(%p) stub!\n", This, isSpecified);
1408     *isSpecified = VARIANT_TRUE;
1409     return S_OK;
1410 }
1411
1412 static HRESULT WINAPI unknode_get_definition(
1413     IXMLDOMNode *iface,
1414     IXMLDOMNode** definitionNode)
1415 {
1416     unknode *This = unknode_from_IXMLDOMNode( iface );
1417     FIXME("(%p)->(%p)\n", This, definitionNode);
1418     return E_NOTIMPL;
1419 }
1420
1421 static HRESULT WINAPI unknode_get_nodeTypedValue(
1422     IXMLDOMNode *iface,
1423     VARIANT* var1)
1424 {
1425     unknode *This = unknode_from_IXMLDOMNode( iface );
1426     FIXME("(%p)->(%p)\n", This, var1);
1427     return return_null_var(var1);
1428 }
1429
1430 static HRESULT WINAPI unknode_put_nodeTypedValue(
1431     IXMLDOMNode *iface,
1432     VARIANT typedValue)
1433 {
1434     unknode *This = unknode_from_IXMLDOMNode( iface );
1435     FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
1436     return E_NOTIMPL;
1437 }
1438
1439 static HRESULT WINAPI unknode_get_dataType(
1440     IXMLDOMNode *iface,
1441     VARIANT* var1)
1442 {
1443     unknode *This = unknode_from_IXMLDOMNode( iface );
1444     TRACE("(%p)->(%p)\n", This, var1);
1445     return return_null_var(var1);
1446 }
1447
1448 static HRESULT WINAPI unknode_put_dataType(
1449     IXMLDOMNode *iface,
1450     BSTR p)
1451 {
1452     unknode *This = unknode_from_IXMLDOMNode( iface );
1453
1454     FIXME("(%p)->(%s)\n", This, debugstr_w(p));
1455
1456     if(!p)
1457         return E_INVALIDARG;
1458
1459     return E_FAIL;
1460 }
1461
1462 static HRESULT WINAPI unknode_get_xml(
1463     IXMLDOMNode *iface,
1464     BSTR* p)
1465 {
1466     unknode *This = unknode_from_IXMLDOMNode( iface );
1467
1468     FIXME("(%p)->(%p)\n", This, p);
1469
1470     return node_get_xml(&This->node, FALSE, p);
1471 }
1472
1473 static HRESULT WINAPI unknode_transformNode(
1474     IXMLDOMNode *iface,
1475     IXMLDOMNode* domNode, BSTR* p)
1476 {
1477     unknode *This = unknode_from_IXMLDOMNode( iface );
1478     return node_transform_node(&This->node, domNode, p);
1479 }
1480
1481 static HRESULT WINAPI unknode_selectNodes(
1482     IXMLDOMNode *iface,
1483     BSTR p, IXMLDOMNodeList** outList)
1484 {
1485     unknode *This = unknode_from_IXMLDOMNode( iface );
1486     return node_select_nodes(&This->node, p, outList);
1487 }
1488
1489 static HRESULT WINAPI unknode_selectSingleNode(
1490     IXMLDOMNode *iface,
1491     BSTR p, IXMLDOMNode** outNode)
1492 {
1493     unknode *This = unknode_from_IXMLDOMNode( iface );
1494     return node_select_singlenode(&This->node, p, outNode);
1495 }
1496
1497 static HRESULT WINAPI unknode_get_parsed(
1498     IXMLDOMNode *iface,
1499     VARIANT_BOOL* isParsed)
1500 {
1501     unknode *This = unknode_from_IXMLDOMNode( iface );
1502     FIXME("(%p)->(%p) stub!\n", This, isParsed);
1503     *isParsed = VARIANT_TRUE;
1504     return S_OK;
1505 }
1506
1507 static HRESULT WINAPI unknode_get_namespaceURI(
1508     IXMLDOMNode *iface,
1509     BSTR* p)
1510 {
1511     unknode *This = unknode_from_IXMLDOMNode( iface );
1512     TRACE("(%p)->(%p)\n", This, p);
1513     return node_get_namespaceURI(&This->node, p);
1514 }
1515
1516 static HRESULT WINAPI unknode_get_prefix(
1517     IXMLDOMNode *iface,
1518     BSTR* p)
1519 {
1520     unknode *This = unknode_from_IXMLDOMNode( iface );
1521     return node_get_prefix(&This->node, p);
1522 }
1523
1524 static HRESULT WINAPI unknode_get_baseName(
1525     IXMLDOMNode *iface,
1526     BSTR* p)
1527 {
1528     unknode *This = unknode_from_IXMLDOMNode( iface );
1529     return node_get_base_name(&This->node, p);
1530 }
1531
1532 static HRESULT WINAPI unknode_transformNodeToObject(
1533     IXMLDOMNode *iface,
1534     IXMLDOMNode* domNode, VARIANT var1)
1535 {
1536     unknode *This = unknode_from_IXMLDOMNode( iface );
1537     FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1538     return E_NOTIMPL;
1539 }
1540
1541 static const struct IXMLDOMNodeVtbl unknode_vtbl =
1542 {
1543     unknode_QueryInterface,
1544     unknode_AddRef,
1545     unknode_Release,
1546     unknode_GetTypeInfoCount,
1547     unknode_GetTypeInfo,
1548     unknode_GetIDsOfNames,
1549     unknode_Invoke,
1550     unknode_get_nodeName,
1551     unknode_get_nodeValue,
1552     unknode_put_nodeValue,
1553     unknode_get_nodeType,
1554     unknode_get_parentNode,
1555     unknode_get_childNodes,
1556     unknode_get_firstChild,
1557     unknode_get_lastChild,
1558     unknode_get_previousSibling,
1559     unknode_get_nextSibling,
1560     unknode_get_attributes,
1561     unknode_insertBefore,
1562     unknode_replaceChild,
1563     unknode_removeChild,
1564     unknode_appendChild,
1565     unknode_hasChildNodes,
1566     unknode_get_ownerDocument,
1567     unknode_cloneNode,
1568     unknode_get_nodeTypeString,
1569     unknode_get_text,
1570     unknode_put_text,
1571     unknode_get_specified,
1572     unknode_get_definition,
1573     unknode_get_nodeTypedValue,
1574     unknode_put_nodeTypedValue,
1575     unknode_get_dataType,
1576     unknode_put_dataType,
1577     unknode_get_xml,
1578     unknode_transformNode,
1579     unknode_selectNodes,
1580     unknode_selectSingleNode,
1581     unknode_get_parsed,
1582     unknode_get_namespaceURI,
1583     unknode_get_prefix,
1584     unknode_get_baseName,
1585     unknode_transformNodeToObject
1586 };
1587
1588 IXMLDOMNode *create_node( xmlNodePtr node )
1589 {
1590     IUnknown *pUnk;
1591     IXMLDOMNode *ret;
1592     HRESULT hr;
1593
1594     if ( !node )
1595         return NULL;
1596
1597     TRACE("type %d\n", node->type);
1598     switch(node->type)
1599     {
1600     case XML_ELEMENT_NODE:
1601         pUnk = create_element( node );
1602         break;
1603     case XML_ATTRIBUTE_NODE:
1604         pUnk = create_attribute( node );
1605         break;
1606     case XML_TEXT_NODE:
1607         pUnk = create_text( node );
1608         break;
1609     case XML_CDATA_SECTION_NODE:
1610         pUnk = create_cdata( node );
1611         break;
1612     case XML_ENTITY_REF_NODE:
1613         pUnk = create_doc_entity_ref( node );
1614         break;
1615     case XML_PI_NODE:
1616         pUnk = create_pi( node );
1617         break;
1618     case XML_COMMENT_NODE:
1619         pUnk = create_comment( node );
1620         break;
1621     case XML_DOCUMENT_NODE:
1622         pUnk = create_domdoc( node );
1623         break;
1624     case XML_DOCUMENT_FRAG_NODE:
1625         pUnk = create_doc_fragment( node );
1626         break;
1627     case XML_DTD_NODE:
1628         pUnk = create_doc_type( node );
1629         break;
1630     default: {
1631         unknode *new_node;
1632
1633         FIXME("only creating basic node for type %d\n", node->type);
1634
1635         new_node = heap_alloc(sizeof(unknode));
1636         if(!new_node)
1637             return NULL;
1638
1639         new_node->IXMLDOMNode_iface.lpVtbl = &unknode_vtbl;
1640         new_node->ref = 1;
1641         init_xmlnode(&new_node->node, node, &new_node->IXMLDOMNode_iface, NULL);
1642         pUnk = (IUnknown*)&new_node->IXMLDOMNode_iface;
1643     }
1644     }
1645
1646     hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1647     IUnknown_Release(pUnk);
1648     if(FAILED(hr)) return NULL;
1649     return ret;
1650 }
1651 #endif