ntdll: Use list_empty() instead of list_count() == 0.
[wine/multimedia.git] / dlls / msxml3 / node.c
bloba2e4d6f6b4be374582ebe68d111a0ff20b61fa7b
1 /*
2 * Node implementation
4 * Copyright 2005 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #define COBJMACROS
25 #include <stdarg.h>
27 #ifdef HAVE_LIBXML2
28 # include <libxml/parser.h>
29 # include <libxml/xmlerror.h>
30 # include <libxml/HTMLtree.h>
31 # ifdef SONAME_LIBXSLT
32 # ifdef HAVE_LIBXSLT_PATTERN_H
33 # include <libxslt/pattern.h>
34 # endif
35 # ifdef HAVE_LIBXSLT_TRANSFORM_H
36 # include <libxslt/transform.h>
37 # endif
38 # include <libxslt/xsltutils.h>
39 # include <libxslt/xsltInternals.h>
40 # endif
41 #endif
43 #include "windef.h"
44 #include "winbase.h"
45 #include "winuser.h"
46 #include "winnls.h"
47 #include "ole2.h"
48 #include "msxml6.h"
50 #include "msxml_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
56 #ifdef HAVE_LIBXML2
58 #ifdef SONAME_LIBXSLT
59 extern void* libxslt_handle;
60 # define MAKE_FUNCPTR(f) extern typeof(f) * p##f
61 MAKE_FUNCPTR(xsltApplyStylesheet);
62 MAKE_FUNCPTR(xsltCleanupGlobals);
63 MAKE_FUNCPTR(xsltFreeStylesheet);
64 MAKE_FUNCPTR(xsltParseStylesheetDoc);
65 # undef MAKE_FUNCPTR
66 #endif
68 /* TODO: get rid of these and use the enum */
69 static const WCHAR szBinBase64[] = {'b','i','n','.','b','a','s','e','6','4',0};
70 static const WCHAR szString[] = {'s','t','r','i','n','g',0};
71 static const WCHAR szNumber[] = {'n','u','m','b','e','r',0};
72 static const WCHAR szInt[] = {'I','n','t',0};
73 static const WCHAR szFixed[] = {'F','i','x','e','d','.','1','4','.','4',0};
74 static const WCHAR szBoolean[] = {'B','o','o','l','e','a','n',0};
75 static const WCHAR szDateTime[] = {'d','a','t','e','T','i','m','e',0};
76 static const WCHAR szDateTimeTZ[] = {'d','a','t','e','T','i','m','e','.','t','z',0};
77 static const WCHAR szDate[] = {'D','a','t','e',0};
78 static const WCHAR szTime[] = {'T','i','m','e',0};
79 static const WCHAR szTimeTZ[] = {'T','i','m','e','.','t','z',0};
80 static const WCHAR szI1[] = {'i','1',0};
81 static const WCHAR szI2[] = {'i','2',0};
82 static const WCHAR szI4[] = {'i','4',0};
83 static const WCHAR szIU1[] = {'u','i','1',0};
84 static const WCHAR szIU2[] = {'u','i','2',0};
85 static const WCHAR szIU4[] = {'u','i','4',0};
86 static const WCHAR szR4[] = {'r','4',0};
87 static const WCHAR szR8[] = {'r','8',0};
88 static const WCHAR szFloat[] = {'f','l','o','a','t',0};
89 static const WCHAR szUUID[] = {'u','u','i','d',0};
90 static const WCHAR szBinHex[] = {'b','i','n','.','h','e','x',0};
92 static const IID IID_xmlnode = {0x4f2f4ba2,0xb822,0x11df,{0x8b,0x8a,0x68,0x50,0xdf,0xd7,0x20,0x85}};
94 xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type )
96 xmlnode *This;
98 if ( !iface )
99 return NULL;
100 This = get_node_obj( iface );
101 if ( !This || !This->node )
102 return NULL;
103 if ( type && This->node->type != type )
104 return NULL;
105 return This->node;
108 BOOL node_query_interface(xmlnode *This, REFIID riid, void **ppv)
110 if(IsEqualGUID(&IID_xmlnode, riid)) {
111 TRACE("(%p)->(IID_xmlnode %p)\n", This, ppv);
112 *ppv = This;
113 return TRUE;
116 if(This->dispex.outer)
117 return dispex_query_interface(&This->dispex, riid, ppv);
119 return FALSE;
122 xmlnode *get_node_obj(IXMLDOMNode *node)
124 xmlnode *obj = NULL;
125 HRESULT hres;
127 hres = IXMLDOMNode_QueryInterface(node, &IID_xmlnode, (void**)&obj);
128 if (!obj) WARN("node is not our IXMLDOMNode implementation\n");
129 return SUCCEEDED(hres) ? obj : NULL;
132 HRESULT node_get_nodeName(xmlnode *This, BSTR *name)
134 if (!name)
135 return E_INVALIDARG;
137 *name = bstr_from_xmlChar(This->node->name);
138 if (!*name)
139 return S_FALSE;
141 return S_OK;
144 HRESULT node_get_content(xmlnode *This, VARIANT *value)
146 xmlChar *content;
148 if(!value)
149 return E_INVALIDARG;
151 content = xmlNodeGetContent(This->node);
152 V_VT(value) = VT_BSTR;
153 V_BSTR(value) = bstr_from_xmlChar( content );
154 xmlFree(content);
156 TRACE("%p returned %s\n", This, debugstr_w(V_BSTR(value)));
157 return S_OK;
160 HRESULT node_set_content(xmlnode *This, LPCWSTR value)
162 xmlChar *str;
164 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
165 str = xmlchar_from_wchar(value);
166 if(!str)
167 return E_OUTOFMEMORY;
169 xmlNodeSetContent(This->node, str);
170 heap_free(str);
171 return S_OK;
174 static HRESULT node_set_content_escaped(xmlnode *This, LPCWSTR value)
176 xmlChar *str, *escaped;
178 TRACE("(%p)->(%s)\n", This, debugstr_w(value));
179 str = xmlchar_from_wchar(value);
180 if(!str)
181 return E_OUTOFMEMORY;
183 escaped = xmlEncodeSpecialChars(NULL, str);
184 if(!escaped)
186 heap_free(str);
187 return E_OUTOFMEMORY;
190 xmlNodeSetContent(This->node, escaped);
192 heap_free(str);
193 xmlFree(escaped);
195 return S_OK;
198 HRESULT node_put_value(xmlnode *This, VARIANT *value)
200 VARIANT string_value;
201 HRESULT hr;
203 VariantInit(&string_value);
204 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
205 if(FAILED(hr)) {
206 WARN("Couldn't convert to VT_BSTR\n");
207 return hr;
210 hr = node_set_content(This, V_BSTR(&string_value));
211 VariantClear(&string_value);
213 return hr;
216 HRESULT node_put_value_escaped(xmlnode *This, VARIANT *value)
218 VARIANT string_value;
219 HRESULT hr;
221 VariantInit(&string_value);
222 hr = VariantChangeType(&string_value, value, 0, VT_BSTR);
223 if(FAILED(hr)) {
224 WARN("Couldn't convert to VT_BSTR\n");
225 return hr;
228 hr = node_set_content_escaped(This, V_BSTR(&string_value));
229 VariantClear(&string_value);
231 return hr;
234 static HRESULT get_node(
235 xmlnode *This,
236 const char *name,
237 xmlNodePtr node,
238 IXMLDOMNode **out )
240 TRACE("(%p)->(%s %p %p)\n", This, name, node, out );
242 if ( !out )
243 return E_INVALIDARG;
245 /* if we don't have a doc, use our parent. */
246 if(node && !node->doc && node->parent)
247 node->doc = node->parent->doc;
249 *out = create_node( node );
250 if (!*out)
251 return S_FALSE;
252 return S_OK;
255 HRESULT node_get_parent(xmlnode *This, IXMLDOMNode **parent)
257 return get_node( This, "parent", This->node->parent, parent );
260 HRESULT node_get_child_nodes(xmlnode *This, IXMLDOMNodeList **ret)
262 if(!ret)
263 return E_INVALIDARG;
265 *ret = create_children_nodelist(This->node);
266 if(!*ret)
267 return E_OUTOFMEMORY;
269 return S_OK;
272 HRESULT node_get_first_child(xmlnode *This, IXMLDOMNode **ret)
274 return get_node(This, "firstChild", This->node->children, ret);
277 HRESULT node_get_last_child(xmlnode *This, IXMLDOMNode **ret)
279 return get_node(This, "lastChild", This->node->last, ret);
282 HRESULT node_get_previous_sibling(xmlnode *This, IXMLDOMNode **ret)
284 return get_node(This, "previous", This->node->prev, ret);
287 HRESULT node_get_next_sibling(xmlnode *This, IXMLDOMNode **ret)
289 return get_node(This, "next", This->node->next, ret);
292 HRESULT node_insert_before(xmlnode *This, IXMLDOMNode *new_child, const VARIANT *ref_child,
293 IXMLDOMNode **ret)
295 IXMLDOMNode *before = NULL;
296 xmlnode *node_obj;
297 xmlDocPtr doc;
298 HRESULT hr;
300 if(!new_child)
301 return E_INVALIDARG;
303 node_obj = get_node_obj(new_child);
304 if(!node_obj) return E_FAIL;
306 switch(V_VT(ref_child))
308 case VT_EMPTY:
309 case VT_NULL:
310 break;
312 case VT_UNKNOWN:
313 case VT_DISPATCH:
314 hr = IUnknown_QueryInterface(V_UNKNOWN(ref_child), &IID_IXMLDOMNode, (void**)&before);
315 if(FAILED(hr)) return hr;
316 break;
318 default:
319 FIXME("refChild var type %x\n", V_VT(ref_child));
320 return E_FAIL;
323 TRACE("new child %p, This->node %p\n", node_obj->node, This->node);
325 if(!node_obj->node->parent)
326 if(xmldoc_remove_orphan(node_obj->node->doc, node_obj->node) != S_OK)
327 WARN("%p is not an orphan of %p\n", node_obj->node, node_obj->node->doc);
329 if(before)
331 xmlnode *before_node_obj = get_node_obj(before);
332 IXMLDOMNode_Release(before);
333 if(!before_node_obj) return E_FAIL;
335 /* unlink from current parent first */
336 if(node_obj->parent)
338 hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
339 if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
341 doc = node_obj->node->doc;
342 xmldoc_add_ref(before_node_obj->node->doc);
343 xmlAddPrevSibling(before_node_obj->node, node_obj->node);
344 xmldoc_release(doc);
345 node_obj->parent = This->parent;
347 else
349 /* unlink from current parent first */
350 if(node_obj->parent)
352 hr = IXMLDOMNode_removeChild(node_obj->parent, node_obj->iface, NULL);
353 if (hr == S_OK) xmldoc_remove_orphan(node_obj->node->doc, node_obj->node);
355 doc = node_obj->node->doc;
356 xmldoc_add_ref(This->node->doc);
357 /* xmlAddChild doesn't unlink node from previous parent */
358 xmlUnlinkNode(node_obj->node);
359 xmlAddChild(This->node, node_obj->node);
360 xmldoc_release(doc);
361 node_obj->parent = This->iface;
364 if(ret)
366 IXMLDOMNode_AddRef(new_child);
367 *ret = new_child;
370 TRACE("ret S_OK\n");
371 return S_OK;
374 HRESULT node_replace_child(xmlnode *This, IXMLDOMNode *newChild, IXMLDOMNode *oldChild,
375 IXMLDOMNode **ret)
377 xmlnode *old_child, *new_child;
378 xmlDocPtr leaving_doc;
379 xmlNode *my_ancestor;
381 /* Do not believe any documentation telling that newChild == NULL
382 means removal. It does certainly *not* apply to msxml3! */
383 if(!newChild || !oldChild)
384 return E_INVALIDARG;
386 if(ret)
387 *ret = NULL;
389 old_child = get_node_obj(oldChild);
390 if(!old_child) return E_FAIL;
392 if(old_child->node->parent != This->node)
394 WARN("childNode %p is not a child of %p\n", oldChild, This);
395 return E_INVALIDARG;
398 new_child = get_node_obj(newChild);
399 if(!new_child) return E_FAIL;
401 my_ancestor = This->node;
402 while(my_ancestor)
404 if(my_ancestor == new_child->node)
406 WARN("tried to create loop\n");
407 return E_FAIL;
409 my_ancestor = my_ancestor->parent;
412 if(!new_child->node->parent)
413 if(xmldoc_remove_orphan(new_child->node->doc, new_child->node) != S_OK)
414 WARN("%p is not an orphan of %p\n", new_child->node, new_child->node->doc);
416 leaving_doc = new_child->node->doc;
417 xmldoc_add_ref(old_child->node->doc);
418 xmlReplaceNode(old_child->node, new_child->node);
419 xmldoc_release(leaving_doc);
420 new_child->parent = old_child->parent;
421 old_child->parent = NULL;
423 xmldoc_add_orphan(old_child->node->doc, old_child->node);
425 if(ret)
427 IXMLDOMNode_AddRef(oldChild);
428 *ret = oldChild;
431 return S_OK;
434 HRESULT node_remove_child(xmlnode *This, IXMLDOMNode* child, IXMLDOMNode** oldChild)
436 xmlnode *child_node;
438 if(!child) return E_INVALIDARG;
440 if(oldChild)
441 *oldChild = NULL;
443 child_node = get_node_obj(child);
444 if(!child_node) return E_FAIL;
446 if(child_node->node->parent != This->node)
448 WARN("childNode %p is not a child of %p\n", child, This);
449 return E_INVALIDARG;
452 xmlUnlinkNode(child_node->node);
453 child_node->parent = NULL;
454 xmldoc_add_orphan(child_node->node->doc, child_node->node);
456 if(oldChild)
458 IXMLDOMNode_AddRef(child);
459 *oldChild = child;
462 return S_OK;
465 HRESULT node_append_child(xmlnode *This, IXMLDOMNode *child, IXMLDOMNode **outChild)
467 DOMNodeType type;
468 VARIANT var;
469 HRESULT hr;
471 hr = IXMLDOMNode_get_nodeType(child, &type);
472 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
473 if (outChild) *outChild = NULL;
474 return E_FAIL;
477 VariantInit(&var);
478 return IXMLDOMNode_insertBefore(This->iface, child, var, outChild);
481 HRESULT node_has_childnodes(const xmlnode *This, VARIANT_BOOL *ret)
483 if (!ret) return E_INVALIDARG;
485 if (!This->node->children)
487 *ret = VARIANT_FALSE;
488 return S_FALSE;
491 *ret = VARIANT_TRUE;
492 return S_OK;
495 HRESULT node_get_owner_doc(const xmlnode *This, IXMLDOMDocument **doc)
497 return get_domdoc_from_xmldoc(This->node->doc, (IXMLDOMDocument3**)doc);
500 HRESULT node_clone(xmlnode *This, VARIANT_BOOL deep, IXMLDOMNode **cloneNode)
502 IXMLDOMNode *node;
503 xmlNodePtr clone;
505 if(!cloneNode) return E_INVALIDARG;
507 clone = xmlCopyNode(This->node, deep ? 1 : 2);
508 if (clone)
510 clone->doc = This->node->doc;
511 xmldoc_add_orphan(clone->doc, clone);
513 node = create_node(clone);
514 if (!node)
516 ERR("Copy failed\n");
517 xmldoc_remove_orphan(clone->doc, clone);
518 xmlFreeNode(clone);
519 return E_FAIL;
522 *cloneNode = node;
524 else
526 ERR("Copy failed\n");
527 return E_FAIL;
530 return S_OK;
533 static inline xmlChar* trim_whitespace(xmlChar* str)
535 xmlChar* ret = str;
536 int len;
538 if (!str)
539 return NULL;
541 while (*ret && isspace(*ret))
542 ++ret;
543 len = xmlStrlen(ret);
544 if (len)
545 while (isspace(ret[len-1])) --len;
547 ret = xmlStrndup(ret, len);
548 xmlFree(str);
549 return ret;
552 static xmlChar* do_get_text(xmlNodePtr node)
554 xmlNodePtr child;
555 xmlChar* str;
556 BOOL preserving = is_preserving_whitespace(node);
558 if (!node->children)
560 str = xmlNodeGetContent(node);
562 else
564 xmlElementType prev_type = XML_TEXT_NODE;
565 xmlChar* tmp;
566 str = xmlStrdup(BAD_CAST "");
567 for (child = node->children; child != NULL; child = child->next)
569 switch (child->type)
571 case XML_ELEMENT_NODE:
572 tmp = do_get_text(child);
573 break;
574 case XML_TEXT_NODE:
575 case XML_CDATA_SECTION_NODE:
576 case XML_ENTITY_REF_NODE:
577 case XML_ENTITY_NODE:
578 tmp = xmlNodeGetContent(child);
579 break;
580 default:
581 tmp = NULL;
582 break;
585 if (tmp)
587 if (*tmp)
589 if (prev_type == XML_ELEMENT_NODE && child->type == XML_ELEMENT_NODE)
590 str = xmlStrcat(str, BAD_CAST " ");
591 str = xmlStrcat(str, tmp);
592 prev_type = child->type;
594 xmlFree(tmp);
599 switch (node->type)
601 case XML_ELEMENT_NODE:
602 case XML_TEXT_NODE:
603 case XML_ENTITY_REF_NODE:
604 case XML_ENTITY_NODE:
605 case XML_DOCUMENT_NODE:
606 case XML_DOCUMENT_FRAG_NODE:
607 if (!preserving)
608 str = trim_whitespace(str);
609 break;
610 default:
611 break;
614 return str;
617 HRESULT node_get_text(const xmlnode *This, BSTR *text)
619 BSTR str = NULL;
620 xmlChar *content;
622 if (!text) return E_INVALIDARG;
624 content = do_get_text(This->node);
625 if (content)
627 str = bstr_from_xmlChar(content);
628 xmlFree(content);
631 /* Always return a string. */
632 if (!str) str = SysAllocStringLen( NULL, 0 );
634 TRACE("%p %s\n", This, debugstr_w(str) );
635 *text = str;
637 return S_OK;
640 HRESULT node_put_text(xmlnode *This, BSTR text)
642 xmlChar *str, *str2;
644 TRACE("(%p)->(%s)\n", This, debugstr_w(text));
646 str = xmlchar_from_wchar(text);
648 /* Escape the string. */
649 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
650 heap_free(str);
652 xmlNodeSetContent(This->node, str2);
653 xmlFree(str2);
655 return S_OK;
658 static inline BYTE hex_to_byte(xmlChar c)
660 if(c <= '9') return c-'0';
661 if(c <= 'F') return c-'A'+10;
662 return c-'a'+10;
665 static inline BYTE base64_to_byte(xmlChar c)
667 if(c == '+') return 62;
668 if(c == '/') return 63;
669 if(c <= '9') return c-'0'+52;
670 if(c <= 'Z') return c-'A';
671 return c-'a'+26;
674 /* TODO: phasing this version out */
675 static inline HRESULT VARIANT_from_xmlChar(xmlChar *str, VARIANT *v, BSTR type)
677 if(!type || !lstrcmpiW(type, szString) ||
678 !lstrcmpiW(type, szNumber) || !lstrcmpiW(type, szUUID))
680 V_VT(v) = VT_BSTR;
681 V_BSTR(v) = bstr_from_xmlChar(str);
683 if(!V_BSTR(v))
684 return E_OUTOFMEMORY;
686 else if(!lstrcmpiW(type, szDateTime) || !lstrcmpiW(type, szDateTimeTZ) ||
687 !lstrcmpiW(type, szDate) || !lstrcmpiW(type, szTime) ||
688 !lstrcmpiW(type, szTimeTZ))
690 VARIANT src;
691 WCHAR *p, *e;
692 SYSTEMTIME st;
693 DOUBLE date = 0.0;
695 st.wYear = 1899;
696 st.wMonth = 12;
697 st.wDay = 30;
698 st.wDayOfWeek = st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
700 V_VT(&src) = VT_BSTR;
701 V_BSTR(&src) = bstr_from_xmlChar(str);
703 if(!V_BSTR(&src))
704 return E_OUTOFMEMORY;
706 p = V_BSTR(&src);
707 e = p + SysStringLen(V_BSTR(&src));
709 if(p+4<e && *(p+4)=='-') /* parse date (yyyy-mm-dd) */
711 st.wYear = atoiW(p);
712 st.wMonth = atoiW(p+5);
713 st.wDay = atoiW(p+8);
714 p += 10;
716 if(*p == 'T') p++;
719 if(p+2<e && *(p+2)==':') /* parse time (hh:mm:ss.?) */
721 st.wHour = atoiW(p);
722 st.wMinute = atoiW(p+3);
723 st.wSecond = atoiW(p+6);
724 p += 8;
726 if(*p == '.')
728 p++;
729 while(isdigitW(*p)) p++;
733 SystemTimeToVariantTime(&st, &date);
734 V_VT(v) = VT_DATE;
735 V_DATE(v) = date;
737 if(*p == '+') /* parse timezone offset (+hh:mm) */
738 V_DATE(v) += (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
739 else if(*p == '-') /* parse timezone offset (-hh:mm) */
740 V_DATE(v) -= (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
742 VariantClear(&src);
744 else if(!lstrcmpiW(type, szBinHex))
746 SAFEARRAYBOUND sab;
747 int i, len;
749 len = xmlStrlen(str)/2;
750 sab.lLbound = 0;
751 sab.cElements = len;
753 V_VT(v) = (VT_ARRAY|VT_UI1);
754 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
756 if(!V_ARRAY(v))
757 return E_OUTOFMEMORY;
759 for(i=0; i<len; i++)
760 ((BYTE*)V_ARRAY(v)->pvData)[i] = (hex_to_byte(str[2*i])<<4)
761 + hex_to_byte(str[2*i+1]);
763 else if(!lstrcmpiW(type, szBinBase64))
765 SAFEARRAYBOUND sab;
766 int i, len;
768 len = xmlStrlen(str);
769 if(str[len-2] == '=') i = 2;
770 else if(str[len-1] == '=') i = 1;
771 else i = 0;
773 sab.lLbound = 0;
774 sab.cElements = len/4*3-i;
776 V_VT(v) = (VT_ARRAY|VT_UI1);
777 V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
779 if(!V_ARRAY(v))
780 return E_OUTOFMEMORY;
782 for(i=0; i<len/4; i++)
784 ((BYTE*)V_ARRAY(v)->pvData)[3*i] = (base64_to_byte(str[4*i])<<2)
785 + (base64_to_byte(str[4*i+1])>>4);
786 if(3*i+1 < sab.cElements)
787 ((BYTE*)V_ARRAY(v)->pvData)[3*i+1] = (base64_to_byte(str[4*i+1])<<4)
788 + (base64_to_byte(str[4*i+2])>>2);
789 if(3*i+2 < sab.cElements)
790 ((BYTE*)V_ARRAY(v)->pvData)[3*i+2] = (base64_to_byte(str[4*i+2])<<6)
791 + base64_to_byte(str[4*i+3]);
794 else
796 VARIANT src;
797 HRESULT hres;
799 if(!lstrcmpiW(type, szInt) || !lstrcmpiW(type, szI4))
800 V_VT(v) = VT_I4;
801 else if(!lstrcmpiW(type, szFixed))
802 V_VT(v) = VT_CY;
803 else if(!lstrcmpiW(type, szBoolean))
804 V_VT(v) = VT_BOOL;
805 else if(!lstrcmpiW(type, szI1))
806 V_VT(v) = VT_I1;
807 else if(!lstrcmpiW(type, szI2))
808 V_VT(v) = VT_I2;
809 else if(!lstrcmpiW(type, szIU1))
810 V_VT(v) = VT_UI1;
811 else if(!lstrcmpiW(type, szIU2))
812 V_VT(v) = VT_UI2;
813 else if(!lstrcmpiW(type, szIU4))
814 V_VT(v) = VT_UI4;
815 else if(!lstrcmpiW(type, szR4))
816 V_VT(v) = VT_R4;
817 else if(!lstrcmpiW(type, szR8) || !lstrcmpiW(type, szFloat))
818 V_VT(v) = VT_R8;
819 else
821 FIXME("Type handling not yet implemented\n");
822 V_VT(v) = VT_BSTR;
825 V_VT(&src) = VT_BSTR;
826 V_BSTR(&src) = bstr_from_xmlChar(str);
828 if(!V_BSTR(&src))
829 return E_OUTOFMEMORY;
831 hres = VariantChangeTypeEx(v, &src, MAKELCID(MAKELANGID(
832 LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),0, V_VT(v));
833 VariantClear(&src);
834 return hres;
837 return S_OK;
840 BSTR EnsureCorrectEOL(BSTR sInput)
842 int nNum = 0;
843 BSTR sNew;
844 int nLen;
845 int i;
847 nLen = SysStringLen(sInput);
848 /* Count line endings */
849 for(i=0; i < nLen; i++)
851 if(sInput[i] == '\n')
852 nNum++;
855 TRACE("len=%d, num=%d\n", nLen, nNum);
857 /* Add linefeed as needed */
858 if(nNum > 0)
860 int nPlace = 0;
861 sNew = SysAllocStringLen(NULL, nLen + nNum+1);
862 for(i=0; i < nLen; i++)
864 if(sInput[i] == '\n')
866 sNew[i+nPlace] = '\r';
867 nPlace++;
869 sNew[i+nPlace] = sInput[i];
872 SysFreeString(sInput);
874 else
876 sNew = sInput;
879 TRACE("len %d\n", SysStringLen(sNew));
881 return sNew;
884 /* Removes encoding information and last character (nullbyte) */
885 static BSTR EnsureNoEncoding(BSTR sInput)
887 static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='};
888 BSTR sNew;
889 WCHAR *pBeg, *pEnd;
891 pBeg = sInput;
892 while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding)))
893 pBeg++;
895 if(*pBeg == '\n')
897 SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1);
898 return sInput;
900 pBeg--;
902 pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2;
903 while(*pEnd != '\"') pEnd++;
904 pEnd++;
906 sNew = SysAllocStringLen(NULL,
907 pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1);
908 memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR));
909 memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR));
911 SysFreeString(sInput);
912 return sNew;
916 * We are trying to replicate the same behaviour as msxml by converting
917 * line endings to \r\n and using indents as \t. The problem is that msxml
918 * only formats nodes that have a line ending. Using libxml we cannot
919 * reproduce behaviour exactly.
922 HRESULT node_get_xml(xmlnode *This, BOOL ensure_eol, BOOL ensure_no_encoding, BSTR *ret)
924 xmlBufferPtr xml_buf;
925 xmlNodePtr xmldecl;
926 int size;
928 if(!ret)
929 return E_INVALIDARG;
931 *ret = NULL;
933 xml_buf = xmlBufferCreate();
934 if(!xml_buf)
935 return E_OUTOFMEMORY;
937 xmldecl = xmldoc_unlink_xmldecl( This->node->doc );
939 size = xmlNodeDump(xml_buf, This->node->doc, This->node, 0, 1);
940 if(size > 0) {
941 const xmlChar *buf_content;
942 BSTR content;
944 /* Attribute Nodes return a space in front of their name */
945 buf_content = xmlBufferContent(xml_buf);
947 content = bstr_from_xmlChar(buf_content + (buf_content[0] == ' ' ? 1 : 0));
948 if(ensure_eol)
949 content = EnsureCorrectEOL(content);
950 if(ensure_no_encoding)
951 content = EnsureNoEncoding(content);
953 *ret = content;
954 }else {
955 *ret = SysAllocStringLen(NULL, 0);
958 xmlBufferFree(xml_buf);
959 xmldoc_link_xmldecl( This->node->doc, xmldecl );
960 return *ret ? S_OK : E_OUTOFMEMORY;
963 HRESULT node_transform_node(const xmlnode *This, IXMLDOMNode *stylesheet, BSTR *p)
965 #ifdef SONAME_LIBXSLT
966 xsltStylesheetPtr xsltSS;
967 xmlnode *sheet;
969 if (!libxslt_handle) return E_NOTIMPL;
970 if (!stylesheet || !p) return E_INVALIDARG;
972 *p = NULL;
974 sheet = get_node_obj(stylesheet);
975 if(!sheet) return E_FAIL;
977 xsltSS = pxsltParseStylesheetDoc(sheet->node->doc);
978 if(xsltSS)
980 xmlDocPtr result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
981 if(result)
983 const xmlChar *content;
985 if(result->type == XML_HTML_DOCUMENT_NODE)
987 xmlOutputBufferPtr output = xmlAllocOutputBuffer(NULL);
988 if (output)
990 htmlDocContentDumpOutput(output, result->doc, NULL);
991 content = xmlBufferContent(output->buffer);
992 *p = bstr_from_xmlChar(content);
993 xmlOutputBufferClose(output);
996 else
998 xmlBufferPtr buf = xmlBufferCreate();
999 if (buf)
1001 int size = xmlNodeDump(buf, NULL, (xmlNodePtr)result, 0, 0);
1002 if(size > 0)
1004 content = xmlBufferContent(buf);
1005 *p = bstr_from_xmlChar(content);
1007 xmlBufferFree(buf);
1010 xmlFreeDoc(result);
1012 /* libxslt "helpfully" frees the XML document the stylesheet was
1013 generated from, too */
1014 xsltSS->doc = NULL;
1015 pxsltFreeStylesheet(xsltSS);
1018 if(!*p) *p = SysAllocStringLen(NULL, 0);
1020 return S_OK;
1021 #else
1022 FIXME("libxslt headers were not found at compile time\n");
1023 return E_NOTIMPL;
1024 #endif
1027 HRESULT node_select_nodes(const xmlnode *This, BSTR query, IXMLDOMNodeList **nodes)
1029 xmlChar* str;
1030 HRESULT hr;
1032 if (!query || !nodes) return E_INVALIDARG;
1034 str = xmlchar_from_wchar(query);
1035 hr = create_selection(This->node, str, nodes);
1036 heap_free(str);
1038 return hr;
1041 HRESULT node_select_singlenode(const xmlnode *This, BSTR query, IXMLDOMNode **node)
1043 IXMLDOMNodeList *list;
1044 HRESULT hr;
1046 hr = node_select_nodes(This, query, &list);
1047 if (hr == S_OK)
1049 hr = IXMLDOMNodeList_nextNode(list, node);
1050 IXMLDOMNodeList_Release(list);
1052 return hr;
1055 HRESULT node_get_namespaceURI(xmlnode *This, BSTR *namespaceURI)
1057 xmlNsPtr *ns;
1059 if(!namespaceURI)
1060 return E_INVALIDARG;
1062 *namespaceURI = NULL;
1064 if ((ns = xmlGetNsList(This->node->doc, This->node)))
1066 if (ns[0]->href) *namespaceURI = bstr_from_xmlChar( ns[0]->href );
1067 xmlFree(ns);
1070 TRACE("uri: %s\n", debugstr_w(*namespaceURI));
1072 return *namespaceURI ? S_OK : S_FALSE;
1075 HRESULT node_get_prefix(xmlnode *This, BSTR *prefix)
1077 xmlNsPtr *ns;
1079 if (!prefix) return E_INVALIDARG;
1081 *prefix = NULL;
1083 if ((ns = xmlGetNsList(This->node->doc, This->node)))
1085 if (ns[0]->prefix) *prefix = bstr_from_xmlChar( ns[0]->prefix );
1086 xmlFree(ns);
1089 TRACE("prefix: %s\n", debugstr_w(*prefix));
1091 return *prefix ? S_OK : S_FALSE;
1094 HRESULT node_get_base_name(xmlnode *This, BSTR *name)
1096 if (!name) return E_INVALIDARG;
1098 *name = bstr_from_xmlChar(This->node->name);
1099 if (!*name) return E_OUTOFMEMORY;
1101 TRACE("returning %s\n", debugstr_w(*name));
1103 return S_OK;
1106 void destroy_xmlnode(xmlnode *This)
1108 if(This->node)
1109 xmldoc_release(This->node->doc);
1112 void init_xmlnode(xmlnode *This, xmlNodePtr node, IXMLDOMNode *node_iface, dispex_static_data_t *dispex_data)
1114 if(node)
1115 xmldoc_add_ref( node->doc );
1117 This->node = node;
1118 This->iface = node_iface;
1119 This->parent = NULL;
1121 if(dispex_data)
1122 init_dispex(&This->dispex, (IUnknown*)This->iface, dispex_data);
1123 else
1124 This->dispex.outer = NULL;
1127 typedef struct {
1128 xmlnode node;
1129 IXMLDOMNode IXMLDOMNode_iface;
1130 LONG ref;
1131 } unknode;
1133 static inline unknode *unknode_from_IXMLDOMNode(IXMLDOMNode *iface)
1135 return CONTAINING_RECORD(iface, unknode, IXMLDOMNode_iface);
1138 static HRESULT WINAPI unknode_QueryInterface(
1139 IXMLDOMNode *iface,
1140 REFIID riid,
1141 void** ppvObject )
1143 unknode *This = unknode_from_IXMLDOMNode( iface );
1145 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
1147 if (IsEqualGUID(riid, &IID_IUnknown)) {
1148 *ppvObject = iface;
1149 }else if (IsEqualGUID( riid, &IID_IDispatch) ||
1150 IsEqualGUID( riid, &IID_IXMLDOMNode)) {
1151 *ppvObject = &This->IXMLDOMNode_iface;
1152 }else if(node_query_interface(&This->node, riid, ppvObject)) {
1153 return *ppvObject ? S_OK : E_NOINTERFACE;
1154 }else {
1155 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1156 *ppvObject = NULL;
1157 return E_NOINTERFACE;
1160 IUnknown_AddRef((IUnknown*)*ppvObject);
1161 return S_OK;
1164 static ULONG WINAPI unknode_AddRef(
1165 IXMLDOMNode *iface )
1167 unknode *This = unknode_from_IXMLDOMNode( iface );
1169 return InterlockedIncrement(&This->ref);
1172 static ULONG WINAPI unknode_Release(
1173 IXMLDOMNode *iface )
1175 unknode *This = unknode_from_IXMLDOMNode( iface );
1176 LONG ref;
1178 ref = InterlockedDecrement( &This->ref );
1179 if(!ref) {
1180 destroy_xmlnode(&This->node);
1181 heap_free(This);
1184 return ref;
1187 static HRESULT WINAPI unknode_GetTypeInfoCount(
1188 IXMLDOMNode *iface,
1189 UINT* pctinfo )
1191 unknode *This = unknode_from_IXMLDOMNode( iface );
1193 TRACE("(%p)->(%p)\n", This, pctinfo);
1195 *pctinfo = 1;
1197 return S_OK;
1200 static HRESULT WINAPI unknode_GetTypeInfo(
1201 IXMLDOMNode *iface,
1202 UINT iTInfo,
1203 LCID lcid,
1204 ITypeInfo** ppTInfo )
1206 unknode *This = unknode_from_IXMLDOMNode( iface );
1207 HRESULT hr;
1209 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
1211 hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo);
1213 return hr;
1216 static HRESULT WINAPI unknode_GetIDsOfNames(
1217 IXMLDOMNode *iface,
1218 REFIID riid,
1219 LPOLESTR* rgszNames,
1220 UINT cNames,
1221 LCID lcid,
1222 DISPID* rgDispId )
1224 unknode *This = unknode_from_IXMLDOMNode( iface );
1226 ITypeInfo *typeinfo;
1227 HRESULT hr;
1229 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
1230 lcid, rgDispId);
1232 if(!rgszNames || cNames == 0 || !rgDispId)
1233 return E_INVALIDARG;
1235 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1236 if(SUCCEEDED(hr))
1238 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
1239 ITypeInfo_Release(typeinfo);
1242 return hr;
1245 static HRESULT WINAPI unknode_Invoke(
1246 IXMLDOMNode *iface,
1247 DISPID dispIdMember,
1248 REFIID riid,
1249 LCID lcid,
1250 WORD wFlags,
1251 DISPPARAMS* pDispParams,
1252 VARIANT* pVarResult,
1253 EXCEPINFO* pExcepInfo,
1254 UINT* puArgErr )
1256 unknode *This = unknode_from_IXMLDOMNode( iface );
1257 ITypeInfo *typeinfo;
1258 HRESULT hr;
1260 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
1261 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1263 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
1264 if(SUCCEEDED(hr))
1266 hr = ITypeInfo_Invoke(typeinfo, &This->IXMLDOMNode_iface, dispIdMember, wFlags, pDispParams,
1267 pVarResult, pExcepInfo, puArgErr);
1268 ITypeInfo_Release(typeinfo);
1271 return hr;
1274 static HRESULT WINAPI unknode_get_nodeName(
1275 IXMLDOMNode *iface,
1276 BSTR* p )
1278 unknode *This = unknode_from_IXMLDOMNode( iface );
1280 FIXME("(%p)->(%p)\n", This, p);
1282 return node_get_nodeName(&This->node, p);
1285 static HRESULT WINAPI unknode_get_nodeValue(
1286 IXMLDOMNode *iface,
1287 VARIANT* value)
1289 unknode *This = unknode_from_IXMLDOMNode( iface );
1291 FIXME("(%p)->(%p)\n", This, value);
1293 if(!value)
1294 return E_INVALIDARG;
1296 V_VT(value) = VT_NULL;
1297 return S_FALSE;
1300 static HRESULT WINAPI unknode_put_nodeValue(
1301 IXMLDOMNode *iface,
1302 VARIANT value)
1304 unknode *This = unknode_from_IXMLDOMNode( iface );
1305 FIXME("(%p)->(v%d)\n", This, V_VT(&value));
1306 return E_FAIL;
1309 static HRESULT WINAPI unknode_get_nodeType(
1310 IXMLDOMNode *iface,
1311 DOMNodeType* domNodeType )
1313 unknode *This = unknode_from_IXMLDOMNode( iface );
1315 FIXME("(%p)->(%p)\n", This, domNodeType);
1317 *domNodeType = This->node.node->type;
1318 return S_OK;
1321 static HRESULT WINAPI unknode_get_parentNode(
1322 IXMLDOMNode *iface,
1323 IXMLDOMNode** parent )
1325 unknode *This = unknode_from_IXMLDOMNode( iface );
1326 FIXME("(%p)->(%p)\n", This, parent);
1327 if (!parent) return E_INVALIDARG;
1328 *parent = NULL;
1329 return S_FALSE;
1332 static HRESULT WINAPI unknode_get_childNodes(
1333 IXMLDOMNode *iface,
1334 IXMLDOMNodeList** outList)
1336 unknode *This = unknode_from_IXMLDOMNode( iface );
1338 TRACE("(%p)->(%p)\n", This, outList);
1340 return node_get_child_nodes(&This->node, outList);
1343 static HRESULT WINAPI unknode_get_firstChild(
1344 IXMLDOMNode *iface,
1345 IXMLDOMNode** domNode)
1347 unknode *This = unknode_from_IXMLDOMNode( iface );
1349 TRACE("(%p)->(%p)\n", This, domNode);
1351 return node_get_first_child(&This->node, domNode);
1354 static HRESULT WINAPI unknode_get_lastChild(
1355 IXMLDOMNode *iface,
1356 IXMLDOMNode** domNode)
1358 unknode *This = unknode_from_IXMLDOMNode( iface );
1360 TRACE("(%p)->(%p)\n", This, domNode);
1362 return node_get_last_child(&This->node, domNode);
1365 static HRESULT WINAPI unknode_get_previousSibling(
1366 IXMLDOMNode *iface,
1367 IXMLDOMNode** domNode)
1369 unknode *This = unknode_from_IXMLDOMNode( iface );
1371 TRACE("(%p)->(%p)\n", This, domNode);
1373 return node_get_previous_sibling(&This->node, domNode);
1376 static HRESULT WINAPI unknode_get_nextSibling(
1377 IXMLDOMNode *iface,
1378 IXMLDOMNode** domNode)
1380 unknode *This = unknode_from_IXMLDOMNode( iface );
1382 TRACE("(%p)->(%p)\n", This, domNode);
1384 return node_get_next_sibling(&This->node, domNode);
1387 static HRESULT WINAPI unknode_get_attributes(
1388 IXMLDOMNode *iface,
1389 IXMLDOMNamedNodeMap** attributeMap)
1391 unknode *This = unknode_from_IXMLDOMNode( iface );
1393 FIXME("(%p)->(%p)\n", This, attributeMap);
1395 return return_null_ptr((void**)attributeMap);
1398 static HRESULT WINAPI unknode_insertBefore(
1399 IXMLDOMNode *iface,
1400 IXMLDOMNode* newNode, VARIANT refChild,
1401 IXMLDOMNode** outOldNode)
1403 unknode *This = unknode_from_IXMLDOMNode( iface );
1405 FIXME("(%p)->(%p x%d %p)\n", This, newNode, V_VT(&refChild), outOldNode);
1407 return node_insert_before(&This->node, newNode, &refChild, outOldNode);
1410 static HRESULT WINAPI unknode_replaceChild(
1411 IXMLDOMNode *iface,
1412 IXMLDOMNode* newNode,
1413 IXMLDOMNode* oldNode,
1414 IXMLDOMNode** outOldNode)
1416 unknode *This = unknode_from_IXMLDOMNode( iface );
1418 FIXME("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
1420 return node_replace_child(&This->node, newNode, oldNode, outOldNode);
1423 static HRESULT WINAPI unknode_removeChild(
1424 IXMLDOMNode *iface,
1425 IXMLDOMNode* domNode, IXMLDOMNode** oldNode)
1427 unknode *This = unknode_from_IXMLDOMNode( iface );
1428 return node_remove_child(&This->node, domNode, oldNode);
1431 static HRESULT WINAPI unknode_appendChild(
1432 IXMLDOMNode *iface,
1433 IXMLDOMNode* newNode, IXMLDOMNode** outNewNode)
1435 unknode *This = unknode_from_IXMLDOMNode( iface );
1436 return node_append_child(&This->node, newNode, outNewNode);
1439 static HRESULT WINAPI unknode_hasChildNodes(
1440 IXMLDOMNode *iface,
1441 VARIANT_BOOL* pbool)
1443 unknode *This = unknode_from_IXMLDOMNode( iface );
1444 return node_has_childnodes(&This->node, pbool);
1447 static HRESULT WINAPI unknode_get_ownerDocument(
1448 IXMLDOMNode *iface,
1449 IXMLDOMDocument** domDocument)
1451 unknode *This = unknode_from_IXMLDOMNode( iface );
1452 return node_get_owner_doc(&This->node, domDocument);
1455 static HRESULT WINAPI unknode_cloneNode(
1456 IXMLDOMNode *iface,
1457 VARIANT_BOOL pbool, IXMLDOMNode** outNode)
1459 unknode *This = unknode_from_IXMLDOMNode( iface );
1460 return node_clone(&This->node, pbool, outNode );
1463 static HRESULT WINAPI unknode_get_nodeTypeString(
1464 IXMLDOMNode *iface,
1465 BSTR* p)
1467 unknode *This = unknode_from_IXMLDOMNode( iface );
1469 FIXME("(%p)->(%p)\n", This, p);
1471 return node_get_nodeName(&This->node, p);
1474 static HRESULT WINAPI unknode_get_text(
1475 IXMLDOMNode *iface,
1476 BSTR* p)
1478 unknode *This = unknode_from_IXMLDOMNode( iface );
1479 return node_get_text(&This->node, p);
1482 static HRESULT WINAPI unknode_put_text(
1483 IXMLDOMNode *iface,
1484 BSTR p)
1486 unknode *This = unknode_from_IXMLDOMNode( iface );
1487 return node_put_text(&This->node, p);
1490 static HRESULT WINAPI unknode_get_specified(
1491 IXMLDOMNode *iface,
1492 VARIANT_BOOL* isSpecified)
1494 unknode *This = unknode_from_IXMLDOMNode( iface );
1495 FIXME("(%p)->(%p) stub!\n", This, isSpecified);
1496 *isSpecified = VARIANT_TRUE;
1497 return S_OK;
1500 static HRESULT WINAPI unknode_get_definition(
1501 IXMLDOMNode *iface,
1502 IXMLDOMNode** definitionNode)
1504 unknode *This = unknode_from_IXMLDOMNode( iface );
1505 FIXME("(%p)->(%p)\n", This, definitionNode);
1506 return E_NOTIMPL;
1509 static HRESULT WINAPI unknode_get_nodeTypedValue(
1510 IXMLDOMNode *iface,
1511 VARIANT* var1)
1513 unknode *This = unknode_from_IXMLDOMNode( iface );
1514 FIXME("(%p)->(%p)\n", This, var1);
1515 return return_null_var(var1);
1518 static HRESULT WINAPI unknode_put_nodeTypedValue(
1519 IXMLDOMNode *iface,
1520 VARIANT typedValue)
1522 unknode *This = unknode_from_IXMLDOMNode( iface );
1523 FIXME("(%p)->(%s)\n", This, debugstr_variant(&typedValue));
1524 return E_NOTIMPL;
1527 static HRESULT WINAPI unknode_get_dataType(
1528 IXMLDOMNode *iface,
1529 VARIANT* var1)
1531 unknode *This = unknode_from_IXMLDOMNode( iface );
1532 TRACE("(%p)->(%p)\n", This, var1);
1533 return return_null_var(var1);
1536 static HRESULT WINAPI unknode_put_dataType(
1537 IXMLDOMNode *iface,
1538 BSTR p)
1540 unknode *This = unknode_from_IXMLDOMNode( iface );
1542 FIXME("(%p)->(%s)\n", This, debugstr_w(p));
1544 if(!p)
1545 return E_INVALIDARG;
1547 return E_FAIL;
1550 static HRESULT WINAPI unknode_get_xml(
1551 IXMLDOMNode *iface,
1552 BSTR* p)
1554 unknode *This = unknode_from_IXMLDOMNode( iface );
1556 FIXME("(%p)->(%p)\n", This, p);
1558 return node_get_xml(&This->node, FALSE, FALSE, p);
1561 static HRESULT WINAPI unknode_transformNode(
1562 IXMLDOMNode *iface,
1563 IXMLDOMNode* domNode, BSTR* p)
1565 unknode *This = unknode_from_IXMLDOMNode( iface );
1566 return node_transform_node(&This->node, domNode, p);
1569 static HRESULT WINAPI unknode_selectNodes(
1570 IXMLDOMNode *iface,
1571 BSTR p, IXMLDOMNodeList** outList)
1573 unknode *This = unknode_from_IXMLDOMNode( iface );
1574 return node_select_nodes(&This->node, p, outList);
1577 static HRESULT WINAPI unknode_selectSingleNode(
1578 IXMLDOMNode *iface,
1579 BSTR p, IXMLDOMNode** outNode)
1581 unknode *This = unknode_from_IXMLDOMNode( iface );
1582 return node_select_singlenode(&This->node, p, outNode);
1585 static HRESULT WINAPI unknode_get_parsed(
1586 IXMLDOMNode *iface,
1587 VARIANT_BOOL* isParsed)
1589 unknode *This = unknode_from_IXMLDOMNode( iface );
1590 FIXME("(%p)->(%p) stub!\n", This, isParsed);
1591 *isParsed = VARIANT_TRUE;
1592 return S_OK;
1595 static HRESULT WINAPI unknode_get_namespaceURI(
1596 IXMLDOMNode *iface,
1597 BSTR* p)
1599 unknode *This = unknode_from_IXMLDOMNode( iface );
1600 TRACE("(%p)->(%p)\n", This, p);
1601 return node_get_namespaceURI(&This->node, p);
1604 static HRESULT WINAPI unknode_get_prefix(
1605 IXMLDOMNode *iface,
1606 BSTR* p)
1608 unknode *This = unknode_from_IXMLDOMNode( iface );
1609 return node_get_prefix(&This->node, p);
1612 static HRESULT WINAPI unknode_get_baseName(
1613 IXMLDOMNode *iface,
1614 BSTR* p)
1616 unknode *This = unknode_from_IXMLDOMNode( iface );
1617 return node_get_base_name(&This->node, p);
1620 static HRESULT WINAPI unknode_transformNodeToObject(
1621 IXMLDOMNode *iface,
1622 IXMLDOMNode* domNode, VARIANT var1)
1624 unknode *This = unknode_from_IXMLDOMNode( iface );
1625 FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
1626 return E_NOTIMPL;
1629 static const struct IXMLDOMNodeVtbl unknode_vtbl =
1631 unknode_QueryInterface,
1632 unknode_AddRef,
1633 unknode_Release,
1634 unknode_GetTypeInfoCount,
1635 unknode_GetTypeInfo,
1636 unknode_GetIDsOfNames,
1637 unknode_Invoke,
1638 unknode_get_nodeName,
1639 unknode_get_nodeValue,
1640 unknode_put_nodeValue,
1641 unknode_get_nodeType,
1642 unknode_get_parentNode,
1643 unknode_get_childNodes,
1644 unknode_get_firstChild,
1645 unknode_get_lastChild,
1646 unknode_get_previousSibling,
1647 unknode_get_nextSibling,
1648 unknode_get_attributes,
1649 unknode_insertBefore,
1650 unknode_replaceChild,
1651 unknode_removeChild,
1652 unknode_appendChild,
1653 unknode_hasChildNodes,
1654 unknode_get_ownerDocument,
1655 unknode_cloneNode,
1656 unknode_get_nodeTypeString,
1657 unknode_get_text,
1658 unknode_put_text,
1659 unknode_get_specified,
1660 unknode_get_definition,
1661 unknode_get_nodeTypedValue,
1662 unknode_put_nodeTypedValue,
1663 unknode_get_dataType,
1664 unknode_put_dataType,
1665 unknode_get_xml,
1666 unknode_transformNode,
1667 unknode_selectNodes,
1668 unknode_selectSingleNode,
1669 unknode_get_parsed,
1670 unknode_get_namespaceURI,
1671 unknode_get_prefix,
1672 unknode_get_baseName,
1673 unknode_transformNodeToObject
1676 IXMLDOMNode *create_node( xmlNodePtr node )
1678 IUnknown *pUnk;
1679 IXMLDOMNode *ret;
1680 HRESULT hr;
1682 if ( !node )
1683 return NULL;
1685 TRACE("type %d\n", node->type);
1686 switch(node->type)
1688 case XML_ELEMENT_NODE:
1689 pUnk = create_element( node );
1690 break;
1691 case XML_ATTRIBUTE_NODE:
1692 pUnk = create_attribute( node );
1693 break;
1694 case XML_TEXT_NODE:
1695 pUnk = create_text( node );
1696 break;
1697 case XML_CDATA_SECTION_NODE:
1698 pUnk = create_cdata( node );
1699 break;
1700 case XML_ENTITY_REF_NODE:
1701 pUnk = create_doc_entity_ref( node );
1702 break;
1703 case XML_PI_NODE:
1704 pUnk = create_pi( node );
1705 break;
1706 case XML_COMMENT_NODE:
1707 pUnk = create_comment( node );
1708 break;
1709 case XML_DOCUMENT_NODE:
1710 pUnk = create_domdoc( node );
1711 break;
1712 case XML_DOCUMENT_FRAG_NODE:
1713 pUnk = create_doc_fragment( node );
1714 break;
1715 case XML_DTD_NODE:
1716 pUnk = create_doc_type( node );
1717 break;
1718 default: {
1719 unknode *new_node;
1721 FIXME("only creating basic node for type %d\n", node->type);
1723 new_node = heap_alloc(sizeof(unknode));
1724 if(!new_node)
1725 return NULL;
1727 new_node->IXMLDOMNode_iface.lpVtbl = &unknode_vtbl;
1728 new_node->ref = 1;
1729 init_xmlnode(&new_node->node, node, &new_node->IXMLDOMNode_iface, NULL);
1730 pUnk = (IUnknown*)&new_node->IXMLDOMNode_iface;
1734 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1735 IUnknown_Release(pUnk);
1736 if(FAILED(hr)) return NULL;
1737 return ret;
1739 #endif