stash
[wine/wine64.git] / dlls / msxml3 / node.c
blob69601e397332d8bc0369f2fec478a0ebaef833fe
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>
26 #include <assert.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "ole2.h"
32 #include "msxml2.h"
34 #include "msxml_private.h"
36 #ifdef HAVE_LIBXML2
37 # include <libxml/HTMLtree.h>
38 #endif
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44 #ifdef HAVE_LIBXML2
46 static const WCHAR szBinBase64[] = {'b','i','n','.','b','a','s','e','6','4',0};
47 static const WCHAR szString[] = {'s','t','r','i','n','g',0};
48 static const WCHAR szNumber[] = {'n','u','m','b','e','r',0};
49 static const WCHAR szInt[] = {'I','n','t',0};
50 static const WCHAR szFixed[] = {'F','i','x','e','d','.','1','4','.','4',0};
51 static const WCHAR szBoolean[] = {'B','o','o','l','e','a','n',0};
52 static const WCHAR szDateTime[] = {'d','a','t','e','T','i','m','e',0};
53 static const WCHAR szDateTimeTZ[] = {'d','a','t','e','T','i','m','e','.','t','z',0};
54 static const WCHAR szDate[] = {'D','a','t','e',0};
55 static const WCHAR szTime[] = {'T','i','m','e',0};
56 static const WCHAR szTimeTZ[] = {'T','i','m','e','.','t','z',0};
57 static const WCHAR szI1[] = {'i','1',0};
58 static const WCHAR szI2[] = {'i','2',0};
59 static const WCHAR szI4[] = {'i','4',0};
60 static const WCHAR szIU1[] = {'u','i','1',0};
61 static const WCHAR szIU2[] = {'u','i','2',0};
62 static const WCHAR szIU4[] = {'u','i','4',0};
63 static const WCHAR szR4[] = {'r','4',0};
64 static const WCHAR szR8[] = {'r','8',0};
65 static const WCHAR szFloat[] = {'f','l','o','a','t',0};
66 static const WCHAR szUUID[] = {'u','u','i','d',0};
67 static const WCHAR szBinHex[] = {'b','i','n','.','h','e','x',0};
69 static inline xmlnode *impl_from_InternalUnknown( IUnknown *iface )
71 return (xmlnode *)((char*)iface - FIELD_OFFSET(xmlnode, lpInternalUnkVtbl));
74 xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type )
76 xmlnode *This;
78 if ( !iface )
79 return NULL;
80 This = impl_from_IXMLDOMNode( iface );
81 if ( !This->node )
82 return NULL;
83 if ( type && This->node->type != type )
84 return NULL;
85 return This->node;
88 static HRESULT WINAPI xmlnode_QueryInterface(
89 IXMLDOMNode *iface,
90 REFIID riid,
91 void** ppvObject )
93 xmlnode *This = impl_from_IXMLDOMNode( iface );
94 TRACE("%p %s %p\n", This, debugstr_guid(riid), ppvObject);
96 return IUnknown_QueryInterface(This->pUnkOuter, riid, ppvObject);
99 static ULONG WINAPI xmlnode_AddRef(
100 IXMLDOMNode *iface )
102 xmlnode *This = impl_from_IXMLDOMNode( iface );
103 return IUnknown_AddRef(This->pUnkOuter);
106 static ULONG WINAPI xmlnode_Release(
107 IXMLDOMNode *iface )
109 xmlnode *This = impl_from_IXMLDOMNode( iface );
110 return IUnknown_Release(This->pUnkOuter);
113 static HRESULT WINAPI xmlnode_GetTypeInfoCount(
114 IXMLDOMNode *iface,
115 UINT* pctinfo )
117 xmlnode *This = impl_from_IXMLDOMNode( iface );
119 TRACE("(%p)->(%p)\n", This, pctinfo);
121 *pctinfo = 1;
123 return S_OK;
126 static HRESULT WINAPI xmlnode_GetTypeInfo(
127 IXMLDOMNode *iface,
128 UINT iTInfo,
129 LCID lcid,
130 ITypeInfo** ppTInfo )
132 xmlnode *This = impl_from_IXMLDOMNode( iface );
133 HRESULT hr;
135 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
137 hr = get_typeinfo(IXMLDOMNode_tid, ppTInfo);
139 return hr;
142 static HRESULT WINAPI xmlnode_GetIDsOfNames(
143 IXMLDOMNode *iface,
144 REFIID riid,
145 LPOLESTR* rgszNames,
146 UINT cNames,
147 LCID lcid,
148 DISPID* rgDispId )
150 xmlnode *This = impl_from_IXMLDOMNode( iface );
152 ITypeInfo *typeinfo;
153 HRESULT hr;
155 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
156 lcid, rgDispId);
158 if(!rgszNames || cNames == 0 || !rgDispId)
159 return E_INVALIDARG;
161 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
162 if(SUCCEEDED(hr))
164 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
165 ITypeInfo_Release(typeinfo);
168 return hr;
171 static HRESULT WINAPI xmlnode_Invoke(
172 IXMLDOMNode *iface,
173 DISPID dispIdMember,
174 REFIID riid,
175 LCID lcid,
176 WORD wFlags,
177 DISPPARAMS* pDispParams,
178 VARIANT* pVarResult,
179 EXCEPINFO* pExcepInfo,
180 UINT* puArgErr )
182 xmlnode *This = impl_from_IXMLDOMNode( iface );
183 ITypeInfo *typeinfo;
184 HRESULT hr;
186 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
187 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
189 hr = get_typeinfo(IXMLDOMNode_tid, &typeinfo);
190 if(SUCCEEDED(hr))
192 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
193 pVarResult, pExcepInfo, puArgErr);
194 ITypeInfo_Release(typeinfo);
197 return hr;
200 static HRESULT WINAPI xmlnode_get_nodeName(
201 IXMLDOMNode *iface,
202 BSTR* name)
204 xmlnode *This = impl_from_IXMLDOMNode( iface );
205 const xmlChar *str;
207 TRACE("%p\n", This );
209 if (!name)
210 return E_INVALIDARG;
212 if ( !This->node )
213 return E_FAIL;
215 switch( This->node->type )
217 case XML_CDATA_SECTION_NODE:
218 str = (const xmlChar*) "#cdata-section";
219 break;
220 case XML_COMMENT_NODE:
221 str = (const xmlChar*) "#comment";
222 break;
223 case XML_DOCUMENT_FRAG_NODE:
224 str = (const xmlChar*) "#document-fragment";
225 break;
226 case XML_TEXT_NODE:
227 str = (const xmlChar*) "#text";
228 break;
229 case XML_DOCUMENT_NODE:
230 str = (const xmlChar*) "#document";
231 break;
232 case XML_ATTRIBUTE_NODE:
233 case XML_ELEMENT_NODE:
234 case XML_PI_NODE:
235 str = This->node->name;
236 break;
237 default:
238 FIXME("nodeName not mapped correctly (%d)\n", This->node->type);
239 str = This->node->name;
240 break;
243 *name = bstr_from_xmlChar( str );
244 if (!*name)
245 return S_FALSE;
247 return S_OK;
250 BSTR bstr_from_xmlChar( const xmlChar *buf )
252 DWORD len;
253 LPWSTR str;
254 BSTR bstr;
256 if ( !buf )
257 return NULL;
259 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) buf, -1, NULL, 0 );
260 str = HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
261 if ( !str )
262 return NULL;
263 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) buf, -1, str, len );
264 bstr = SysAllocString( str );
265 HeapFree( GetProcessHeap(), 0, str );
266 return bstr;
269 static HRESULT WINAPI xmlnode_get_nodeValue(
270 IXMLDOMNode *iface,
271 VARIANT* value)
273 xmlnode *This = impl_from_IXMLDOMNode( iface );
274 HRESULT r = S_FALSE;
276 TRACE("%p %p\n", This, value);
278 if(!value)
279 return E_INVALIDARG;
281 V_BSTR(value) = NULL;
282 V_VT(value) = VT_NULL;
284 switch ( This->node->type )
286 case XML_CDATA_SECTION_NODE:
287 case XML_COMMENT_NODE:
288 case XML_PI_NODE:
289 case XML_ATTRIBUTE_NODE:
291 xmlChar *content = xmlNodeGetContent(This->node);
292 V_VT(value) = VT_BSTR;
293 V_BSTR(value) = bstr_from_xmlChar( content );
294 xmlFree(content);
295 r = S_OK;
296 break;
298 case XML_TEXT_NODE:
299 V_VT(value) = VT_BSTR;
300 V_BSTR(value) = bstr_from_xmlChar( This->node->content );
301 r = S_OK;
302 break;
303 case XML_ELEMENT_NODE:
304 case XML_DOCUMENT_NODE:
305 /* these seem to return NULL */
306 break;
308 default:
309 FIXME("node %p type %d\n", This, This->node->type);
312 TRACE("%p returned %s\n", This, debugstr_w( V_BSTR(value) ) );
314 return r;
317 static HRESULT WINAPI xmlnode_put_nodeValue(
318 IXMLDOMNode *iface,
319 VARIANT value)
321 xmlnode *This = impl_from_IXMLDOMNode( iface );
322 HRESULT hr;
323 xmlChar *str = NULL;
324 VARIANT string_value;
326 TRACE("%p type(%d)\n", This, This->node->type);
328 VariantInit(&string_value);
329 hr = VariantChangeType(&string_value, &value, 0, VT_BSTR);
330 if(FAILED(hr))
332 VariantClear(&string_value);
333 WARN("Couldn't convert to VT_BSTR\n");
334 return hr;
337 hr = S_FALSE;
338 /* Document, Document Fragment, Document Type, Element,
339 Entity, Entity Reference, Notation aren't supported. */
340 switch ( This->node->type )
342 case XML_ATTRIBUTE_NODE:
343 case XML_CDATA_SECTION_NODE:
344 case XML_COMMENT_NODE:
345 case XML_PI_NODE:
346 case XML_TEXT_NODE:
348 str = xmlChar_from_wchar((WCHAR*)V_BSTR(&string_value));
349 xmlNodeSetContent(This->node, str);
350 HeapFree(GetProcessHeap(),0,str);
351 hr = S_OK;
352 break;
354 default:
355 /* Do nothing for unsupported types. */
356 break;
359 VariantClear(&string_value);
361 return hr;
364 static HRESULT WINAPI xmlnode_get_nodeType(
365 IXMLDOMNode *iface,
366 DOMNodeType* type)
368 xmlnode *This = impl_from_IXMLDOMNode( iface );
370 TRACE("%p %p\n", This, type);
372 assert( NODE_ELEMENT == XML_ELEMENT_NODE );
373 assert( NODE_NOTATION == XML_NOTATION_NODE );
375 *type = This->node->type;
377 return S_OK;
380 static HRESULT get_node(
381 xmlnode *This,
382 const char *name,
383 xmlNodePtr node,
384 IXMLDOMNode **out )
386 TRACE("%p->%s %p\n", This, name, node );
388 if ( !out )
389 return E_INVALIDARG;
390 *out = create_node( node );
391 if (!*out)
392 return S_FALSE;
393 return S_OK;
396 static HRESULT WINAPI xmlnode_get_parentNode(
397 IXMLDOMNode *iface,
398 IXMLDOMNode** parent)
400 xmlnode *This = impl_from_IXMLDOMNode( iface );
401 return get_node( This, "parent", This->node->parent, parent );
404 static HRESULT WINAPI xmlnode_get_childNodes(
405 IXMLDOMNode *iface,
406 IXMLDOMNodeList** childList)
408 xmlnode *This = impl_from_IXMLDOMNode( iface );
410 TRACE("%p %p\n", This, childList );
412 if ( !childList )
413 return E_INVALIDARG;
415 *childList = create_children_nodelist(This->node);
416 if (*childList == NULL)
417 return E_OUTOFMEMORY;
419 return S_OK;
422 static HRESULT WINAPI xmlnode_get_firstChild(
423 IXMLDOMNode *iface,
424 IXMLDOMNode** firstChild)
426 xmlnode *This = impl_from_IXMLDOMNode( iface );
427 return get_node( This, "firstChild", This->node->children, firstChild );
430 static HRESULT WINAPI xmlnode_get_lastChild(
431 IXMLDOMNode *iface,
432 IXMLDOMNode** lastChild)
434 xmlnode *This = impl_from_IXMLDOMNode( iface );
436 TRACE("%p\n", This );
438 if (!lastChild)
439 return E_INVALIDARG;
441 switch( This->node->type )
443 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
444 case XML_TEXT_NODE:
445 case XML_CDATA_SECTION_NODE:
446 case XML_PI_NODE:
447 case XML_COMMENT_NODE:
448 *lastChild = NULL;
449 return S_FALSE;
450 default:
451 return get_node( This, "lastChild", This->node->last, lastChild );
455 static HRESULT WINAPI xmlnode_get_previousSibling(
456 IXMLDOMNode *iface,
457 IXMLDOMNode** previousSibling)
459 xmlnode *This = impl_from_IXMLDOMNode( iface );
461 TRACE("%p\n", This );
463 if (!previousSibling)
464 return E_INVALIDARG;
466 switch( This->node->type )
468 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
469 case XML_DOCUMENT_NODE:
470 case XML_DOCUMENT_FRAG_NODE:
471 case XML_ATTRIBUTE_NODE:
472 *previousSibling = NULL;
473 return S_FALSE;
474 default:
475 return get_node( This, "previous", This->node->prev, previousSibling );
479 static HRESULT WINAPI xmlnode_get_nextSibling(
480 IXMLDOMNode *iface,
481 IXMLDOMNode** nextSibling)
483 xmlnode *This = impl_from_IXMLDOMNode( iface );
485 TRACE("%p\n", This );
487 if (!nextSibling)
488 return E_INVALIDARG;
490 switch( This->node->type )
492 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
493 case XML_DOCUMENT_NODE:
494 case XML_DOCUMENT_FRAG_NODE:
495 case XML_ATTRIBUTE_NODE:
496 *nextSibling = NULL;
497 return S_FALSE;
498 default:
499 return get_node( This, "next", This->node->next, nextSibling );
503 static HRESULT WINAPI xmlnode_get_attributes(
504 IXMLDOMNode *iface,
505 IXMLDOMNamedNodeMap** attributeMap)
507 xmlnode *This = impl_from_IXMLDOMNode( iface );
508 TRACE("%p\n", This);
510 if (!attributeMap)
511 return E_INVALIDARG;
513 switch( This->node->type )
515 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
516 Entity and Text Nodes does not support get_attributes */
517 case XML_ATTRIBUTE_NODE:
518 case XML_CDATA_SECTION_NODE:
519 case XML_COMMENT_NODE:
520 case XML_DOCUMENT_NODE:
521 case XML_DOCUMENT_FRAG_NODE:
522 case XML_ENTITY_NODE:
523 case XML_ENTITY_REF_NODE:
524 case XML_TEXT_NODE:
525 *attributeMap = NULL;
526 return S_FALSE;
527 default:
528 *attributeMap = create_nodemap( iface );
529 return S_OK;
533 static HRESULT WINAPI xmlnode_insertBefore(
534 IXMLDOMNode *iface,
535 IXMLDOMNode* newChild,
536 VARIANT refChild,
537 IXMLDOMNode** outNewChild)
539 xmlnode *This = impl_from_IXMLDOMNode( iface );
540 xmlNodePtr before_node, new_child_node;
541 IXMLDOMNode *before = NULL, *new;
542 HRESULT hr;
544 TRACE("(%p)->(%p,var,%p)\n",This,newChild,outNewChild);
546 if (!newChild)
547 return E_INVALIDARG;
549 switch(V_VT(&refChild))
551 case VT_EMPTY:
552 case VT_NULL:
553 break;
555 case VT_UNKNOWN:
556 hr = IUnknown_QueryInterface(V_UNKNOWN(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
557 if(FAILED(hr)) return hr;
558 break;
560 case VT_DISPATCH:
561 hr = IDispatch_QueryInterface(V_DISPATCH(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
562 if(FAILED(hr)) return hr;
563 break;
565 default:
566 FIXME("refChild var type %x\n", V_VT(&refChild));
567 return E_FAIL;
570 IXMLDOMNode_QueryInterface(newChild, &IID_IXMLDOMNode, (LPVOID)&new);
571 new_child_node = impl_from_IXMLDOMNode(new)->node;
572 TRACE("new_child_node %p This->node %p\n", new_child_node, This->node);
574 if(!new_child_node->parent)
575 if(xmldoc_remove_orphan(new_child_node->doc, new_child_node) != S_OK)
576 WARN("%p is not an orphan of %p\n", new_child_node, new_child_node->doc);
578 if(before)
580 before_node = impl_from_IXMLDOMNode(before)->node;
581 xmlAddPrevSibling(before_node, new_child_node);
582 IXMLDOMNode_Release(before);
584 else
586 xmlAddChild(This->node, new_child_node);
589 IXMLDOMNode_Release(new);
590 IXMLDOMNode_AddRef(newChild);
591 if(outNewChild)
592 *outNewChild = newChild;
594 TRACE("ret S_OK\n");
595 return S_OK;
598 static HRESULT WINAPI xmlnode_replaceChild(
599 IXMLDOMNode *iface,
600 IXMLDOMNode* newChild,
601 IXMLDOMNode* oldChild,
602 IXMLDOMNode** outOldChild)
604 xmlnode *This = impl_from_IXMLDOMNode( iface );
605 xmlNode *old_child_ptr, *new_child_ptr;
606 xmlDocPtr leaving_doc;
607 xmlNode *my_ancestor;
608 IXMLDOMNode *realOldChild;
609 HRESULT hr;
611 TRACE("%p->(%p,%p,%p)\n",This,newChild,oldChild,outOldChild);
613 /* Do not believe any documentation telling that newChild == NULL
614 means removal. It does certainly *not* apply to msxml3! */
615 if(!newChild || !oldChild)
616 return E_INVALIDARG;
618 if(outOldChild)
619 *outOldChild = NULL;
621 hr = IXMLDOMNode_QueryInterface(oldChild,&IID_IXMLDOMNode,(LPVOID*)&realOldChild);
622 if(FAILED(hr))
623 return hr;
625 old_child_ptr = impl_from_IXMLDOMNode(realOldChild)->node;
626 IXMLDOMNode_Release(realOldChild);
627 if(old_child_ptr->parent != This->node)
629 WARN("childNode %p is not a child of %p\n", oldChild, iface);
630 return E_INVALIDARG;
633 new_child_ptr = impl_from_IXMLDOMNode(newChild)->node;
634 my_ancestor = This->node;
635 while(my_ancestor)
637 if(my_ancestor == new_child_ptr)
639 WARN("tried to create loop\n");
640 return E_FAIL;
642 my_ancestor = my_ancestor->parent;
645 if(!new_child_ptr->parent)
646 if(xmldoc_remove_orphan(new_child_ptr->doc, new_child_ptr) != S_OK)
647 WARN("%p is not an orphan of %p\n", new_child_ptr, new_child_ptr->doc);
649 leaving_doc = new_child_ptr->doc;
650 xmldoc_add_ref(old_child_ptr->doc);
651 xmlReplaceNode(old_child_ptr, new_child_ptr);
652 xmldoc_release(leaving_doc);
654 xmldoc_add_orphan(old_child_ptr->doc, old_child_ptr);
656 if(outOldChild)
658 IXMLDOMNode_AddRef(oldChild);
659 *outOldChild = oldChild;
662 return S_OK;
665 static HRESULT WINAPI xmlnode_removeChild(
666 IXMLDOMNode *iface,
667 IXMLDOMNode* childNode,
668 IXMLDOMNode** oldChild)
670 xmlnode *This = impl_from_IXMLDOMNode( iface );
671 xmlNode *child_node_ptr;
672 HRESULT hr;
673 IXMLDOMNode *child;
675 TRACE("%p->(%p, %p)\n", This, childNode, oldChild);
677 if(!childNode) return E_INVALIDARG;
679 if(oldChild)
680 *oldChild = NULL;
682 hr = IXMLDOMNode_QueryInterface(childNode, &IID_IXMLDOMNode, (LPVOID)&child);
683 if(FAILED(hr))
684 return hr;
686 child_node_ptr = impl_from_IXMLDOMNode(child)->node;
687 if(child_node_ptr->parent != This->node)
689 WARN("childNode %p is not a child of %p\n", childNode, iface);
690 IXMLDOMNode_Release(child);
691 return E_INVALIDARG;
694 xmlUnlinkNode(child_node_ptr);
696 IXMLDOMNode_Release(child);
698 if(oldChild)
700 IXMLDOMNode_AddRef(childNode);
701 *oldChild = childNode;
704 return S_OK;
707 static HRESULT WINAPI xmlnode_appendChild(
708 IXMLDOMNode *iface,
709 IXMLDOMNode* newChild,
710 IXMLDOMNode** outNewChild)
712 xmlnode *This = impl_from_IXMLDOMNode( iface );
713 DOMNodeType type;
714 VARIANT var;
715 HRESULT hr;
717 TRACE("(%p)->(%p,%p)\n", This, newChild, outNewChild);
719 hr = IXMLDOMNode_get_nodeType(newChild, &type);
720 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
721 if(outNewChild) *outNewChild = NULL;
722 return E_FAIL;
725 VariantInit(&var);
726 return IXMLDOMNode_insertBefore(iface, newChild, var, outNewChild);
729 static HRESULT WINAPI xmlnode_hasChildNodes(
730 IXMLDOMNode *iface,
731 VARIANT_BOOL* hasChild)
733 xmlnode *This = impl_from_IXMLDOMNode( iface );
735 TRACE("%p\n", This);
737 if (!hasChild)
738 return E_INVALIDARG;
739 if (!This->node->children)
741 *hasChild = VARIANT_FALSE;
742 return S_FALSE;
745 *hasChild = VARIANT_TRUE;
746 return S_OK;
749 static HRESULT WINAPI xmlnode_get_ownerDocument(
750 IXMLDOMNode *iface,
751 IXMLDOMDocument** DOMDocument)
753 xmlnode *This = impl_from_IXMLDOMNode( iface );
755 TRACE("%p (%p)\n", This, DOMDocument);
757 return DOMDocument_create_from_xmldoc(This->node->doc, (IXMLDOMDocument2**)DOMDocument);
760 static HRESULT WINAPI xmlnode_cloneNode(
761 IXMLDOMNode *iface,
762 VARIANT_BOOL deep,
763 IXMLDOMNode** cloneRoot)
765 xmlnode *This = impl_from_IXMLDOMNode( iface );
766 xmlNodePtr pClone = NULL;
767 IXMLDOMNode *pNode = NULL;
769 TRACE("%p (%d)\n", This, deep);
771 if(!cloneRoot)
772 return E_INVALIDARG;
774 pClone = xmlCopyNode(This->node, deep ? 1 : 2);
775 if(pClone)
777 pClone->doc = This->node->doc;
778 xmldoc_add_orphan(pClone->doc, pClone);
780 pNode = create_node(pClone);
781 if(!pNode)
783 ERR("Copy failed\n");
784 return E_FAIL;
787 *cloneRoot = pNode;
789 else
791 ERR("Copy failed\n");
792 return E_FAIL;
795 return S_OK;
798 static HRESULT WINAPI xmlnode_get_nodeTypeString(
799 IXMLDOMNode *iface,
800 BSTR* xmlnodeType)
802 xmlnode *This = impl_from_IXMLDOMNode( iface );
803 const xmlChar *str;
805 TRACE("%p\n", This );
807 if (!xmlnodeType)
808 return E_INVALIDARG;
810 if ( !This->node )
811 return E_FAIL;
813 switch( This->node->type )
815 case XML_ATTRIBUTE_NODE:
816 str = (const xmlChar*) "attribute";
817 break;
818 case XML_CDATA_SECTION_NODE:
819 str = (const xmlChar*) "cdatasection";
820 break;
821 case XML_COMMENT_NODE:
822 str = (const xmlChar*) "comment";
823 break;
824 case XML_DOCUMENT_NODE:
825 str = (const xmlChar*) "document";
826 break;
827 case XML_DOCUMENT_FRAG_NODE:
828 str = (const xmlChar*) "documentfragment";
829 break;
830 case XML_ELEMENT_NODE:
831 str = (const xmlChar*) "element";
832 break;
833 case XML_ENTITY_NODE:
834 str = (const xmlChar*) "entity";
835 break;
836 case XML_ENTITY_REF_NODE:
837 str = (const xmlChar*) "entityreference";
838 break;
839 case XML_NOTATION_NODE:
840 str = (const xmlChar*) "notation";
841 break;
842 case XML_PI_NODE:
843 str = (const xmlChar*) "processinginstruction";
844 break;
845 case XML_TEXT_NODE:
846 str = (const xmlChar*) "text";
847 break;
848 default:
849 FIXME("Unknown node type (%d)\n", This->node->type);
850 str = This->node->name;
851 break;
854 *xmlnodeType = bstr_from_xmlChar( str );
855 if (!*xmlnodeType)
856 return S_FALSE;
858 return S_OK;
861 static HRESULT WINAPI xmlnode_get_text(
862 IXMLDOMNode *iface,
863 BSTR* text)
865 xmlnode *This = impl_from_IXMLDOMNode( iface );
866 BSTR str = NULL;
867 xmlChar *pContent;
869 TRACE("%p type %d\n", This, This->node->type);
871 if ( !text )
872 return E_INVALIDARG;
874 pContent = xmlNodeGetContent((xmlNodePtr)This->node);
875 if(pContent)
877 str = bstr_from_xmlChar(pContent);
878 xmlFree(pContent);
881 /* Always return a string. */
882 if (!str) str = SysAllocStringLen( NULL, 0 );
884 TRACE("%p %s\n", This, debugstr_w(str) );
885 *text = str;
887 return S_OK;
890 static HRESULT WINAPI xmlnode_put_text(
891 IXMLDOMNode *iface,
892 BSTR text)
894 xmlnode *This = impl_from_IXMLDOMNode( iface );
895 xmlChar *str, *str2;
897 TRACE("%p\n", This);
899 switch(This->node->type)
901 case XML_DOCUMENT_NODE:
902 return E_FAIL;
903 default:
904 break;
907 str = xmlChar_from_wchar((WCHAR*)text);
909 /* Escape the string. */
910 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
911 HeapFree(GetProcessHeap(), 0, str);
913 xmlNodeSetContent(This->node, str2);
914 xmlFree(str2);
916 return S_OK;
919 static HRESULT WINAPI xmlnode_get_specified(
920 IXMLDOMNode *iface,
921 VARIANT_BOOL* isSpecified)
923 FIXME("\n");
924 return E_NOTIMPL;
927 static HRESULT WINAPI xmlnode_get_definition(
928 IXMLDOMNode *iface,
929 IXMLDOMNode** definitionNode)
931 FIXME("\n");
932 return E_NOTIMPL;
935 static HRESULT WINAPI xmlnode_get_nodeTypedValue(
936 IXMLDOMNode *iface,
937 VARIANT* typedValue)
939 xmlnode *This = impl_from_IXMLDOMNode( iface );
940 HRESULT r = S_FALSE;
942 FIXME("ignoring data type %p %p\n", This, typedValue);
944 if(!typedValue)
945 return E_INVALIDARG;
947 V_VT(typedValue) = VT_NULL;
949 switch ( This->node->type )
951 case XML_ELEMENT_NODE:
953 xmlChar *content = xmlNodeGetContent(This->node);
954 V_VT(typedValue) = VT_BSTR;
955 V_BSTR(typedValue) = bstr_from_xmlChar( content );
956 xmlFree(content);
957 r = S_OK;
958 break;
960 default:
961 r = xmlnode_get_nodeValue(iface, typedValue);
964 return r;
967 static HRESULT WINAPI xmlnode_put_nodeTypedValue(
968 IXMLDOMNode *iface,
969 VARIANT typedValue)
971 FIXME("\n");
972 return E_NOTIMPL;
975 static HRESULT WINAPI xmlnode_get_dataType(
976 IXMLDOMNode *iface,
977 VARIANT* dataTypeName)
979 xmlnode *This = impl_from_IXMLDOMNode( iface );
980 xmlChar *pVal;
982 TRACE("iface %p\n", iface);
984 if(!dataTypeName)
985 return E_INVALIDARG;
987 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
988 Entity, Notation, PI, and Text Node are non-typed. */
989 V_BSTR(dataTypeName) = NULL;
990 V_VT(dataTypeName) = VT_NULL;
992 switch ( This->node->type )
994 case XML_ELEMENT_NODE:
995 pVal = xmlGetNsProp(This->node, (xmlChar*)"dt",
996 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
997 if (pVal)
999 V_VT(dataTypeName) = VT_BSTR;
1000 V_BSTR(dataTypeName) = bstr_from_xmlChar( pVal );
1001 xmlFree(pVal);
1003 break;
1004 case XML_ENTITY_REF_NODE:
1005 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
1006 break;
1007 default:
1008 TRACE("Type %d returning NULL\n", This->node->type);
1011 /* non-typed nodes return S_FALSE */
1012 if(V_VT(dataTypeName) == VT_NULL)
1014 return S_FALSE;
1017 return S_OK;
1020 static HRESULT WINAPI xmlnode_put_dataType(
1021 IXMLDOMNode *iface,
1022 BSTR dataTypeName)
1024 xmlnode *This = impl_from_IXMLDOMNode( iface );
1025 HRESULT hr = E_FAIL;
1027 TRACE("iface %p\n", iface);
1029 if(dataTypeName == NULL)
1030 return E_INVALIDARG;
1032 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1033 This applies to changing types (string->bool) or setting a new one
1035 FIXME("Need to Validate the data before allowing a type to be set.\n");
1037 /* Check all supported types. */
1038 if(lstrcmpiW(dataTypeName,szString) == 0 ||
1039 lstrcmpiW(dataTypeName,szNumber) == 0 ||
1040 lstrcmpiW(dataTypeName,szUUID) == 0 ||
1041 lstrcmpiW(dataTypeName,szInt) == 0 ||
1042 lstrcmpiW(dataTypeName,szI4) == 0 ||
1043 lstrcmpiW(dataTypeName,szFixed) == 0 ||
1044 lstrcmpiW(dataTypeName,szBoolean) == 0 ||
1045 lstrcmpiW(dataTypeName,szDateTime) == 0 ||
1046 lstrcmpiW(dataTypeName,szDateTimeTZ) == 0 ||
1047 lstrcmpiW(dataTypeName,szDate) == 0 ||
1048 lstrcmpiW(dataTypeName,szTime) == 0 ||
1049 lstrcmpiW(dataTypeName,szTimeTZ) == 0 ||
1050 lstrcmpiW(dataTypeName,szI1) == 0 ||
1051 lstrcmpiW(dataTypeName,szI2) == 0 ||
1052 lstrcmpiW(dataTypeName,szIU1) == 0 ||
1053 lstrcmpiW(dataTypeName,szIU2) == 0 ||
1054 lstrcmpiW(dataTypeName,szIU4) == 0 ||
1055 lstrcmpiW(dataTypeName,szR4) == 0 ||
1056 lstrcmpiW(dataTypeName,szR8) == 0 ||
1057 lstrcmpiW(dataTypeName,szFloat) == 0 ||
1058 lstrcmpiW(dataTypeName,szBinHex) == 0 ||
1059 lstrcmpiW(dataTypeName,szBinBase64) == 0)
1061 xmlNsPtr pNS = NULL;
1062 xmlAttrPtr pAttr = NULL;
1063 xmlChar* str = xmlChar_from_wchar((WCHAR*)dataTypeName);
1065 pAttr = xmlHasNsProp(This->node, (xmlChar*)"dt",
1066 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1067 if (pAttr)
1069 pAttr = xmlSetNsProp(This->node, pAttr->ns, (xmlChar*)"dt", str);
1071 hr = S_OK;
1073 else
1075 pNS = xmlNewNs(This->node, (xmlChar*)"urn:schemas-microsoft-com:datatypes", (xmlChar*)"dt");
1076 if(pNS)
1078 pAttr = xmlNewNsProp(This->node, pNS, (xmlChar*)"dt", str);
1079 if(pAttr)
1081 xmlAddChild(This->node, (xmlNodePtr)pAttr);
1083 hr = S_OK;
1085 else
1086 ERR("Failed to create Attribute\n");
1088 else
1089 ERR("Failed to Create Namepsace\n");
1091 HeapFree( GetProcessHeap(), 0, str );
1094 return hr;
1097 static BSTR EnsureCorrectEOL(BSTR sInput)
1099 static const WCHAR SZ_RETURN[] = {'\n',0};
1100 static const WCHAR SZ_LINEFEED[] = {'\r',0};
1101 int nNum = 0;
1102 BSTR sNew;
1103 int nLen;
1104 int i;
1106 nLen = lstrlenW(sInput);
1107 /* Count line endings */
1108 for(i=0; i < nLen; i++)
1110 if(sInput[i] == SZ_RETURN[0])
1111 nNum++;
1114 TRACE("len=%d, num=%d\n", nLen, nNum);
1116 /* Add linefeed as needed */
1117 if(nNum > 0)
1119 int nPlace = 0;
1120 sNew = SysAllocStringLen(NULL, nLen + nNum+1);
1121 for(i=0; i < nLen; i++)
1123 if(sInput[i] == SZ_RETURN[0])
1125 sNew[i+nPlace] = SZ_LINEFEED[0];
1126 nPlace++;
1128 sNew[i+nPlace] = sInput[i];
1131 SysFreeString(sInput);
1133 else
1135 sNew = sInput;
1138 TRACE("len %d\n", lstrlenW(sNew));
1140 return sNew;
1143 /* Removes encoding information and last character (nullbyte) */
1144 static BSTR EnsureNoEncoding(BSTR sInput)
1146 static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='};
1147 BSTR sNew;
1148 WCHAR *pBeg, *pEnd;
1150 pBeg = sInput;
1151 while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding)))
1152 pBeg++;
1154 if(*pBeg == '\n')
1156 SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1);
1157 return sInput;
1159 pBeg--;
1161 pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2;
1162 while(*pEnd != '\"') pEnd++;
1163 pEnd++;
1165 sNew = SysAllocStringLen(NULL,
1166 pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1);
1167 memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR));
1168 memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR));
1170 SysFreeString(sInput);
1171 return sNew;
1175 * We are trying to replicate the same behaviour as msxml by converting
1176 * line endings to \r\n and using idents as \t. The problem is that msxml
1177 * only formats nodes that have a line ending. Using libxml we cannot
1178 * reproduce behaviour exactly.
1181 static HRESULT WINAPI xmlnode_get_xml(
1182 IXMLDOMNode *iface,
1183 BSTR* xmlString)
1185 xmlnode *This = impl_from_IXMLDOMNode( iface );
1186 xmlBufferPtr pXmlBuf;
1187 int nSize;
1189 TRACE("iface %p %d\n", iface, This->node->type);
1191 if(!xmlString)
1192 return E_INVALIDARG;
1194 *xmlString = NULL;
1196 pXmlBuf = xmlBufferCreate();
1197 if(pXmlBuf)
1199 nSize = xmlNodeDump(pXmlBuf, This->node->doc, This->node, 0, 1);
1200 if(nSize > 0)
1202 const xmlChar *pContent;
1203 BSTR bstrContent;
1205 /* Attribute Nodes return a space in front of their name */
1206 pContent = xmlBufferContent(pXmlBuf);
1207 if( ((char*)pContent)[0] == ' ')
1208 bstrContent = bstr_from_xmlChar(pContent+1);
1209 else
1210 bstrContent = bstr_from_xmlChar(pContent);
1212 switch(This->node->type)
1214 case XML_ELEMENT_NODE:
1215 *xmlString = EnsureCorrectEOL(bstrContent);
1216 break;
1217 case XML_DOCUMENT_NODE:
1218 *xmlString = EnsureCorrectEOL(bstrContent);
1219 *xmlString = EnsureNoEncoding(*xmlString);
1220 break;
1221 default:
1222 *xmlString = bstrContent;
1226 xmlBufferFree(pXmlBuf);
1229 /* Always returns a string. */
1230 if(*xmlString == NULL) *xmlString = SysAllocStringLen( NULL, 0 );
1232 return S_OK;
1235 static HRESULT WINAPI xmlnode_transformNode(
1236 IXMLDOMNode *iface,
1237 IXMLDOMNode* styleSheet,
1238 BSTR* xmlString)
1240 #ifdef SONAME_LIBXSLT
1241 xmlnode *This = impl_from_IXMLDOMNode( iface );
1242 xmlnode *pStyleSheet = NULL;
1243 xsltStylesheetPtr xsltSS = NULL;
1244 xmlDocPtr result = NULL;
1245 IXMLDOMNode *ssNew;
1247 TRACE("%p %p %p\n", This, styleSheet, xmlString);
1249 if (!libxslt_handle)
1250 return E_NOTIMPL;
1251 if(!styleSheet || !xmlString)
1252 return E_INVALIDARG;
1254 *xmlString = NULL;
1256 if(IXMLDOMNode_QueryInterface(styleSheet, &IID_IXMLDOMNode, (LPVOID)&ssNew) == S_OK)
1258 pStyleSheet = impl_from_IXMLDOMNode( ssNew );
1260 xsltSS = pxsltParseStylesheetDoc( pStyleSheet->node->doc);
1261 if(xsltSS)
1263 result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
1264 if(result)
1266 const xmlChar *pContent;
1268 if(result->type == XML_HTML_DOCUMENT_NODE)
1270 xmlOutputBufferPtr pOutput = xmlAllocOutputBuffer(NULL);
1271 if(pOutput)
1273 htmlDocContentDumpOutput(pOutput, result->doc, NULL);
1274 pContent = xmlBufferContent(pOutput->buffer);
1275 *xmlString = bstr_from_xmlChar(pContent);
1276 xmlOutputBufferClose(pOutput);
1279 else
1281 xmlBufferPtr pXmlBuf;
1282 int nSize;
1284 pXmlBuf = xmlBufferCreate();
1285 if(pXmlBuf)
1287 nSize = xmlNodeDump(pXmlBuf, NULL, (xmlNodePtr)result, 0, 0);
1288 if(nSize > 0)
1290 pContent = xmlBufferContent(pXmlBuf);
1291 *xmlString = bstr_from_xmlChar(pContent);
1293 xmlBufferFree(pXmlBuf);
1296 xmlFreeDoc(result);
1298 /* libxslt "helpfully" frees the XML document the stylesheet was
1299 generated from, too */
1300 xsltSS->doc = NULL;
1301 pxsltFreeStylesheet(xsltSS);
1304 IXMLDOMNode_Release(ssNew);
1307 if(*xmlString == NULL)
1308 *xmlString = SysAllocStringLen(NULL, 0);
1310 return S_OK;
1311 #else
1312 FIXME("libxslt headers were not found at compile time\n");
1313 return E_NOTIMPL;
1314 #endif
1317 static HRESULT WINAPI xmlnode_selectNodes(
1318 IXMLDOMNode *iface,
1319 BSTR queryString,
1320 IXMLDOMNodeList** resultList)
1322 xmlnode *This = impl_from_IXMLDOMNode( iface );
1324 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList );
1326 return queryresult_create( This->node, queryString, resultList );
1329 static HRESULT WINAPI xmlnode_selectSingleNode(
1330 IXMLDOMNode *iface,
1331 BSTR queryString,
1332 IXMLDOMNode** resultNode)
1334 xmlnode *This = impl_from_IXMLDOMNode( iface );
1335 IXMLDOMNodeList *list;
1336 HRESULT r;
1338 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode );
1340 *resultNode = NULL;
1341 r = IXMLDOMNode_selectNodes(iface, queryString, &list);
1342 if(r == S_OK)
1344 r = IXMLDOMNodeList_nextNode(list, resultNode);
1345 IXMLDOMNodeList_Release(list);
1347 return r;
1350 static HRESULT WINAPI xmlnode_get_parsed(
1351 IXMLDOMNode *iface,
1352 VARIANT_BOOL* isParsed)
1354 FIXME("\n");
1355 return E_NOTIMPL;
1358 static HRESULT WINAPI xmlnode_get_namespaceURI(
1359 IXMLDOMNode *iface,
1360 BSTR* namespaceURI)
1362 xmlnode *This = impl_from_IXMLDOMNode( iface );
1363 HRESULT hr = S_FALSE;
1364 xmlNsPtr *pNSList;
1366 TRACE("%p %p\n", This, namespaceURI );
1368 if(!namespaceURI)
1369 return E_INVALIDARG;
1371 *namespaceURI = NULL;
1373 pNSList = xmlGetNsList(This->node->doc, This->node);
1374 if(pNSList)
1376 *namespaceURI = bstr_from_xmlChar( pNSList[0]->href );
1378 xmlFree( pNSList );
1379 hr = S_OK;
1382 return hr;
1385 static HRESULT WINAPI xmlnode_get_prefix(
1386 IXMLDOMNode *iface,
1387 BSTR* prefixString)
1389 xmlnode *This = impl_from_IXMLDOMNode( iface );
1390 HRESULT hr = S_FALSE;
1391 xmlNsPtr *pNSList;
1393 TRACE("%p %p\n", This, prefixString );
1395 if(!prefixString)
1396 return E_INVALIDARG;
1398 *prefixString = NULL;
1400 pNSList = xmlGetNsList(This->node->doc, This->node);
1401 if(pNSList)
1403 *prefixString = bstr_from_xmlChar( pNSList[0]->prefix );
1405 xmlFree(pNSList);
1406 hr = S_OK;
1409 return hr;
1412 static HRESULT WINAPI xmlnode_get_baseName(
1413 IXMLDOMNode *iface,
1414 BSTR* nameString)
1416 xmlnode *This = impl_from_IXMLDOMNode( iface );
1417 BSTR str = NULL;
1418 HRESULT r = S_FALSE;
1420 TRACE("%p %p\n", This, nameString );
1422 if ( !nameString )
1423 return E_INVALIDARG;
1425 switch ( This->node->type )
1427 case XML_ELEMENT_NODE:
1428 case XML_ATTRIBUTE_NODE:
1429 str = bstr_from_xmlChar( This->node->name );
1430 r = S_OK;
1431 break;
1432 case XML_TEXT_NODE:
1433 break;
1434 default:
1435 ERR("Unhandled type %d\n", This->node->type );
1436 break;
1439 TRACE("returning %08x str = %s\n", r, debugstr_w( str ) );
1441 *nameString = str;
1442 return r;
1445 static HRESULT WINAPI xmlnode_transformNodeToObject(
1446 IXMLDOMNode *iface,
1447 IXMLDOMNode* stylesheet,
1448 VARIANT outputObject)
1450 FIXME("\n");
1451 return E_NOTIMPL;
1454 static const struct IXMLDOMNodeVtbl xmlnode_vtbl =
1456 xmlnode_QueryInterface,
1457 xmlnode_AddRef,
1458 xmlnode_Release,
1459 xmlnode_GetTypeInfoCount,
1460 xmlnode_GetTypeInfo,
1461 xmlnode_GetIDsOfNames,
1462 xmlnode_Invoke,
1463 xmlnode_get_nodeName,
1464 xmlnode_get_nodeValue,
1465 xmlnode_put_nodeValue,
1466 xmlnode_get_nodeType,
1467 xmlnode_get_parentNode,
1468 xmlnode_get_childNodes,
1469 xmlnode_get_firstChild,
1470 xmlnode_get_lastChild,
1471 xmlnode_get_previousSibling,
1472 xmlnode_get_nextSibling,
1473 xmlnode_get_attributes,
1474 xmlnode_insertBefore,
1475 xmlnode_replaceChild,
1476 xmlnode_removeChild,
1477 xmlnode_appendChild,
1478 xmlnode_hasChildNodes,
1479 xmlnode_get_ownerDocument,
1480 xmlnode_cloneNode,
1481 xmlnode_get_nodeTypeString,
1482 xmlnode_get_text,
1483 xmlnode_put_text,
1484 xmlnode_get_specified,
1485 xmlnode_get_definition,
1486 xmlnode_get_nodeTypedValue,
1487 xmlnode_put_nodeTypedValue,
1488 xmlnode_get_dataType,
1489 xmlnode_put_dataType,
1490 xmlnode_get_xml,
1491 xmlnode_transformNode,
1492 xmlnode_selectNodes,
1493 xmlnode_selectSingleNode,
1494 xmlnode_get_parsed,
1495 xmlnode_get_namespaceURI,
1496 xmlnode_get_prefix,
1497 xmlnode_get_baseName,
1498 xmlnode_transformNodeToObject,
1501 static HRESULT WINAPI Internal_QueryInterface(
1502 IUnknown *iface,
1503 REFIID riid,
1504 void** ppvObject )
1506 xmlnode *This = impl_from_InternalUnknown( iface );
1508 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
1511 if ( IsEqualGUID( riid, &IID_IUnknown ))
1512 *ppvObject = iface;
1513 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
1514 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
1515 *ppvObject = &This->lpVtbl;
1516 else
1518 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1519 *ppvObject = NULL;
1520 return E_NOINTERFACE;
1523 IUnknown_AddRef( (IUnknown*)*ppvObject );
1525 return S_OK;
1528 static ULONG WINAPI Internal_AddRef(
1529 IUnknown *iface )
1531 xmlnode *This = impl_from_InternalUnknown( iface );
1532 return InterlockedIncrement( &This->ref );
1535 static ULONG WINAPI Internal_Release(
1536 IUnknown *iface )
1538 xmlnode *This = impl_from_InternalUnknown( iface );
1539 ULONG ref;
1541 ref = InterlockedDecrement( &This->ref );
1542 if ( ref == 0 )
1544 if( This->node )
1545 xmldoc_release( This->node->doc );
1546 HeapFree( GetProcessHeap(), 0, This );
1549 return ref;
1552 static const struct IUnknownVtbl internal_unk_vtbl =
1554 Internal_QueryInterface,
1555 Internal_AddRef,
1556 Internal_Release
1559 IUnknown *create_basic_node( xmlNodePtr node, IUnknown *pUnkOuter )
1561 xmlnode *This;
1563 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
1564 if ( !This )
1565 return NULL;
1567 if(node)
1568 xmldoc_add_ref( node->doc );
1570 This->lpVtbl = &xmlnode_vtbl;
1571 This->lpInternalUnkVtbl = &internal_unk_vtbl;
1573 if(pUnkOuter)
1574 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
1575 else
1576 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
1578 This->ref = 1;
1579 This->node = node;
1581 return (IUnknown*)&This->lpInternalUnkVtbl;
1584 IXMLDOMNode *create_node( xmlNodePtr node )
1586 IUnknown *pUnk;
1587 IXMLDOMNode *ret;
1588 HRESULT hr;
1590 if ( !node )
1591 return NULL;
1593 TRACE("type %d\n", node->type);
1594 switch(node->type)
1596 case XML_ELEMENT_NODE:
1597 pUnk = create_element( node, NULL );
1598 break;
1599 case XML_ATTRIBUTE_NODE:
1600 pUnk = create_attribute( node );
1601 break;
1602 case XML_TEXT_NODE:
1603 pUnk = create_text( node );
1604 break;
1605 case XML_CDATA_SECTION_NODE:
1606 pUnk = create_cdata( node );
1607 break;
1608 case XML_COMMENT_NODE:
1609 pUnk = create_comment( node );
1610 break;
1611 case XML_DOCUMENT_NODE:
1612 pUnk = create_domdoc( node );
1613 break;
1614 default:
1615 FIXME("only creating basic node for type %d\n", node->type);
1616 pUnk = create_basic_node( node, NULL );
1619 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1620 IUnknown_Release(pUnk);
1621 if(FAILED(hr)) return NULL;
1622 return ret;
1624 #endif