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