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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #include "msxml_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
42 typedef struct _xmlnode
44 const struct IXMLDOMNodeVtbl *lpVtbl;
49 static inline xmlnode *impl_from_IXMLDOMNode( IXMLDOMNode *iface )
51 return (xmlnode *)((char*)iface - FIELD_OFFSET(xmlnode, lpVtbl));
54 xmlNodePtr xmlNodePtr_from_domnode( IXMLDOMNode *iface, xmlElementType type )
60 This = impl_from_IXMLDOMNode( iface );
63 if ( type && This->node->type != type )
68 static HRESULT WINAPI xmlnode_QueryInterface(
73 TRACE("%p %s %p\n", iface, debugstr_guid(riid), ppvObject);
75 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
76 IsEqualGUID( riid, &IID_IDispatch ) ||
77 IsEqualGUID( riid, &IID_IXMLDOMNode ) )
84 IXMLDOMElement_AddRef( iface );
89 static ULONG WINAPI xmlnode_AddRef(
92 xmlnode *This = impl_from_IXMLDOMNode( iface );
93 return InterlockedIncrement( &This->ref );
96 static ULONG WINAPI xmlnode_Release(
99 xmlnode *This = impl_from_IXMLDOMNode( iface );
102 ref = InterlockedDecrement( &This->ref );
105 assert( This->node->doc );
106 xmldoc_release( This->node->doc );
107 HeapFree( GetProcessHeap(), 0, This );
113 static HRESULT WINAPI xmlnode_GetTypeInfoCount(
121 static HRESULT WINAPI xmlnode_GetTypeInfo(
125 ITypeInfo** ppTInfo )
131 static HRESULT WINAPI xmlnode_GetIDsOfNames(
143 static HRESULT WINAPI xmlnode_Invoke(
149 DISPPARAMS* pDispParams,
151 EXCEPINFO* pExcepInfo,
158 static HRESULT WINAPI xmlnode_get_nodeName(
162 xmlnode *This = impl_from_IXMLDOMNode( iface );
165 TRACE("%p\n", This );
173 switch( This->node->type )
176 str = (const xmlChar*) "#text";
178 case XML_DOCUMENT_NODE:
179 str = (const xmlChar*) "#document";
182 str = This->node->name;
186 *name = bstr_from_xmlChar( str );
193 BSTR bstr_from_xmlChar( const xmlChar *buf )
202 len = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) buf, -1, NULL, 0 );
203 str = (LPWSTR) HeapAlloc( GetProcessHeap(), 0, len * sizeof (WCHAR) );
206 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) buf, -1, str, len );
207 bstr = SysAllocString( str );
208 HeapFree( GetProcessHeap(), 0, str );
212 static HRESULT WINAPI xmlnode_get_nodeValue(
216 xmlnode *This = impl_from_IXMLDOMNode( iface );
219 TRACE("%p %p\n", This, value);
221 V_BSTR(value) = NULL;
222 V_VT(value) = VT_NULL;
224 switch ( This->node->type )
226 case XML_ATTRIBUTE_NODE:
227 V_VT(value) = VT_BSTR;
228 V_BSTR(value) = bstr_from_xmlChar( This->node->name );
232 V_VT(value) = VT_BSTR;
233 V_BSTR(value) = bstr_from_xmlChar( This->node->content );
236 case XML_ELEMENT_NODE:
237 case XML_DOCUMENT_NODE:
238 /* these seem to return NULL */
242 FIXME("node %p type %d\n", This, This->node->type);
245 TRACE("%p returned %s\n", This, debugstr_w( V_BSTR(value) ) );
250 static HRESULT WINAPI xmlnode_put_nodeValue(
258 static HRESULT WINAPI xmlnode_get_nodeType(
262 xmlnode *This = impl_from_IXMLDOMNode( iface );
264 TRACE("%p %p\n", This, type);
266 assert( NODE_ELEMENT == XML_ELEMENT_NODE );
267 assert( NODE_NOTATION == XML_NOTATION_NODE );
269 *type = This->node->type;
274 static HRESULT get_node(
280 TRACE("%p->%s %p\n", This, name, node );
284 *out = create_node( node );
290 static HRESULT WINAPI xmlnode_get_parentNode(
292 IXMLDOMNode** parent)
294 xmlnode *This = impl_from_IXMLDOMNode( iface );
295 return get_node( This, "parent", This->node->parent, parent );
298 static HRESULT WINAPI xmlnode_get_childNodes(
300 IXMLDOMNodeList** childList)
302 xmlnode *This = impl_from_IXMLDOMNode( iface );
304 TRACE("%p %p\n", This, childList );
309 switch(This->node->type)
311 case XML_ELEMENT_NODE:
312 *childList = create_filtered_nodelist( This->node->children, (const xmlChar *)"*" );
315 case XML_ATTRIBUTE_NODE:
316 *childList = create_filtered_nodelist( This->node->children, (const xmlChar *)"node()" );
320 FIXME("unhandled node type %d\n", This->node->type);
329 static HRESULT WINAPI xmlnode_get_firstChild(
331 IXMLDOMNode** firstChild)
333 xmlnode *This = impl_from_IXMLDOMNode( iface );
334 return get_node( This, "firstChild", This->node->children, firstChild );
337 static HRESULT WINAPI xmlnode_get_lastChild(
339 IXMLDOMNode** lastChild)
341 xmlnode *This = impl_from_IXMLDOMNode( iface );
342 return get_node( This, "lastChild", This->node->last, lastChild );
345 static HRESULT WINAPI xmlnode_get_previousSibling(
347 IXMLDOMNode** previousSibling)
349 xmlnode *This = impl_from_IXMLDOMNode( iface );
350 return get_node( This, "previous", This->node->prev, previousSibling );
353 static HRESULT WINAPI xmlnode_get_nextSibling(
355 IXMLDOMNode** nextSibling)
357 xmlnode *This = impl_from_IXMLDOMNode( iface );
358 return get_node( This, "next", This->node->next, nextSibling );
361 static HRESULT WINAPI xmlnode_get_attributes(
363 IXMLDOMNamedNodeMap** attributeMap)
365 xmlnode *This = impl_from_IXMLDOMNode( iface );
367 *attributeMap = create_nodemap( iface );
371 static HRESULT WINAPI xmlnode_insertBefore(
373 IXMLDOMNode* newChild,
375 IXMLDOMNode** outNewChild)
381 static HRESULT WINAPI xmlnode_replaceChild(
383 IXMLDOMNode* newChild,
384 IXMLDOMNode* oldChild,
385 IXMLDOMNode** outOldChild)
391 static HRESULT WINAPI xmlnode_removeChild(
393 IXMLDOMNode* childNode,
394 IXMLDOMNode** oldChild)
400 static HRESULT WINAPI xmlnode_appendChild(
402 IXMLDOMNode* newChild,
403 IXMLDOMNode** outNewChild)
409 static HRESULT WINAPI xmlnode_hasChildNodes(
411 VARIANT_BOOL* hasChild)
413 xmlnode *This = impl_from_IXMLDOMNode( iface );
419 if (!This->node->children)
421 *hasChild = VARIANT_FALSE;
425 *hasChild = VARIANT_TRUE;
429 static HRESULT WINAPI xmlnode_get_ownerDocument(
431 IXMLDOMDocument** DOMDocument)
437 static HRESULT WINAPI xmlnode_cloneNode(
440 IXMLDOMNode** cloneRoot)
446 static HRESULT WINAPI xmlnode_get_nodeTypeString(
454 static HRESULT WINAPI xmlnode_get_text(
458 xmlnode *This = impl_from_IXMLDOMNode( iface );
467 child = This->node->children;
468 if ( child && child->type == XML_TEXT_NODE )
469 str = bstr_from_xmlChar( child->content );
471 TRACE("%p %s\n", This, debugstr_w(str) );
477 static HRESULT WINAPI xmlnode_put_text(
485 static HRESULT WINAPI xmlnode_get_specified(
487 VARIANT_BOOL* isSpecified)
493 static HRESULT WINAPI xmlnode_get_definition(
495 IXMLDOMNode** definitionNode)
501 static HRESULT WINAPI xmlnode_get_nodeTypedValue(
509 static HRESULT WINAPI xmlnode_put_nodeTypedValue(
517 static HRESULT WINAPI xmlnode_get_dataType(
519 VARIANT* dataTypeName)
525 static HRESULT WINAPI xmlnode_put_dataType(
533 static HRESULT WINAPI xmlnode_get_xml(
541 static HRESULT WINAPI xmlnode_transformNode(
543 IXMLDOMNode* styleSheet,
550 static HRESULT WINAPI xmlnode_selectNodes(
553 IXMLDOMNodeList** resultList)
555 xmlnode *This = impl_from_IXMLDOMNode( iface );
559 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultList );
561 str = xmlChar_from_wchar( queryString );
565 *resultList = create_filtered_nodelist( This->node->children, str );
566 HeapFree( GetProcessHeap(), 0, str );
570 static HRESULT WINAPI xmlnode_selectSingleNode(
573 IXMLDOMNode** resultNode)
575 xmlnode *This = impl_from_IXMLDOMNode( iface );
576 IXMLDOMNodeList *list;
579 TRACE("%p %s %p\n", This, debugstr_w(queryString), resultNode );
581 r = IXMLDOMNode_selectNodes(iface, queryString, &list);
584 r = IXMLDOMNodeList_nextNode(list, resultNode);
585 IXMLDOMNodeList_Release(list);
590 static HRESULT WINAPI xmlnode_get_parsed(
592 VARIANT_BOOL* isParsed)
598 static HRESULT WINAPI xmlnode_get_namespaceURI(
606 static HRESULT WINAPI xmlnode_get_prefix(
614 static HRESULT WINAPI xmlnode_get_baseName(
618 xmlnode *This = impl_from_IXMLDOMNode( iface );
622 TRACE("%p %p\n", This, nameString );
627 switch ( This->node->type )
629 case XML_ELEMENT_NODE:
630 case XML_ATTRIBUTE_NODE:
631 str = bstr_from_xmlChar( This->node->name );
637 ERR("Unhandled type %d\n", This->node->type );
641 TRACE("returning %08lx str = %s\n", r, debugstr_w( str ) );
647 static HRESULT WINAPI xmlnode_transformNodeToObject(
649 IXMLDOMNode* stylesheet,
650 VARIANT outputObject)
656 static const struct IXMLDOMNodeVtbl xmlnode_vtbl =
658 xmlnode_QueryInterface,
661 xmlnode_GetTypeInfoCount,
663 xmlnode_GetIDsOfNames,
665 xmlnode_get_nodeName,
666 xmlnode_get_nodeValue,
667 xmlnode_put_nodeValue,
668 xmlnode_get_nodeType,
669 xmlnode_get_parentNode,
670 xmlnode_get_childNodes,
671 xmlnode_get_firstChild,
672 xmlnode_get_lastChild,
673 xmlnode_get_previousSibling,
674 xmlnode_get_nextSibling,
675 xmlnode_get_attributes,
676 xmlnode_insertBefore,
677 xmlnode_replaceChild,
680 xmlnode_hasChildNodes,
681 xmlnode_get_ownerDocument,
683 xmlnode_get_nodeTypeString,
686 xmlnode_get_specified,
687 xmlnode_get_definition,
688 xmlnode_get_nodeTypedValue,
689 xmlnode_put_nodeTypedValue,
690 xmlnode_get_dataType,
691 xmlnode_put_dataType,
693 xmlnode_transformNode,
695 xmlnode_selectSingleNode,
697 xmlnode_get_namespaceURI,
699 xmlnode_get_baseName,
700 xmlnode_transformNodeToObject,
703 IXMLDOMNode *create_node( xmlNodePtr node )
712 This = HeapAlloc( GetProcessHeap(), 0, sizeof *This );
716 if ( node->type == XML_DOCUMENT_NODE )
718 assert( node->doc == (xmlDocPtr) node );
719 node->doc->_private = 0;
722 xmldoc_add_ref( node->doc );
724 This->lpVtbl = &xmlnode_vtbl;
728 return (IXMLDOMNode*) &This->lpVtbl;