cmd: Fix German translation.
[wine/hramrach.git] / dlls / msxml3 / node.c
blob19fa4c592ce09839478aa3476ddbbc36937759c2
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(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( (int)NODE_ELEMENT == (int)XML_ELEMENT_NODE );
373 assert( (int)NODE_NOTATION == (int)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;
391 /* if we don't have a doc, use our parent. */
392 if(node && !node->doc && node->parent)
393 node->doc = node->parent->doc;
395 *out = create_node( node );
396 if (!*out)
397 return S_FALSE;
398 return S_OK;
401 static HRESULT WINAPI xmlnode_get_parentNode(
402 IXMLDOMNode *iface,
403 IXMLDOMNode** parent)
405 xmlnode *This = impl_from_IXMLDOMNode( iface );
406 return get_node( This, "parent", This->node->parent, parent );
409 static HRESULT WINAPI xmlnode_get_childNodes(
410 IXMLDOMNode *iface,
411 IXMLDOMNodeList** childList)
413 xmlnode *This = impl_from_IXMLDOMNode( iface );
415 TRACE("%p %p\n", This, childList );
417 if ( !childList )
418 return E_INVALIDARG;
420 *childList = create_children_nodelist(This->node);
421 if (*childList == NULL)
422 return E_OUTOFMEMORY;
424 return S_OK;
427 static HRESULT WINAPI xmlnode_get_firstChild(
428 IXMLDOMNode *iface,
429 IXMLDOMNode** firstChild)
431 xmlnode *This = impl_from_IXMLDOMNode( iface );
432 return get_node( This, "firstChild", This->node->children, firstChild );
435 static HRESULT WINAPI xmlnode_get_lastChild(
436 IXMLDOMNode *iface,
437 IXMLDOMNode** lastChild)
439 xmlnode *This = impl_from_IXMLDOMNode( iface );
441 TRACE("%p\n", This );
443 if (!lastChild)
444 return E_INVALIDARG;
446 switch( This->node->type )
448 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
449 case XML_TEXT_NODE:
450 case XML_CDATA_SECTION_NODE:
451 case XML_PI_NODE:
452 case XML_COMMENT_NODE:
453 *lastChild = NULL;
454 return S_FALSE;
455 default:
456 return get_node( This, "lastChild", This->node->last, lastChild );
460 static HRESULT WINAPI xmlnode_get_previousSibling(
461 IXMLDOMNode *iface,
462 IXMLDOMNode** previousSibling)
464 xmlnode *This = impl_from_IXMLDOMNode( iface );
466 TRACE("%p\n", This );
468 if (!previousSibling)
469 return E_INVALIDARG;
471 switch( This->node->type )
473 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
474 case XML_DOCUMENT_NODE:
475 case XML_DOCUMENT_FRAG_NODE:
476 case XML_ATTRIBUTE_NODE:
477 *previousSibling = NULL;
478 return S_FALSE;
479 default:
480 return get_node( This, "previous", This->node->prev, previousSibling );
484 static HRESULT WINAPI xmlnode_get_nextSibling(
485 IXMLDOMNode *iface,
486 IXMLDOMNode** nextSibling)
488 xmlnode *This = impl_from_IXMLDOMNode( iface );
490 TRACE("%p\n", This );
492 if (!nextSibling)
493 return E_INVALIDARG;
495 switch( This->node->type )
497 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
498 case XML_DOCUMENT_NODE:
499 case XML_DOCUMENT_FRAG_NODE:
500 case XML_ATTRIBUTE_NODE:
501 *nextSibling = NULL;
502 return S_FALSE;
503 default:
504 return get_node( This, "next", This->node->next, nextSibling );
508 static HRESULT WINAPI xmlnode_get_attributes(
509 IXMLDOMNode *iface,
510 IXMLDOMNamedNodeMap** attributeMap)
512 xmlnode *This = impl_from_IXMLDOMNode( iface );
513 TRACE("%p\n", This);
515 if (!attributeMap)
516 return E_INVALIDARG;
518 switch( This->node->type )
520 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
521 Entity and Text Nodes does not support get_attributes */
522 case XML_ATTRIBUTE_NODE:
523 case XML_CDATA_SECTION_NODE:
524 case XML_COMMENT_NODE:
525 case XML_DOCUMENT_NODE:
526 case XML_DOCUMENT_FRAG_NODE:
527 case XML_ENTITY_NODE:
528 case XML_ENTITY_REF_NODE:
529 case XML_TEXT_NODE:
530 *attributeMap = NULL;
531 return S_FALSE;
532 default:
533 *attributeMap = create_nodemap( iface );
534 return S_OK;
538 static HRESULT WINAPI xmlnode_insertBefore(
539 IXMLDOMNode *iface,
540 IXMLDOMNode* newChild,
541 VARIANT refChild,
542 IXMLDOMNode** outNewChild)
544 xmlnode *This = impl_from_IXMLDOMNode( iface );
545 xmlNodePtr before_node, new_child_node;
546 IXMLDOMNode *before = NULL, *new;
547 HRESULT hr;
549 TRACE("(%p)->(%p,var,%p)\n",This,newChild,outNewChild);
551 if (!newChild)
552 return E_INVALIDARG;
554 switch(V_VT(&refChild))
556 case VT_EMPTY:
557 case VT_NULL:
558 break;
560 case VT_UNKNOWN:
561 hr = IUnknown_QueryInterface(V_UNKNOWN(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
562 if(FAILED(hr)) return hr;
563 break;
565 case VT_DISPATCH:
566 hr = IDispatch_QueryInterface(V_DISPATCH(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
567 if(FAILED(hr)) return hr;
568 break;
570 default:
571 FIXME("refChild var type %x\n", V_VT(&refChild));
572 return E_FAIL;
575 IXMLDOMNode_QueryInterface(newChild, &IID_IXMLDOMNode, (LPVOID)&new);
576 new_child_node = impl_from_IXMLDOMNode(new)->node;
577 TRACE("new_child_node %p This->node %p\n", new_child_node, This->node);
579 if(!new_child_node->parent)
580 if(xmldoc_remove_orphan(new_child_node->doc, new_child_node) != S_OK)
581 WARN("%p is not an orphan of %p\n", new_child_node, new_child_node->doc);
583 if(before)
585 before_node = impl_from_IXMLDOMNode(before)->node;
586 xmlAddPrevSibling(before_node, new_child_node);
587 IXMLDOMNode_Release(before);
589 else
591 xmlAddChild(This->node, new_child_node);
594 IXMLDOMNode_Release(new);
595 IXMLDOMNode_AddRef(newChild);
596 if(outNewChild)
597 *outNewChild = newChild;
599 TRACE("ret S_OK\n");
600 return S_OK;
603 static HRESULT WINAPI xmlnode_replaceChild(
604 IXMLDOMNode *iface,
605 IXMLDOMNode* newChild,
606 IXMLDOMNode* oldChild,
607 IXMLDOMNode** outOldChild)
609 xmlnode *This = impl_from_IXMLDOMNode( iface );
610 xmlNode *old_child_ptr, *new_child_ptr;
611 xmlDocPtr leaving_doc;
612 xmlNode *my_ancestor;
613 IXMLDOMNode *realOldChild;
614 HRESULT hr;
616 TRACE("%p->(%p,%p,%p)\n",This,newChild,oldChild,outOldChild);
618 /* Do not believe any documentation telling that newChild == NULL
619 means removal. It does certainly *not* apply to msxml3! */
620 if(!newChild || !oldChild)
621 return E_INVALIDARG;
623 if(outOldChild)
624 *outOldChild = NULL;
626 hr = IXMLDOMNode_QueryInterface(oldChild,&IID_IXMLDOMNode,(LPVOID*)&realOldChild);
627 if(FAILED(hr))
628 return hr;
630 old_child_ptr = impl_from_IXMLDOMNode(realOldChild)->node;
631 IXMLDOMNode_Release(realOldChild);
632 if(old_child_ptr->parent != This->node)
634 WARN("childNode %p is not a child of %p\n", oldChild, iface);
635 return E_INVALIDARG;
638 new_child_ptr = impl_from_IXMLDOMNode(newChild)->node;
639 my_ancestor = This->node;
640 while(my_ancestor)
642 if(my_ancestor == new_child_ptr)
644 WARN("tried to create loop\n");
645 return E_FAIL;
647 my_ancestor = my_ancestor->parent;
650 if(!new_child_ptr->parent)
651 if(xmldoc_remove_orphan(new_child_ptr->doc, new_child_ptr) != S_OK)
652 WARN("%p is not an orphan of %p\n", new_child_ptr, new_child_ptr->doc);
654 leaving_doc = new_child_ptr->doc;
655 xmldoc_add_ref(old_child_ptr->doc);
656 xmlReplaceNode(old_child_ptr, new_child_ptr);
657 xmldoc_release(leaving_doc);
659 xmldoc_add_orphan(old_child_ptr->doc, old_child_ptr);
661 if(outOldChild)
663 IXMLDOMNode_AddRef(oldChild);
664 *outOldChild = oldChild;
667 return S_OK;
670 static HRESULT WINAPI xmlnode_removeChild(
671 IXMLDOMNode *iface,
672 IXMLDOMNode* childNode,
673 IXMLDOMNode** oldChild)
675 xmlnode *This = impl_from_IXMLDOMNode( iface );
676 xmlNode *child_node_ptr;
677 HRESULT hr;
678 IXMLDOMNode *child;
680 TRACE("%p->(%p, %p)\n", This, childNode, oldChild);
682 if(!childNode) return E_INVALIDARG;
684 if(oldChild)
685 *oldChild = NULL;
687 hr = IXMLDOMNode_QueryInterface(childNode, &IID_IXMLDOMNode, (LPVOID)&child);
688 if(FAILED(hr))
689 return hr;
691 child_node_ptr = impl_from_IXMLDOMNode(child)->node;
692 if(child_node_ptr->parent != This->node)
694 WARN("childNode %p is not a child of %p\n", childNode, iface);
695 IXMLDOMNode_Release(child);
696 return E_INVALIDARG;
699 xmlUnlinkNode(child_node_ptr);
701 IXMLDOMNode_Release(child);
703 if(oldChild)
705 IXMLDOMNode_AddRef(childNode);
706 *oldChild = childNode;
709 return S_OK;
712 static HRESULT WINAPI xmlnode_appendChild(
713 IXMLDOMNode *iface,
714 IXMLDOMNode* newChild,
715 IXMLDOMNode** outNewChild)
717 xmlnode *This = impl_from_IXMLDOMNode( iface );
718 DOMNodeType type;
719 VARIANT var;
720 HRESULT hr;
722 TRACE("(%p)->(%p,%p)\n", This, newChild, outNewChild);
724 hr = IXMLDOMNode_get_nodeType(newChild, &type);
725 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
726 if(outNewChild) *outNewChild = NULL;
727 return E_FAIL;
730 VariantInit(&var);
731 return IXMLDOMNode_insertBefore(iface, newChild, var, outNewChild);
734 static HRESULT WINAPI xmlnode_hasChildNodes(
735 IXMLDOMNode *iface,
736 VARIANT_BOOL* hasChild)
738 xmlnode *This = impl_from_IXMLDOMNode( iface );
740 TRACE("%p\n", This);
742 if (!hasChild)
743 return E_INVALIDARG;
744 if (!This->node->children)
746 *hasChild = VARIANT_FALSE;
747 return S_FALSE;
750 *hasChild = VARIANT_TRUE;
751 return S_OK;
754 static HRESULT WINAPI xmlnode_get_ownerDocument(
755 IXMLDOMNode *iface,
756 IXMLDOMDocument** DOMDocument)
758 xmlnode *This = impl_from_IXMLDOMNode( iface );
760 TRACE("%p (%p)\n", This, DOMDocument);
762 return DOMDocument_create_from_xmldoc(This->node->doc, (IXMLDOMDocument2**)DOMDocument);
765 static HRESULT WINAPI xmlnode_cloneNode(
766 IXMLDOMNode *iface,
767 VARIANT_BOOL deep,
768 IXMLDOMNode** cloneRoot)
770 xmlnode *This = impl_from_IXMLDOMNode( iface );
771 xmlNodePtr pClone = NULL;
772 IXMLDOMNode *pNode = NULL;
774 TRACE("%p (%d)\n", This, deep);
776 if(!cloneRoot)
777 return E_INVALIDARG;
779 pClone = xmlCopyNode(This->node, deep ? 1 : 2);
780 if(pClone)
782 pClone->doc = This->node->doc;
783 xmldoc_add_orphan(pClone->doc, pClone);
785 pNode = create_node(pClone);
786 if(!pNode)
788 ERR("Copy failed\n");
789 return E_FAIL;
792 *cloneRoot = pNode;
794 else
796 ERR("Copy failed\n");
797 return E_FAIL;
800 return S_OK;
803 static HRESULT WINAPI xmlnode_get_nodeTypeString(
804 IXMLDOMNode *iface,
805 BSTR* xmlnodeType)
807 xmlnode *This = impl_from_IXMLDOMNode( iface );
808 const xmlChar *str;
810 TRACE("%p\n", This );
812 if (!xmlnodeType)
813 return E_INVALIDARG;
815 if ( !This->node )
816 return E_FAIL;
818 switch( This->node->type )
820 case XML_ATTRIBUTE_NODE:
821 str = (const xmlChar*) "attribute";
822 break;
823 case XML_CDATA_SECTION_NODE:
824 str = (const xmlChar*) "cdatasection";
825 break;
826 case XML_COMMENT_NODE:
827 str = (const xmlChar*) "comment";
828 break;
829 case XML_DOCUMENT_NODE:
830 str = (const xmlChar*) "document";
831 break;
832 case XML_DOCUMENT_FRAG_NODE:
833 str = (const xmlChar*) "documentfragment";
834 break;
835 case XML_ELEMENT_NODE:
836 str = (const xmlChar*) "element";
837 break;
838 case XML_ENTITY_NODE:
839 str = (const xmlChar*) "entity";
840 break;
841 case XML_ENTITY_REF_NODE:
842 str = (const xmlChar*) "entityreference";
843 break;
844 case XML_NOTATION_NODE:
845 str = (const xmlChar*) "notation";
846 break;
847 case XML_PI_NODE:
848 str = (const xmlChar*) "processinginstruction";
849 break;
850 case XML_TEXT_NODE:
851 str = (const xmlChar*) "text";
852 break;
853 default:
854 FIXME("Unknown node type (%d)\n", This->node->type);
855 str = This->node->name;
856 break;
859 *xmlnodeType = bstr_from_xmlChar( str );
860 if (!*xmlnodeType)
861 return S_FALSE;
863 return S_OK;
866 static HRESULT WINAPI xmlnode_get_text(
867 IXMLDOMNode *iface,
868 BSTR* text)
870 xmlnode *This = impl_from_IXMLDOMNode( iface );
871 BSTR str = NULL;
872 xmlChar *pContent;
874 TRACE("%p type %d\n", This, This->node->type);
876 if ( !text )
877 return E_INVALIDARG;
879 pContent = xmlNodeGetContent((xmlNodePtr)This->node);
880 if(pContent)
882 str = bstr_from_xmlChar(pContent);
883 xmlFree(pContent);
886 /* Always return a string. */
887 if (!str) str = SysAllocStringLen( NULL, 0 );
889 TRACE("%p %s\n", This, debugstr_w(str) );
890 *text = str;
892 return S_OK;
895 static HRESULT WINAPI xmlnode_put_text(
896 IXMLDOMNode *iface,
897 BSTR text)
899 xmlnode *This = impl_from_IXMLDOMNode( iface );
900 xmlChar *str, *str2;
902 TRACE("%p\n", This);
904 switch(This->node->type)
906 case XML_DOCUMENT_NODE:
907 return E_FAIL;
908 default:
909 break;
912 str = xmlChar_from_wchar(text);
914 /* Escape the string. */
915 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
916 HeapFree(GetProcessHeap(), 0, str);
918 xmlNodeSetContent(This->node, str2);
919 xmlFree(str2);
921 return S_OK;
924 static HRESULT WINAPI xmlnode_get_specified(
925 IXMLDOMNode *iface,
926 VARIANT_BOOL* isSpecified)
928 FIXME("\n");
929 return E_NOTIMPL;
932 static HRESULT WINAPI xmlnode_get_definition(
933 IXMLDOMNode *iface,
934 IXMLDOMNode** definitionNode)
936 FIXME("\n");
937 return E_NOTIMPL;
940 static HRESULT WINAPI xmlnode_get_nodeTypedValue(
941 IXMLDOMNode *iface,
942 VARIANT* typedValue)
944 xmlnode *This = impl_from_IXMLDOMNode( iface );
945 HRESULT r = S_FALSE;
947 FIXME("ignoring data type %p %p\n", This, typedValue);
949 if(!typedValue)
950 return E_INVALIDARG;
952 V_VT(typedValue) = VT_NULL;
954 switch ( This->node->type )
956 case XML_ELEMENT_NODE:
958 xmlChar *content = xmlNodeGetContent(This->node);
959 V_VT(typedValue) = VT_BSTR;
960 V_BSTR(typedValue) = bstr_from_xmlChar( content );
961 xmlFree(content);
962 r = S_OK;
963 break;
965 default:
966 r = xmlnode_get_nodeValue(iface, typedValue);
969 return r;
972 static HRESULT WINAPI xmlnode_put_nodeTypedValue(
973 IXMLDOMNode *iface,
974 VARIANT typedValue)
976 FIXME("\n");
977 return E_NOTIMPL;
980 static HRESULT WINAPI xmlnode_get_dataType(
981 IXMLDOMNode *iface,
982 VARIANT* dataTypeName)
984 xmlnode *This = impl_from_IXMLDOMNode( iface );
985 xmlChar *pVal;
987 TRACE("iface %p\n", iface);
989 if(!dataTypeName)
990 return E_INVALIDARG;
992 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
993 Entity, Notation, PI, and Text Node are non-typed. */
994 V_BSTR(dataTypeName) = NULL;
995 V_VT(dataTypeName) = VT_NULL;
997 switch ( This->node->type )
999 case XML_ELEMENT_NODE:
1000 pVal = xmlGetNsProp(This->node, (xmlChar*)"dt",
1001 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1002 if (pVal)
1004 V_VT(dataTypeName) = VT_BSTR;
1005 V_BSTR(dataTypeName) = bstr_from_xmlChar( pVal );
1006 xmlFree(pVal);
1008 break;
1009 case XML_ENTITY_REF_NODE:
1010 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
1011 break;
1012 default:
1013 TRACE("Type %d returning NULL\n", This->node->type);
1016 /* non-typed nodes return S_FALSE */
1017 if(V_VT(dataTypeName) == VT_NULL)
1019 return S_FALSE;
1022 return S_OK;
1025 static HRESULT WINAPI xmlnode_put_dataType(
1026 IXMLDOMNode *iface,
1027 BSTR dataTypeName)
1029 xmlnode *This = impl_from_IXMLDOMNode( iface );
1030 HRESULT hr = E_FAIL;
1032 TRACE("iface %p\n", iface);
1034 if(dataTypeName == NULL)
1035 return E_INVALIDARG;
1037 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1038 This applies to changing types (string->bool) or setting a new one
1040 FIXME("Need to Validate the data before allowing a type to be set.\n");
1042 /* Check all supported types. */
1043 if(lstrcmpiW(dataTypeName,szString) == 0 ||
1044 lstrcmpiW(dataTypeName,szNumber) == 0 ||
1045 lstrcmpiW(dataTypeName,szUUID) == 0 ||
1046 lstrcmpiW(dataTypeName,szInt) == 0 ||
1047 lstrcmpiW(dataTypeName,szI4) == 0 ||
1048 lstrcmpiW(dataTypeName,szFixed) == 0 ||
1049 lstrcmpiW(dataTypeName,szBoolean) == 0 ||
1050 lstrcmpiW(dataTypeName,szDateTime) == 0 ||
1051 lstrcmpiW(dataTypeName,szDateTimeTZ) == 0 ||
1052 lstrcmpiW(dataTypeName,szDate) == 0 ||
1053 lstrcmpiW(dataTypeName,szTime) == 0 ||
1054 lstrcmpiW(dataTypeName,szTimeTZ) == 0 ||
1055 lstrcmpiW(dataTypeName,szI1) == 0 ||
1056 lstrcmpiW(dataTypeName,szI2) == 0 ||
1057 lstrcmpiW(dataTypeName,szIU1) == 0 ||
1058 lstrcmpiW(dataTypeName,szIU2) == 0 ||
1059 lstrcmpiW(dataTypeName,szIU4) == 0 ||
1060 lstrcmpiW(dataTypeName,szR4) == 0 ||
1061 lstrcmpiW(dataTypeName,szR8) == 0 ||
1062 lstrcmpiW(dataTypeName,szFloat) == 0 ||
1063 lstrcmpiW(dataTypeName,szBinHex) == 0 ||
1064 lstrcmpiW(dataTypeName,szBinBase64) == 0)
1066 xmlNsPtr pNS = NULL;
1067 xmlAttrPtr pAttr = NULL;
1068 xmlChar* str = xmlChar_from_wchar(dataTypeName);
1070 pAttr = xmlHasNsProp(This->node, (xmlChar*)"dt",
1071 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1072 if (pAttr)
1074 pAttr = xmlSetNsProp(This->node, pAttr->ns, (xmlChar*)"dt", str);
1076 hr = S_OK;
1078 else
1080 pNS = xmlNewNs(This->node, (xmlChar*)"urn:schemas-microsoft-com:datatypes", (xmlChar*)"dt");
1081 if(pNS)
1083 pAttr = xmlNewNsProp(This->node, pNS, (xmlChar*)"dt", str);
1084 if(pAttr)
1086 xmlAddChild(This->node, (xmlNodePtr)pAttr);
1088 hr = S_OK;
1090 else
1091 ERR("Failed to create Attribute\n");
1093 else
1094 ERR("Failed to Create Namepsace\n");
1096 HeapFree( GetProcessHeap(), 0, str );
1099 return hr;
1102 static BSTR EnsureCorrectEOL(BSTR sInput)
1104 static const WCHAR SZ_RETURN[] = {'\n',0};
1105 static const WCHAR SZ_LINEFEED[] = {'\r',0};
1106 int nNum = 0;
1107 BSTR sNew;
1108 int nLen;
1109 int i;
1111 nLen = lstrlenW(sInput);
1112 /* Count line endings */
1113 for(i=0; i < nLen; i++)
1115 if(sInput[i] == SZ_RETURN[0])
1116 nNum++;
1119 TRACE("len=%d, num=%d\n", nLen, nNum);
1121 /* Add linefeed as needed */
1122 if(nNum > 0)
1124 int nPlace = 0;
1125 sNew = SysAllocStringLen(NULL, nLen + nNum+1);
1126 for(i=0; i < nLen; i++)
1128 if(sInput[i] == SZ_RETURN[0])
1130 sNew[i+nPlace] = SZ_LINEFEED[0];
1131 nPlace++;
1133 sNew[i+nPlace] = sInput[i];
1136 SysFreeString(sInput);
1138 else
1140 sNew = sInput;
1143 TRACE("len %d\n", lstrlenW(sNew));
1145 return sNew;
1148 /* Removes encoding information and last character (nullbyte) */
1149 static BSTR EnsureNoEncoding(BSTR sInput)
1151 static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='};
1152 BSTR sNew;
1153 WCHAR *pBeg, *pEnd;
1155 pBeg = sInput;
1156 while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding)))
1157 pBeg++;
1159 if(*pBeg == '\n')
1161 SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1);
1162 return sInput;
1164 pBeg--;
1166 pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2;
1167 while(*pEnd != '\"') pEnd++;
1168 pEnd++;
1170 sNew = SysAllocStringLen(NULL,
1171 pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1);
1172 memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR));
1173 memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR));
1175 SysFreeString(sInput);
1176 return sNew;
1180 * We are trying to replicate the same behaviour as msxml by converting
1181 * line endings to \r\n and using idents as \t. The problem is that msxml
1182 * only formats nodes that have a line ending. Using libxml we cannot
1183 * reproduce behaviour exactly.
1186 static HRESULT WINAPI xmlnode_get_xml(
1187 IXMLDOMNode *iface,
1188 BSTR* xmlString)
1190 xmlnode *This = impl_from_IXMLDOMNode( iface );
1191 xmlBufferPtr pXmlBuf;
1192 int nSize;
1194 TRACE("iface %p %d\n", iface, This->node->type);
1196 if(!xmlString)
1197 return E_INVALIDARG;
1199 *xmlString = NULL;
1201 pXmlBuf = xmlBufferCreate();
1202 if(pXmlBuf)
1204 nSize = xmlNodeDump(pXmlBuf, This->node->doc, This->node, 0, 1);
1205 if(nSize > 0)
1207 const xmlChar *pContent;
1208 BSTR bstrContent;
1210 /* Attribute Nodes return a space in front of their name */
1211 pContent = xmlBufferContent(pXmlBuf);
1212 if( ((char*)pContent)[0] == ' ')
1213 bstrContent = bstr_from_xmlChar(pContent+1);
1214 else
1215 bstrContent = bstr_from_xmlChar(pContent);
1217 switch(This->node->type)
1219 case XML_ELEMENT_NODE:
1220 *xmlString = EnsureCorrectEOL(bstrContent);
1221 break;
1222 case XML_DOCUMENT_NODE:
1223 *xmlString = EnsureCorrectEOL(bstrContent);
1224 *xmlString = EnsureNoEncoding(*xmlString);
1225 break;
1226 default:
1227 *xmlString = bstrContent;
1231 xmlBufferFree(pXmlBuf);
1234 /* Always returns a string. */
1235 if(*xmlString == NULL) *xmlString = SysAllocStringLen( NULL, 0 );
1237 return S_OK;
1240 static HRESULT WINAPI xmlnode_transformNode(
1241 IXMLDOMNode *iface,
1242 IXMLDOMNode* styleSheet,
1243 BSTR* xmlString)
1245 #ifdef SONAME_LIBXSLT
1246 xmlnode *This = impl_from_IXMLDOMNode( iface );
1247 xmlnode *pStyleSheet = NULL;
1248 xsltStylesheetPtr xsltSS = NULL;
1249 xmlDocPtr result = NULL;
1250 IXMLDOMNode *ssNew;
1252 TRACE("%p %p %p\n", This, styleSheet, xmlString);
1254 if (!libxslt_handle)
1255 return E_NOTIMPL;
1256 if(!styleSheet || !xmlString)
1257 return E_INVALIDARG;
1259 *xmlString = NULL;
1261 if(IXMLDOMNode_QueryInterface(styleSheet, &IID_IXMLDOMNode, (LPVOID)&ssNew) == S_OK)
1263 pStyleSheet = impl_from_IXMLDOMNode( ssNew );
1265 xsltSS = pxsltParseStylesheetDoc( pStyleSheet->node->doc);
1266 if(xsltSS)
1268 result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
1269 if(result)
1271 const xmlChar *pContent;
1273 if(result->type == XML_HTML_DOCUMENT_NODE)
1275 xmlOutputBufferPtr pOutput = xmlAllocOutputBuffer(NULL);
1276 if(pOutput)
1278 htmlDocContentDumpOutput(pOutput, result->doc, NULL);
1279 pContent = xmlBufferContent(pOutput->buffer);
1280 *xmlString = bstr_from_xmlChar(pContent);
1281 xmlOutputBufferClose(pOutput);
1284 else
1286 xmlBufferPtr pXmlBuf;
1287 int nSize;
1289 pXmlBuf = xmlBufferCreate();
1290 if(pXmlBuf)
1292 nSize = xmlNodeDump(pXmlBuf, NULL, (xmlNodePtr)result, 0, 0);
1293 if(nSize > 0)
1295 pContent = xmlBufferContent(pXmlBuf);
1296 *xmlString = bstr_from_xmlChar(pContent);
1298 xmlBufferFree(pXmlBuf);
1301 xmlFreeDoc(result);
1303 /* libxslt "helpfully" frees the XML document the stylesheet was
1304 generated from, too */
1305 xsltSS->doc = NULL;
1306 pxsltFreeStylesheet(xsltSS);
1309 IXMLDOMNode_Release(ssNew);
1312 if(*xmlString == NULL)
1313 *xmlString = SysAllocStringLen(NULL, 0);
1315 return S_OK;
1316 #else
1317 FIXME("libxslt headers were not found at compile time\n");
1318 return E_NOTIMPL;
1319 #endif
1322 static HRESULT WINAPI xmlnode_selectNodes(
1323 IXMLDOMNode *iface,
1324 BSTR queryString,
1325 IXMLDOMNodeList** resultList)
1327 xmlnode *This = impl_from_IXMLDOMNode( iface );
1329 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList );
1331 return queryresult_create( This->node, queryString, resultList );
1334 static HRESULT WINAPI xmlnode_selectSingleNode(
1335 IXMLDOMNode *iface,
1336 BSTR queryString,
1337 IXMLDOMNode** resultNode)
1339 xmlnode *This = impl_from_IXMLDOMNode( iface );
1340 IXMLDOMNodeList *list;
1341 HRESULT r;
1343 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode );
1345 *resultNode = NULL;
1346 r = IXMLDOMNode_selectNodes(iface, queryString, &list);
1347 if(r == S_OK)
1349 r = IXMLDOMNodeList_nextNode(list, resultNode);
1350 IXMLDOMNodeList_Release(list);
1352 return r;
1355 static HRESULT WINAPI xmlnode_get_parsed(
1356 IXMLDOMNode *iface,
1357 VARIANT_BOOL* isParsed)
1359 FIXME("\n");
1360 return E_NOTIMPL;
1363 static HRESULT WINAPI xmlnode_get_namespaceURI(
1364 IXMLDOMNode *iface,
1365 BSTR* namespaceURI)
1367 xmlnode *This = impl_from_IXMLDOMNode( iface );
1368 HRESULT hr = S_FALSE;
1369 xmlNsPtr *pNSList;
1371 TRACE("%p %p\n", This, namespaceURI );
1373 if(!namespaceURI)
1374 return E_INVALIDARG;
1376 *namespaceURI = NULL;
1378 pNSList = xmlGetNsList(This->node->doc, This->node);
1379 if(pNSList)
1381 *namespaceURI = bstr_from_xmlChar( pNSList[0]->href );
1383 xmlFree( pNSList );
1384 hr = S_OK;
1387 return hr;
1390 static HRESULT WINAPI xmlnode_get_prefix(
1391 IXMLDOMNode *iface,
1392 BSTR* prefixString)
1394 xmlnode *This = impl_from_IXMLDOMNode( iface );
1395 HRESULT hr = S_FALSE;
1396 xmlNsPtr *pNSList;
1398 TRACE("%p %p\n", This, prefixString );
1400 if(!prefixString)
1401 return E_INVALIDARG;
1403 *prefixString = NULL;
1405 pNSList = xmlGetNsList(This->node->doc, This->node);
1406 if(pNSList)
1408 *prefixString = bstr_from_xmlChar( pNSList[0]->prefix );
1410 xmlFree(pNSList);
1411 hr = S_OK;
1414 return hr;
1417 static HRESULT WINAPI xmlnode_get_baseName(
1418 IXMLDOMNode *iface,
1419 BSTR* nameString)
1421 xmlnode *This = impl_from_IXMLDOMNode( iface );
1422 BSTR str = NULL;
1423 HRESULT r = S_FALSE;
1425 TRACE("%p %p\n", This, nameString );
1427 if ( !nameString )
1428 return E_INVALIDARG;
1430 switch ( This->node->type )
1432 case XML_ELEMENT_NODE:
1433 case XML_ATTRIBUTE_NODE:
1434 str = bstr_from_xmlChar( This->node->name );
1435 r = S_OK;
1436 break;
1437 case XML_TEXT_NODE:
1438 break;
1439 default:
1440 ERR("Unhandled type %d\n", This->node->type );
1441 break;
1444 TRACE("returning %08x str = %s\n", r, debugstr_w( str ) );
1446 *nameString = str;
1447 return r;
1450 static HRESULT WINAPI xmlnode_transformNodeToObject(
1451 IXMLDOMNode *iface,
1452 IXMLDOMNode* stylesheet,
1453 VARIANT outputObject)
1455 FIXME("\n");
1456 return E_NOTIMPL;
1459 static const struct IXMLDOMNodeVtbl xmlnode_vtbl =
1461 xmlnode_QueryInterface,
1462 xmlnode_AddRef,
1463 xmlnode_Release,
1464 xmlnode_GetTypeInfoCount,
1465 xmlnode_GetTypeInfo,
1466 xmlnode_GetIDsOfNames,
1467 xmlnode_Invoke,
1468 xmlnode_get_nodeName,
1469 xmlnode_get_nodeValue,
1470 xmlnode_put_nodeValue,
1471 xmlnode_get_nodeType,
1472 xmlnode_get_parentNode,
1473 xmlnode_get_childNodes,
1474 xmlnode_get_firstChild,
1475 xmlnode_get_lastChild,
1476 xmlnode_get_previousSibling,
1477 xmlnode_get_nextSibling,
1478 xmlnode_get_attributes,
1479 xmlnode_insertBefore,
1480 xmlnode_replaceChild,
1481 xmlnode_removeChild,
1482 xmlnode_appendChild,
1483 xmlnode_hasChildNodes,
1484 xmlnode_get_ownerDocument,
1485 xmlnode_cloneNode,
1486 xmlnode_get_nodeTypeString,
1487 xmlnode_get_text,
1488 xmlnode_put_text,
1489 xmlnode_get_specified,
1490 xmlnode_get_definition,
1491 xmlnode_get_nodeTypedValue,
1492 xmlnode_put_nodeTypedValue,
1493 xmlnode_get_dataType,
1494 xmlnode_put_dataType,
1495 xmlnode_get_xml,
1496 xmlnode_transformNode,
1497 xmlnode_selectNodes,
1498 xmlnode_selectSingleNode,
1499 xmlnode_get_parsed,
1500 xmlnode_get_namespaceURI,
1501 xmlnode_get_prefix,
1502 xmlnode_get_baseName,
1503 xmlnode_transformNodeToObject,
1506 static HRESULT WINAPI Internal_QueryInterface(
1507 IUnknown *iface,
1508 REFIID riid,
1509 void** ppvObject )
1511 xmlnode *This = impl_from_InternalUnknown( iface );
1513 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
1516 if ( IsEqualGUID( riid, &IID_IUnknown ))
1517 *ppvObject = iface;
1518 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
1519 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
1520 *ppvObject = &This->lpVtbl;
1521 else
1523 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1524 *ppvObject = NULL;
1525 return E_NOINTERFACE;
1528 IUnknown_AddRef( (IUnknown*)*ppvObject );
1530 return S_OK;
1533 static ULONG WINAPI Internal_AddRef(
1534 IUnknown *iface )
1536 xmlnode *This = impl_from_InternalUnknown( iface );
1537 return InterlockedIncrement( &This->ref );
1540 static ULONG WINAPI Internal_Release(
1541 IUnknown *iface )
1543 xmlnode *This = impl_from_InternalUnknown( iface );
1544 ULONG ref;
1546 ref = InterlockedDecrement( &This->ref );
1547 if ( ref == 0 )
1549 if( This->node )
1550 xmldoc_release( This->node->doc );
1551 HeapFree( GetProcessHeap(), 0, This );
1554 return ref;
1557 static const struct IUnknownVtbl internal_unk_vtbl =
1559 Internal_QueryInterface,
1560 Internal_AddRef,
1561 Internal_Release
1564 IUnknown *create_basic_node( xmlNodePtr node, IUnknown *pUnkOuter )
1566 xmlnode *This;
1568 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
1569 if ( !This )
1570 return NULL;
1572 if(node)
1573 xmldoc_add_ref( node->doc );
1575 This->lpVtbl = &xmlnode_vtbl;
1576 This->lpInternalUnkVtbl = &internal_unk_vtbl;
1578 if(pUnkOuter)
1579 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
1580 else
1581 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
1583 This->ref = 1;
1584 This->node = node;
1586 return (IUnknown*)&This->lpInternalUnkVtbl;
1589 IXMLDOMNode *create_node( xmlNodePtr node )
1591 IUnknown *pUnk;
1592 IXMLDOMNode *ret;
1593 HRESULT hr;
1595 if ( !node )
1596 return NULL;
1598 TRACE("type %d\n", node->type);
1599 switch(node->type)
1601 case XML_ELEMENT_NODE:
1602 pUnk = create_element( node, NULL );
1603 break;
1604 case XML_ATTRIBUTE_NODE:
1605 pUnk = create_attribute( node );
1606 break;
1607 case XML_TEXT_NODE:
1608 pUnk = create_text( node );
1609 break;
1610 case XML_CDATA_SECTION_NODE:
1611 pUnk = create_cdata( node );
1612 break;
1613 case XML_COMMENT_NODE:
1614 pUnk = create_comment( node );
1615 break;
1616 case XML_DOCUMENT_NODE:
1617 pUnk = create_domdoc( node );
1618 break;
1619 default:
1620 FIXME("only creating basic node for type %d\n", node->type);
1621 pUnk = create_basic_node( node, NULL );
1624 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1625 IUnknown_Release(pUnk);
1626 if(FAILED(hr)) return NULL;
1627 return ret;
1629 #endif