jscript: Update Lithuanian translation.
[wine/multimedia.git] / dlls / msxml3 / node.c
blob987b07d2d09079a2fa84a86e0169fff130b9bae7
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 static HRESULT WINAPI xmlnode_get_nodeValue(
251 IXMLDOMNode *iface,
252 VARIANT* value)
254 xmlnode *This = impl_from_IXMLDOMNode( iface );
255 HRESULT r = S_FALSE;
257 TRACE("%p %p\n", This, value);
259 if(!value)
260 return E_INVALIDARG;
262 V_BSTR(value) = NULL;
263 V_VT(value) = VT_NULL;
265 switch ( This->node->type )
267 case XML_CDATA_SECTION_NODE:
268 case XML_COMMENT_NODE:
269 case XML_PI_NODE:
270 case XML_ATTRIBUTE_NODE:
272 xmlChar *content = xmlNodeGetContent(This->node);
273 V_VT(value) = VT_BSTR;
274 V_BSTR(value) = bstr_from_xmlChar( content );
275 xmlFree(content);
276 r = S_OK;
277 break;
279 case XML_TEXT_NODE:
280 V_VT(value) = VT_BSTR;
281 V_BSTR(value) = bstr_from_xmlChar( This->node->content );
282 r = S_OK;
283 break;
284 case XML_ELEMENT_NODE:
285 case XML_DOCUMENT_NODE:
286 /* these seem to return NULL */
287 break;
289 default:
290 FIXME("node %p type %d\n", This, This->node->type);
293 TRACE("%p returned %s\n", This, debugstr_w( V_BSTR(value) ) );
295 return r;
298 static HRESULT WINAPI xmlnode_put_nodeValue(
299 IXMLDOMNode *iface,
300 VARIANT value)
302 xmlnode *This = impl_from_IXMLDOMNode( iface );
303 HRESULT hr;
304 xmlChar *str = NULL;
305 VARIANT string_value;
307 TRACE("%p type(%d)\n", This, This->node->type);
309 VariantInit(&string_value);
310 hr = VariantChangeType(&string_value, &value, 0, VT_BSTR);
311 if(FAILED(hr))
313 VariantClear(&string_value);
314 WARN("Couldn't convert to VT_BSTR\n");
315 return hr;
318 hr = S_FALSE;
319 /* Document, Document Fragment, Document Type, Element,
320 Entity, Entity Reference, Notation aren't supported. */
321 switch ( This->node->type )
323 case XML_ATTRIBUTE_NODE:
324 case XML_CDATA_SECTION_NODE:
325 case XML_COMMENT_NODE:
326 case XML_PI_NODE:
327 case XML_TEXT_NODE:
329 str = xmlChar_from_wchar(V_BSTR(&string_value));
330 xmlNodeSetContent(This->node, str);
331 HeapFree(GetProcessHeap(),0,str);
332 hr = S_OK;
333 break;
335 default:
336 /* Do nothing for unsupported types. */
337 break;
340 VariantClear(&string_value);
342 return hr;
345 static HRESULT WINAPI xmlnode_get_nodeType(
346 IXMLDOMNode *iface,
347 DOMNodeType* type)
349 xmlnode *This = impl_from_IXMLDOMNode( iface );
351 TRACE("%p %p\n", This, type);
353 assert( (int)NODE_ELEMENT == (int)XML_ELEMENT_NODE );
354 assert( (int)NODE_NOTATION == (int)XML_NOTATION_NODE );
356 *type = This->node->type;
358 return S_OK;
361 static HRESULT get_node(
362 xmlnode *This,
363 const char *name,
364 xmlNodePtr node,
365 IXMLDOMNode **out )
367 TRACE("%p->%s %p\n", This, name, node );
369 if ( !out )
370 return E_INVALIDARG;
372 /* if we don't have a doc, use our parent. */
373 if(node && !node->doc && node->parent)
374 node->doc = node->parent->doc;
376 *out = create_node( node );
377 if (!*out)
378 return S_FALSE;
379 return S_OK;
382 static HRESULT WINAPI xmlnode_get_parentNode(
383 IXMLDOMNode *iface,
384 IXMLDOMNode** parent)
386 xmlnode *This = impl_from_IXMLDOMNode( iface );
387 return get_node( This, "parent", This->node->parent, parent );
390 static HRESULT WINAPI xmlnode_get_childNodes(
391 IXMLDOMNode *iface,
392 IXMLDOMNodeList** childList)
394 xmlnode *This = impl_from_IXMLDOMNode( iface );
396 TRACE("%p %p\n", This, childList );
398 if ( !childList )
399 return E_INVALIDARG;
401 *childList = create_children_nodelist(This->node);
402 if (*childList == NULL)
403 return E_OUTOFMEMORY;
405 return S_OK;
408 static HRESULT WINAPI xmlnode_get_firstChild(
409 IXMLDOMNode *iface,
410 IXMLDOMNode** firstChild)
412 xmlnode *This = impl_from_IXMLDOMNode( iface );
413 return get_node( This, "firstChild", This->node->children, firstChild );
416 static HRESULT WINAPI xmlnode_get_lastChild(
417 IXMLDOMNode *iface,
418 IXMLDOMNode** lastChild)
420 xmlnode *This = impl_from_IXMLDOMNode( iface );
422 TRACE("%p\n", This );
424 if (!lastChild)
425 return E_INVALIDARG;
427 switch( This->node->type )
429 /* CDATASection, Comment, PI and Text Nodes do not support lastChild */
430 case XML_TEXT_NODE:
431 case XML_CDATA_SECTION_NODE:
432 case XML_PI_NODE:
433 case XML_COMMENT_NODE:
434 *lastChild = NULL;
435 return S_FALSE;
436 default:
437 return get_node( This, "lastChild", This->node->last, lastChild );
441 static HRESULT WINAPI xmlnode_get_previousSibling(
442 IXMLDOMNode *iface,
443 IXMLDOMNode** previousSibling)
445 xmlnode *This = impl_from_IXMLDOMNode( iface );
447 TRACE("%p\n", This );
449 if (!previousSibling)
450 return E_INVALIDARG;
452 switch( This->node->type )
454 /* Attribute, Document and Document Fragment Nodes do not support previousSibling */
455 case XML_DOCUMENT_NODE:
456 case XML_DOCUMENT_FRAG_NODE:
457 case XML_ATTRIBUTE_NODE:
458 *previousSibling = NULL;
459 return S_FALSE;
460 default:
461 return get_node( This, "previous", This->node->prev, previousSibling );
465 static HRESULT WINAPI xmlnode_get_nextSibling(
466 IXMLDOMNode *iface,
467 IXMLDOMNode** nextSibling)
469 xmlnode *This = impl_from_IXMLDOMNode( iface );
471 TRACE("%p\n", This );
473 if (!nextSibling)
474 return E_INVALIDARG;
476 switch( This->node->type )
478 /* Attribute, Document and Document Fragment Nodes do not support nextSibling */
479 case XML_DOCUMENT_NODE:
480 case XML_DOCUMENT_FRAG_NODE:
481 case XML_ATTRIBUTE_NODE:
482 *nextSibling = NULL;
483 return S_FALSE;
484 default:
485 return get_node( This, "next", This->node->next, nextSibling );
489 static HRESULT WINAPI xmlnode_get_attributes(
490 IXMLDOMNode *iface,
491 IXMLDOMNamedNodeMap** attributeMap)
493 xmlnode *This = impl_from_IXMLDOMNode( iface );
494 TRACE("%p\n", This);
496 if (!attributeMap)
497 return E_INVALIDARG;
499 switch( This->node->type )
501 /* Attribute, CDataSection, Comment, Documents, Documents Fragments,
502 Entity and Text Nodes does not support get_attributes */
503 case XML_ATTRIBUTE_NODE:
504 case XML_CDATA_SECTION_NODE:
505 case XML_COMMENT_NODE:
506 case XML_DOCUMENT_NODE:
507 case XML_DOCUMENT_FRAG_NODE:
508 case XML_ENTITY_NODE:
509 case XML_ENTITY_REF_NODE:
510 case XML_TEXT_NODE:
511 *attributeMap = NULL;
512 return S_FALSE;
513 default:
514 *attributeMap = create_nodemap( iface );
515 return S_OK;
519 static HRESULT WINAPI xmlnode_insertBefore(
520 IXMLDOMNode *iface,
521 IXMLDOMNode* newChild,
522 VARIANT refChild,
523 IXMLDOMNode** outNewChild)
525 xmlnode *This = impl_from_IXMLDOMNode( iface );
526 xmlNodePtr before_node, new_child_node;
527 IXMLDOMNode *before = NULL, *new;
528 HRESULT hr;
530 TRACE("(%p)->(%p,var,%p)\n",This,newChild,outNewChild);
532 if (!newChild)
533 return E_INVALIDARG;
535 switch(V_VT(&refChild))
537 case VT_EMPTY:
538 case VT_NULL:
539 break;
541 case VT_UNKNOWN:
542 hr = IUnknown_QueryInterface(V_UNKNOWN(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
543 if(FAILED(hr)) return hr;
544 break;
546 case VT_DISPATCH:
547 hr = IDispatch_QueryInterface(V_DISPATCH(&refChild), &IID_IXMLDOMNode, (LPVOID)&before);
548 if(FAILED(hr)) return hr;
549 break;
551 default:
552 FIXME("refChild var type %x\n", V_VT(&refChild));
553 return E_FAIL;
556 IXMLDOMNode_QueryInterface(newChild, &IID_IXMLDOMNode, (LPVOID)&new);
557 new_child_node = impl_from_IXMLDOMNode(new)->node;
558 TRACE("new_child_node %p This->node %p\n", new_child_node, This->node);
560 if(!new_child_node->parent)
561 if(xmldoc_remove_orphan(new_child_node->doc, new_child_node) != S_OK)
562 WARN("%p is not an orphan of %p\n", new_child_node, new_child_node->doc);
564 if(before)
566 before_node = impl_from_IXMLDOMNode(before)->node;
567 xmlAddPrevSibling(before_node, new_child_node);
568 IXMLDOMNode_Release(before);
570 else
572 xmlAddChild(This->node, new_child_node);
575 IXMLDOMNode_Release(new);
576 IXMLDOMNode_AddRef(newChild);
577 if(outNewChild)
578 *outNewChild = newChild;
580 TRACE("ret S_OK\n");
581 return S_OK;
584 static HRESULT WINAPI xmlnode_replaceChild(
585 IXMLDOMNode *iface,
586 IXMLDOMNode* newChild,
587 IXMLDOMNode* oldChild,
588 IXMLDOMNode** outOldChild)
590 xmlnode *This = impl_from_IXMLDOMNode( iface );
591 xmlNode *old_child_ptr, *new_child_ptr;
592 xmlDocPtr leaving_doc;
593 xmlNode *my_ancestor;
594 IXMLDOMNode *realOldChild;
595 HRESULT hr;
597 TRACE("%p->(%p,%p,%p)\n",This,newChild,oldChild,outOldChild);
599 /* Do not believe any documentation telling that newChild == NULL
600 means removal. It does certainly *not* apply to msxml3! */
601 if(!newChild || !oldChild)
602 return E_INVALIDARG;
604 if(outOldChild)
605 *outOldChild = NULL;
607 hr = IXMLDOMNode_QueryInterface(oldChild,&IID_IXMLDOMNode,(LPVOID*)&realOldChild);
608 if(FAILED(hr))
609 return hr;
611 old_child_ptr = impl_from_IXMLDOMNode(realOldChild)->node;
612 IXMLDOMNode_Release(realOldChild);
613 if(old_child_ptr->parent != This->node)
615 WARN("childNode %p is not a child of %p\n", oldChild, iface);
616 return E_INVALIDARG;
619 new_child_ptr = impl_from_IXMLDOMNode(newChild)->node;
620 my_ancestor = This->node;
621 while(my_ancestor)
623 if(my_ancestor == new_child_ptr)
625 WARN("tried to create loop\n");
626 return E_FAIL;
628 my_ancestor = my_ancestor->parent;
631 if(!new_child_ptr->parent)
632 if(xmldoc_remove_orphan(new_child_ptr->doc, new_child_ptr) != S_OK)
633 WARN("%p is not an orphan of %p\n", new_child_ptr, new_child_ptr->doc);
635 leaving_doc = new_child_ptr->doc;
636 xmldoc_add_ref(old_child_ptr->doc);
637 xmlReplaceNode(old_child_ptr, new_child_ptr);
638 xmldoc_release(leaving_doc);
640 xmldoc_add_orphan(old_child_ptr->doc, old_child_ptr);
642 if(outOldChild)
644 IXMLDOMNode_AddRef(oldChild);
645 *outOldChild = oldChild;
648 return S_OK;
651 static HRESULT WINAPI xmlnode_removeChild(
652 IXMLDOMNode *iface,
653 IXMLDOMNode* childNode,
654 IXMLDOMNode** oldChild)
656 xmlnode *This = impl_from_IXMLDOMNode( iface );
657 xmlNode *child_node_ptr;
658 HRESULT hr;
659 IXMLDOMNode *child;
661 TRACE("%p->(%p, %p)\n", This, childNode, oldChild);
663 if(!childNode) return E_INVALIDARG;
665 if(oldChild)
666 *oldChild = NULL;
668 hr = IXMLDOMNode_QueryInterface(childNode, &IID_IXMLDOMNode, (LPVOID)&child);
669 if(FAILED(hr))
670 return hr;
672 child_node_ptr = impl_from_IXMLDOMNode(child)->node;
673 if(child_node_ptr->parent != This->node)
675 WARN("childNode %p is not a child of %p\n", childNode, iface);
676 IXMLDOMNode_Release(child);
677 return E_INVALIDARG;
680 xmlUnlinkNode(child_node_ptr);
682 IXMLDOMNode_Release(child);
684 if(oldChild)
686 IXMLDOMNode_AddRef(childNode);
687 *oldChild = childNode;
690 return S_OK;
693 static HRESULT WINAPI xmlnode_appendChild(
694 IXMLDOMNode *iface,
695 IXMLDOMNode* newChild,
696 IXMLDOMNode** outNewChild)
698 xmlnode *This = impl_from_IXMLDOMNode( iface );
699 DOMNodeType type;
700 VARIANT var;
701 HRESULT hr;
703 TRACE("(%p)->(%p,%p)\n", This, newChild, outNewChild);
705 hr = IXMLDOMNode_get_nodeType(newChild, &type);
706 if(FAILED(hr) || type == NODE_ATTRIBUTE) {
707 if(outNewChild) *outNewChild = NULL;
708 return E_FAIL;
711 VariantInit(&var);
712 return IXMLDOMNode_insertBefore(iface, newChild, var, outNewChild);
715 static HRESULT WINAPI xmlnode_hasChildNodes(
716 IXMLDOMNode *iface,
717 VARIANT_BOOL* hasChild)
719 xmlnode *This = impl_from_IXMLDOMNode( iface );
721 TRACE("%p\n", This);
723 if (!hasChild)
724 return E_INVALIDARG;
725 if (!This->node->children)
727 *hasChild = VARIANT_FALSE;
728 return S_FALSE;
731 *hasChild = VARIANT_TRUE;
732 return S_OK;
735 static HRESULT WINAPI xmlnode_get_ownerDocument(
736 IXMLDOMNode *iface,
737 IXMLDOMDocument** DOMDocument)
739 xmlnode *This = impl_from_IXMLDOMNode( iface );
741 TRACE("%p (%p)\n", This, DOMDocument);
743 return DOMDocument_create_from_xmldoc(This->node->doc, (IXMLDOMDocument2**)DOMDocument);
746 static HRESULT WINAPI xmlnode_cloneNode(
747 IXMLDOMNode *iface,
748 VARIANT_BOOL deep,
749 IXMLDOMNode** cloneRoot)
751 xmlnode *This = impl_from_IXMLDOMNode( iface );
752 xmlNodePtr pClone = NULL;
753 IXMLDOMNode *pNode = NULL;
755 TRACE("%p (%d)\n", This, deep);
757 if(!cloneRoot)
758 return E_INVALIDARG;
760 pClone = xmlCopyNode(This->node, deep ? 1 : 2);
761 if(pClone)
763 pClone->doc = This->node->doc;
764 xmldoc_add_orphan(pClone->doc, pClone);
766 pNode = create_node(pClone);
767 if(!pNode)
769 ERR("Copy failed\n");
770 return E_FAIL;
773 *cloneRoot = pNode;
775 else
777 ERR("Copy failed\n");
778 return E_FAIL;
781 return S_OK;
784 static HRESULT WINAPI xmlnode_get_nodeTypeString(
785 IXMLDOMNode *iface,
786 BSTR* xmlnodeType)
788 xmlnode *This = impl_from_IXMLDOMNode( iface );
789 const xmlChar *str;
791 TRACE("%p\n", This );
793 if (!xmlnodeType)
794 return E_INVALIDARG;
796 if ( !This->node )
797 return E_FAIL;
799 switch( This->node->type )
801 case XML_ATTRIBUTE_NODE:
802 str = (const xmlChar*) "attribute";
803 break;
804 case XML_CDATA_SECTION_NODE:
805 str = (const xmlChar*) "cdatasection";
806 break;
807 case XML_COMMENT_NODE:
808 str = (const xmlChar*) "comment";
809 break;
810 case XML_DOCUMENT_NODE:
811 str = (const xmlChar*) "document";
812 break;
813 case XML_DOCUMENT_FRAG_NODE:
814 str = (const xmlChar*) "documentfragment";
815 break;
816 case XML_ELEMENT_NODE:
817 str = (const xmlChar*) "element";
818 break;
819 case XML_ENTITY_NODE:
820 str = (const xmlChar*) "entity";
821 break;
822 case XML_ENTITY_REF_NODE:
823 str = (const xmlChar*) "entityreference";
824 break;
825 case XML_NOTATION_NODE:
826 str = (const xmlChar*) "notation";
827 break;
828 case XML_PI_NODE:
829 str = (const xmlChar*) "processinginstruction";
830 break;
831 case XML_TEXT_NODE:
832 str = (const xmlChar*) "text";
833 break;
834 default:
835 FIXME("Unknown node type (%d)\n", This->node->type);
836 str = This->node->name;
837 break;
840 *xmlnodeType = bstr_from_xmlChar( str );
841 if (!*xmlnodeType)
842 return S_FALSE;
844 return S_OK;
847 static HRESULT WINAPI xmlnode_get_text(
848 IXMLDOMNode *iface,
849 BSTR* text)
851 xmlnode *This = impl_from_IXMLDOMNode( iface );
852 BSTR str = NULL;
853 xmlChar *pContent;
855 TRACE("%p type %d\n", This, This->node->type);
857 if ( !text )
858 return E_INVALIDARG;
860 pContent = xmlNodeGetContent((xmlNodePtr)This->node);
861 if(pContent)
863 str = bstr_from_xmlChar(pContent);
864 xmlFree(pContent);
867 /* Always return a string. */
868 if (!str) str = SysAllocStringLen( NULL, 0 );
870 TRACE("%p %s\n", This, debugstr_w(str) );
871 *text = str;
873 return S_OK;
876 static HRESULT WINAPI xmlnode_put_text(
877 IXMLDOMNode *iface,
878 BSTR text)
880 xmlnode *This = impl_from_IXMLDOMNode( iface );
881 xmlChar *str, *str2;
883 TRACE("%p\n", This);
885 switch(This->node->type)
887 case XML_DOCUMENT_NODE:
888 return E_FAIL;
889 default:
890 break;
893 str = xmlChar_from_wchar(text);
895 /* Escape the string. */
896 str2 = xmlEncodeEntitiesReentrant(This->node->doc, str);
897 HeapFree(GetProcessHeap(), 0, str);
899 xmlNodeSetContent(This->node, str2);
900 xmlFree(str2);
902 return S_OK;
905 static HRESULT WINAPI xmlnode_get_specified(
906 IXMLDOMNode *iface,
907 VARIANT_BOOL* isSpecified)
909 FIXME("\n");
910 return E_NOTIMPL;
913 static HRESULT WINAPI xmlnode_get_definition(
914 IXMLDOMNode *iface,
915 IXMLDOMNode** definitionNode)
917 FIXME("\n");
918 return E_NOTIMPL;
921 static HRESULT WINAPI xmlnode_get_nodeTypedValue(
922 IXMLDOMNode *iface,
923 VARIANT* typedValue)
925 xmlnode *This = impl_from_IXMLDOMNode( iface );
926 HRESULT r = S_FALSE;
928 FIXME("ignoring data type %p %p\n", This, typedValue);
930 if(!typedValue)
931 return E_INVALIDARG;
933 V_VT(typedValue) = VT_NULL;
935 switch ( This->node->type )
937 case XML_ELEMENT_NODE:
939 xmlChar *content = xmlNodeGetContent(This->node);
940 V_VT(typedValue) = VT_BSTR;
941 V_BSTR(typedValue) = bstr_from_xmlChar( content );
942 xmlFree(content);
943 r = S_OK;
944 break;
946 default:
947 r = xmlnode_get_nodeValue(iface, typedValue);
950 return r;
953 static HRESULT WINAPI xmlnode_put_nodeTypedValue(
954 IXMLDOMNode *iface,
955 VARIANT typedValue)
957 FIXME("\n");
958 return E_NOTIMPL;
961 static HRESULT WINAPI xmlnode_get_dataType(
962 IXMLDOMNode *iface,
963 VARIANT* dataTypeName)
965 xmlnode *This = impl_from_IXMLDOMNode( iface );
966 xmlChar *pVal;
968 TRACE("iface %p\n", iface);
970 if(!dataTypeName)
971 return E_INVALIDARG;
973 /* Attribute, CDATA Section, Comment, Document, Document Fragment,
974 Entity, Notation, PI, and Text Node are non-typed. */
975 V_BSTR(dataTypeName) = NULL;
976 V_VT(dataTypeName) = VT_NULL;
978 switch ( This->node->type )
980 case XML_ELEMENT_NODE:
981 pVal = xmlGetNsProp(This->node, (xmlChar*)"dt",
982 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
983 if (pVal)
985 V_VT(dataTypeName) = VT_BSTR;
986 V_BSTR(dataTypeName) = bstr_from_xmlChar( pVal );
987 xmlFree(pVal);
989 break;
990 case XML_ENTITY_REF_NODE:
991 FIXME("XML_ENTITY_REF_NODE should return a valid value.\n");
992 break;
993 default:
994 TRACE("Type %d returning NULL\n", This->node->type);
997 /* non-typed nodes return S_FALSE */
998 if(V_VT(dataTypeName) == VT_NULL)
1000 return S_FALSE;
1003 return S_OK;
1006 static HRESULT WINAPI xmlnode_put_dataType(
1007 IXMLDOMNode *iface,
1008 BSTR dataTypeName)
1010 xmlnode *This = impl_from_IXMLDOMNode( iface );
1011 HRESULT hr = E_FAIL;
1013 TRACE("iface %p\n", iface);
1015 if(dataTypeName == NULL)
1016 return E_INVALIDARG;
1018 /* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
1019 This applies to changing types (string->bool) or setting a new one
1021 FIXME("Need to Validate the data before allowing a type to be set.\n");
1023 /* Check all supported types. */
1024 if(lstrcmpiW(dataTypeName,szString) == 0 ||
1025 lstrcmpiW(dataTypeName,szNumber) == 0 ||
1026 lstrcmpiW(dataTypeName,szUUID) == 0 ||
1027 lstrcmpiW(dataTypeName,szInt) == 0 ||
1028 lstrcmpiW(dataTypeName,szI4) == 0 ||
1029 lstrcmpiW(dataTypeName,szFixed) == 0 ||
1030 lstrcmpiW(dataTypeName,szBoolean) == 0 ||
1031 lstrcmpiW(dataTypeName,szDateTime) == 0 ||
1032 lstrcmpiW(dataTypeName,szDateTimeTZ) == 0 ||
1033 lstrcmpiW(dataTypeName,szDate) == 0 ||
1034 lstrcmpiW(dataTypeName,szTime) == 0 ||
1035 lstrcmpiW(dataTypeName,szTimeTZ) == 0 ||
1036 lstrcmpiW(dataTypeName,szI1) == 0 ||
1037 lstrcmpiW(dataTypeName,szI2) == 0 ||
1038 lstrcmpiW(dataTypeName,szIU1) == 0 ||
1039 lstrcmpiW(dataTypeName,szIU2) == 0 ||
1040 lstrcmpiW(dataTypeName,szIU4) == 0 ||
1041 lstrcmpiW(dataTypeName,szR4) == 0 ||
1042 lstrcmpiW(dataTypeName,szR8) == 0 ||
1043 lstrcmpiW(dataTypeName,szFloat) == 0 ||
1044 lstrcmpiW(dataTypeName,szBinHex) == 0 ||
1045 lstrcmpiW(dataTypeName,szBinBase64) == 0)
1047 xmlNsPtr pNS = NULL;
1048 xmlAttrPtr pAttr = NULL;
1049 xmlChar* str = xmlChar_from_wchar(dataTypeName);
1051 pAttr = xmlHasNsProp(This->node, (xmlChar*)"dt",
1052 (xmlChar*)"urn:schemas-microsoft-com:datatypes");
1053 if (pAttr)
1055 pAttr = xmlSetNsProp(This->node, pAttr->ns, (xmlChar*)"dt", str);
1057 hr = S_OK;
1059 else
1061 pNS = xmlNewNs(This->node, (xmlChar*)"urn:schemas-microsoft-com:datatypes", (xmlChar*)"dt");
1062 if(pNS)
1064 pAttr = xmlNewNsProp(This->node, pNS, (xmlChar*)"dt", str);
1065 if(pAttr)
1067 xmlAddChild(This->node, (xmlNodePtr)pAttr);
1069 hr = S_OK;
1071 else
1072 ERR("Failed to create Attribute\n");
1074 else
1075 ERR("Failed to Create Namepsace\n");
1077 HeapFree( GetProcessHeap(), 0, str );
1080 return hr;
1083 static BSTR EnsureCorrectEOL(BSTR sInput)
1085 static const WCHAR SZ_RETURN[] = {'\n',0};
1086 static const WCHAR SZ_LINEFEED[] = {'\r',0};
1087 int nNum = 0;
1088 BSTR sNew;
1089 int nLen;
1090 int i;
1092 nLen = lstrlenW(sInput);
1093 /* Count line endings */
1094 for(i=0; i < nLen; i++)
1096 if(sInput[i] == SZ_RETURN[0])
1097 nNum++;
1100 TRACE("len=%d, num=%d\n", nLen, nNum);
1102 /* Add linefeed as needed */
1103 if(nNum > 0)
1105 int nPlace = 0;
1106 sNew = SysAllocStringLen(NULL, nLen + nNum+1);
1107 for(i=0; i < nLen; i++)
1109 if(sInput[i] == SZ_RETURN[0])
1111 sNew[i+nPlace] = SZ_LINEFEED[0];
1112 nPlace++;
1114 sNew[i+nPlace] = sInput[i];
1117 SysFreeString(sInput);
1119 else
1121 sNew = sInput;
1124 TRACE("len %d\n", lstrlenW(sNew));
1126 return sNew;
1129 /* Removes encoding information and last character (nullbyte) */
1130 static BSTR EnsureNoEncoding(BSTR sInput)
1132 static const WCHAR wszEncoding[] = {'e','n','c','o','d','i','n','g','='};
1133 BSTR sNew;
1134 WCHAR *pBeg, *pEnd;
1136 pBeg = sInput;
1137 while(*pBeg != '\n' && memcmp(pBeg, wszEncoding, sizeof(wszEncoding)))
1138 pBeg++;
1140 if(*pBeg == '\n')
1142 SysReAllocStringLen(&sInput, sInput, SysStringLen(sInput)-1);
1143 return sInput;
1145 pBeg--;
1147 pEnd = pBeg + sizeof(wszEncoding)/sizeof(WCHAR) + 2;
1148 while(*pEnd != '\"') pEnd++;
1149 pEnd++;
1151 sNew = SysAllocStringLen(NULL,
1152 pBeg-sInput + SysStringLen(sInput)-(pEnd-sInput)-1);
1153 memcpy(sNew, sInput, (pBeg-sInput)*sizeof(WCHAR));
1154 memcpy(&sNew[pBeg-sInput], pEnd, (SysStringLen(sInput)-(pEnd-sInput)-1)*sizeof(WCHAR));
1156 SysFreeString(sInput);
1157 return sNew;
1161 * We are trying to replicate the same behaviour as msxml by converting
1162 * line endings to \r\n and using idents as \t. The problem is that msxml
1163 * only formats nodes that have a line ending. Using libxml we cannot
1164 * reproduce behaviour exactly.
1167 static HRESULT WINAPI xmlnode_get_xml(
1168 IXMLDOMNode *iface,
1169 BSTR* xmlString)
1171 xmlnode *This = impl_from_IXMLDOMNode( iface );
1172 xmlBufferPtr pXmlBuf;
1173 int nSize;
1175 TRACE("iface %p %d\n", iface, This->node->type);
1177 if(!xmlString)
1178 return E_INVALIDARG;
1180 *xmlString = NULL;
1182 pXmlBuf = xmlBufferCreate();
1183 if(pXmlBuf)
1185 nSize = xmlNodeDump(pXmlBuf, This->node->doc, This->node, 0, 1);
1186 if(nSize > 0)
1188 const xmlChar *pContent;
1189 BSTR bstrContent;
1191 /* Attribute Nodes return a space in front of their name */
1192 pContent = xmlBufferContent(pXmlBuf);
1193 if( ((char*)pContent)[0] == ' ')
1194 bstrContent = bstr_from_xmlChar(pContent+1);
1195 else
1196 bstrContent = bstr_from_xmlChar(pContent);
1198 switch(This->node->type)
1200 case XML_ELEMENT_NODE:
1201 *xmlString = EnsureCorrectEOL(bstrContent);
1202 break;
1203 case XML_DOCUMENT_NODE:
1204 *xmlString = EnsureCorrectEOL(bstrContent);
1205 *xmlString = EnsureNoEncoding(*xmlString);
1206 break;
1207 default:
1208 *xmlString = bstrContent;
1212 xmlBufferFree(pXmlBuf);
1215 /* Always returns a string. */
1216 if(*xmlString == NULL) *xmlString = SysAllocStringLen( NULL, 0 );
1218 return S_OK;
1221 static HRESULT WINAPI xmlnode_transformNode(
1222 IXMLDOMNode *iface,
1223 IXMLDOMNode* styleSheet,
1224 BSTR* xmlString)
1226 #ifdef SONAME_LIBXSLT
1227 xmlnode *This = impl_from_IXMLDOMNode( iface );
1228 xmlnode *pStyleSheet = NULL;
1229 xsltStylesheetPtr xsltSS = NULL;
1230 xmlDocPtr result = NULL;
1231 IXMLDOMNode *ssNew;
1233 TRACE("%p %p %p\n", This, styleSheet, xmlString);
1235 if (!libxslt_handle)
1236 return E_NOTIMPL;
1237 if(!styleSheet || !xmlString)
1238 return E_INVALIDARG;
1240 *xmlString = NULL;
1242 if(IXMLDOMNode_QueryInterface(styleSheet, &IID_IXMLDOMNode, (LPVOID)&ssNew) == S_OK)
1244 pStyleSheet = impl_from_IXMLDOMNode( ssNew );
1246 xsltSS = pxsltParseStylesheetDoc( pStyleSheet->node->doc);
1247 if(xsltSS)
1249 result = pxsltApplyStylesheet(xsltSS, This->node->doc, NULL);
1250 if(result)
1252 const xmlChar *pContent;
1254 if(result->type == XML_HTML_DOCUMENT_NODE)
1256 xmlOutputBufferPtr pOutput = xmlAllocOutputBuffer(NULL);
1257 if(pOutput)
1259 htmlDocContentDumpOutput(pOutput, result->doc, NULL);
1260 pContent = xmlBufferContent(pOutput->buffer);
1261 *xmlString = bstr_from_xmlChar(pContent);
1262 xmlOutputBufferClose(pOutput);
1265 else
1267 xmlBufferPtr pXmlBuf;
1268 int nSize;
1270 pXmlBuf = xmlBufferCreate();
1271 if(pXmlBuf)
1273 nSize = xmlNodeDump(pXmlBuf, NULL, (xmlNodePtr)result, 0, 0);
1274 if(nSize > 0)
1276 pContent = xmlBufferContent(pXmlBuf);
1277 *xmlString = bstr_from_xmlChar(pContent);
1279 xmlBufferFree(pXmlBuf);
1282 xmlFreeDoc(result);
1284 /* libxslt "helpfully" frees the XML document the stylesheet was
1285 generated from, too */
1286 xsltSS->doc = NULL;
1287 pxsltFreeStylesheet(xsltSS);
1290 IXMLDOMNode_Release(ssNew);
1293 if(*xmlString == NULL)
1294 *xmlString = SysAllocStringLen(NULL, 0);
1296 return S_OK;
1297 #else
1298 FIXME("libxslt headers were not found at compile time\n");
1299 return E_NOTIMPL;
1300 #endif
1303 static HRESULT WINAPI xmlnode_selectNodes(
1304 IXMLDOMNode *iface,
1305 BSTR queryString,
1306 IXMLDOMNodeList** resultList)
1308 xmlnode *This = impl_from_IXMLDOMNode( iface );
1310 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList );
1312 return queryresult_create( This->node, queryString, resultList );
1315 static HRESULT WINAPI xmlnode_selectSingleNode(
1316 IXMLDOMNode *iface,
1317 BSTR queryString,
1318 IXMLDOMNode** resultNode)
1320 xmlnode *This = impl_from_IXMLDOMNode( iface );
1321 IXMLDOMNodeList *list;
1322 HRESULT r;
1324 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode );
1326 *resultNode = NULL;
1327 r = IXMLDOMNode_selectNodes(iface, queryString, &list);
1328 if(r == S_OK)
1330 r = IXMLDOMNodeList_nextNode(list, resultNode);
1331 IXMLDOMNodeList_Release(list);
1333 return r;
1336 static HRESULT WINAPI xmlnode_get_parsed(
1337 IXMLDOMNode *iface,
1338 VARIANT_BOOL* isParsed)
1340 FIXME("\n");
1341 return E_NOTIMPL;
1344 static HRESULT WINAPI xmlnode_get_namespaceURI(
1345 IXMLDOMNode *iface,
1346 BSTR* namespaceURI)
1348 xmlnode *This = impl_from_IXMLDOMNode( iface );
1349 HRESULT hr = S_FALSE;
1350 xmlNsPtr *pNSList;
1352 TRACE("%p %p\n", This, namespaceURI );
1354 if(!namespaceURI)
1355 return E_INVALIDARG;
1357 *namespaceURI = NULL;
1359 pNSList = xmlGetNsList(This->node->doc, This->node);
1360 if(pNSList)
1362 *namespaceURI = bstr_from_xmlChar( pNSList[0]->href );
1364 xmlFree( pNSList );
1365 hr = S_OK;
1368 return hr;
1371 static HRESULT WINAPI xmlnode_get_prefix(
1372 IXMLDOMNode *iface,
1373 BSTR* prefixString)
1375 xmlnode *This = impl_from_IXMLDOMNode( iface );
1376 HRESULT hr = S_FALSE;
1377 xmlNsPtr *pNSList;
1379 TRACE("%p %p\n", This, prefixString );
1381 if(!prefixString)
1382 return E_INVALIDARG;
1384 *prefixString = NULL;
1386 pNSList = xmlGetNsList(This->node->doc, This->node);
1387 if(pNSList)
1389 *prefixString = bstr_from_xmlChar( pNSList[0]->prefix );
1391 xmlFree(pNSList);
1392 hr = S_OK;
1395 return hr;
1398 static HRESULT WINAPI xmlnode_get_baseName(
1399 IXMLDOMNode *iface,
1400 BSTR* nameString)
1402 xmlnode *This = impl_from_IXMLDOMNode( iface );
1403 BSTR str = NULL;
1404 HRESULT r = S_FALSE;
1406 TRACE("%p %p\n", This, nameString );
1408 if ( !nameString )
1409 return E_INVALIDARG;
1411 switch ( This->node->type )
1413 case XML_ELEMENT_NODE:
1414 case XML_ATTRIBUTE_NODE:
1415 str = bstr_from_xmlChar( This->node->name );
1416 r = S_OK;
1417 break;
1418 case XML_TEXT_NODE:
1419 break;
1420 default:
1421 ERR("Unhandled type %d\n", This->node->type );
1422 break;
1425 TRACE("returning %08x str = %s\n", r, debugstr_w( str ) );
1427 *nameString = str;
1428 return r;
1431 static HRESULT WINAPI xmlnode_transformNodeToObject(
1432 IXMLDOMNode *iface,
1433 IXMLDOMNode* stylesheet,
1434 VARIANT outputObject)
1436 FIXME("\n");
1437 return E_NOTIMPL;
1440 static const struct IXMLDOMNodeVtbl xmlnode_vtbl =
1442 xmlnode_QueryInterface,
1443 xmlnode_AddRef,
1444 xmlnode_Release,
1445 xmlnode_GetTypeInfoCount,
1446 xmlnode_GetTypeInfo,
1447 xmlnode_GetIDsOfNames,
1448 xmlnode_Invoke,
1449 xmlnode_get_nodeName,
1450 xmlnode_get_nodeValue,
1451 xmlnode_put_nodeValue,
1452 xmlnode_get_nodeType,
1453 xmlnode_get_parentNode,
1454 xmlnode_get_childNodes,
1455 xmlnode_get_firstChild,
1456 xmlnode_get_lastChild,
1457 xmlnode_get_previousSibling,
1458 xmlnode_get_nextSibling,
1459 xmlnode_get_attributes,
1460 xmlnode_insertBefore,
1461 xmlnode_replaceChild,
1462 xmlnode_removeChild,
1463 xmlnode_appendChild,
1464 xmlnode_hasChildNodes,
1465 xmlnode_get_ownerDocument,
1466 xmlnode_cloneNode,
1467 xmlnode_get_nodeTypeString,
1468 xmlnode_get_text,
1469 xmlnode_put_text,
1470 xmlnode_get_specified,
1471 xmlnode_get_definition,
1472 xmlnode_get_nodeTypedValue,
1473 xmlnode_put_nodeTypedValue,
1474 xmlnode_get_dataType,
1475 xmlnode_put_dataType,
1476 xmlnode_get_xml,
1477 xmlnode_transformNode,
1478 xmlnode_selectNodes,
1479 xmlnode_selectSingleNode,
1480 xmlnode_get_parsed,
1481 xmlnode_get_namespaceURI,
1482 xmlnode_get_prefix,
1483 xmlnode_get_baseName,
1484 xmlnode_transformNodeToObject,
1487 static HRESULT WINAPI Internal_QueryInterface(
1488 IUnknown *iface,
1489 REFIID riid,
1490 void** ppvObject )
1492 xmlnode *This = impl_from_InternalUnknown( iface );
1494 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
1497 if ( IsEqualGUID( riid, &IID_IUnknown ))
1498 *ppvObject = iface;
1499 else if ( IsEqualGUID( riid, &IID_IDispatch ) ||
1500 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
1501 *ppvObject = &This->lpVtbl;
1502 else
1504 FIXME("interface %s not implemented\n", debugstr_guid(riid));
1505 *ppvObject = NULL;
1506 return E_NOINTERFACE;
1509 IUnknown_AddRef( (IUnknown*)*ppvObject );
1511 return S_OK;
1514 static ULONG WINAPI Internal_AddRef(
1515 IUnknown *iface )
1517 xmlnode *This = impl_from_InternalUnknown( iface );
1518 return InterlockedIncrement( &This->ref );
1521 static ULONG WINAPI Internal_Release(
1522 IUnknown *iface )
1524 xmlnode *This = impl_from_InternalUnknown( iface );
1525 ULONG ref;
1527 ref = InterlockedDecrement( &This->ref );
1528 if ( ref == 0 )
1530 if( This->node )
1531 xmldoc_release( This->node->doc );
1532 HeapFree( GetProcessHeap(), 0, This );
1535 return ref;
1538 static const struct IUnknownVtbl internal_unk_vtbl =
1540 Internal_QueryInterface,
1541 Internal_AddRef,
1542 Internal_Release
1545 xmlnode *create_basic_node( xmlNodePtr node, IUnknown *pUnkOuter, dispex_static_data_t *dispex_data )
1547 xmlnode *This;
1549 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
1550 if ( !This )
1551 return NULL;
1553 if(node)
1554 xmldoc_add_ref( node->doc );
1556 This->lpVtbl = &xmlnode_vtbl;
1557 This->lpInternalUnkVtbl = &internal_unk_vtbl;
1559 if(pUnkOuter)
1560 This->pUnkOuter = pUnkOuter; /* Don't take a ref on outer Unknown */
1561 else
1562 This->pUnkOuter = (IUnknown *)&This->lpInternalUnkVtbl;
1564 if(dispex_data)
1565 init_dispex(&This->dispex, This->pUnkOuter, dispex_data);
1567 This->ref = 1;
1568 This->node = node;
1570 return This;
1573 IXMLDOMNode *create_node( xmlNodePtr node )
1575 IUnknown *pUnk;
1576 IXMLDOMNode *ret;
1577 HRESULT hr;
1579 if ( !node )
1580 return NULL;
1582 TRACE("type %d\n", node->type);
1583 switch(node->type)
1585 case XML_ELEMENT_NODE:
1586 pUnk = create_element( node );
1587 break;
1588 case XML_ATTRIBUTE_NODE:
1589 pUnk = create_attribute( node );
1590 break;
1591 case XML_TEXT_NODE:
1592 pUnk = create_text( node );
1593 break;
1594 case XML_CDATA_SECTION_NODE:
1595 pUnk = create_cdata( node );
1596 break;
1597 case XML_COMMENT_NODE:
1598 pUnk = create_comment( node );
1599 break;
1600 case XML_DOCUMENT_NODE:
1601 pUnk = create_domdoc( node );
1602 break;
1603 default:
1604 FIXME("only creating basic node for type %d\n", node->type);
1605 pUnk = (IUnknown*)&create_basic_node( node, NULL, NULL )->lpInternalUnkVtbl;
1608 hr = IUnknown_QueryInterface(pUnk, &IID_IXMLDOMNode, (LPVOID*)&ret);
1609 IUnknown_Release(pUnk);
1610 if(FAILED(hr)) return NULL;
1611 return ret;
1613 #endif