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