2 * DOM Document 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
38 #include "wine/debug.h"
40 #include "msxml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
47 const struct IBindStatusCallbackVtbl *lpVtbl;
50 static HRESULT WINAPI bsc_QueryInterface(
51 IBindStatusCallback *iface,
55 if (IsEqualGUID(riid, &IID_IUnknown) ||
56 IsEqualGUID(riid, &IID_IBindStatusCallback))
58 IBindStatusCallback_AddRef( iface );
63 FIXME("interface %s not implemented\n", debugstr_guid(riid));
67 static ULONG WINAPI bsc_AddRef(
68 IBindStatusCallback *iface )
73 static ULONG WINAPI bsc_Release(
74 IBindStatusCallback *iface )
79 static HRESULT WINAPI bsc_OnStartBinding(
80 IBindStatusCallback* iface,
87 static HRESULT WINAPI bsc_GetPriority(
88 IBindStatusCallback* iface,
94 static HRESULT WINAPI bsc_OnLowResource(
95 IBindStatusCallback* iface,
101 static HRESULT WINAPI bsc_OnProgress(
102 IBindStatusCallback* iface,
106 LPCWSTR szStatusText)
111 static HRESULT WINAPI bsc_OnStopBinding(
112 IBindStatusCallback* iface,
119 static HRESULT WINAPI bsc_GetBindInfo(
120 IBindStatusCallback* iface,
124 *grfBINDF = BINDF_RESYNCHRONIZE;
129 static HRESULT WINAPI bsc_OnDataAvailable(
130 IBindStatusCallback* iface,
133 FORMATETC* pformatetc,
139 static HRESULT WINAPI bsc_OnObjectAvailable(
140 IBindStatusCallback* iface,
147 const struct IBindStatusCallbackVtbl bsc_vtbl =
159 bsc_OnObjectAvailable
162 static bsc domdoc_bsc = { &bsc_vtbl };
164 typedef struct _domdoc
166 const struct IXMLDOMDocumentVtbl *lpVtbl;
174 LONG xmldoc_add_ref(xmlDocPtr doc)
176 LONG ref = InterlockedIncrement((LONG*)&doc->_private);
181 LONG xmldoc_release(xmlDocPtr doc)
183 LONG ref = InterlockedDecrement((LONG*)&doc->_private);
187 TRACE("freeing docptr %p\n", doc);
194 static inline domdoc *impl_from_IXMLDOMDocument( IXMLDOMDocument *iface )
196 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpVtbl));
199 static inline xmlDocPtr get_doc( domdoc *This )
201 return (xmlDocPtr) xmlNodePtr_from_domnode( This->node, XML_DOCUMENT_NODE );
204 static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument *iface, REFIID riid, void** ppvObject )
206 domdoc *This = impl_from_IXMLDOMDocument( iface );
208 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
210 if ( IsEqualGUID( riid, &IID_IXMLDOMDocument ) ||
211 IsEqualGUID( riid, &IID_IUnknown ) )
215 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
216 IsEqualGUID( riid, &IID_IDispatch ) )
218 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
222 FIXME("interface %s not implemented\n", debugstr_guid(riid));
223 return E_NOINTERFACE;
226 IXMLDOMDocument_AddRef( iface );
232 static ULONG WINAPI domdoc_AddRef(
233 IXMLDOMDocument *iface )
235 domdoc *This = impl_from_IXMLDOMDocument( iface );
236 TRACE("%p\n", This );
237 return InterlockedIncrement( &This->ref );
241 static ULONG WINAPI domdoc_Release(
242 IXMLDOMDocument *iface )
244 domdoc *This = impl_from_IXMLDOMDocument( iface );
247 TRACE("%p\n", This );
249 ref = InterlockedDecrement( &This->ref );
252 IUnknown_Release( This->node_unk );
253 HeapFree( GetProcessHeap(), 0, This );
259 static HRESULT WINAPI domdoc_GetTypeInfoCount( IXMLDOMDocument *iface, UINT* pctinfo )
265 static HRESULT WINAPI domdoc_GetTypeInfo(
266 IXMLDOMDocument *iface,
267 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
273 static HRESULT WINAPI domdoc_GetIDsOfNames(
274 IXMLDOMDocument *iface,
286 static HRESULT WINAPI domdoc_Invoke(
287 IXMLDOMDocument *iface,
292 DISPPARAMS* pDispParams,
294 EXCEPINFO* pExcepInfo,
302 static HRESULT WINAPI domdoc_get_nodeName(
303 IXMLDOMDocument *iface,
306 domdoc *This = impl_from_IXMLDOMDocument( iface );
307 return IXMLDOMNode_get_nodeName( This->node, name );
311 static HRESULT WINAPI domdoc_get_nodeValue(
312 IXMLDOMDocument *iface,
315 domdoc *This = impl_from_IXMLDOMDocument( iface );
316 return IXMLDOMNode_get_nodeValue( This->node, value );
320 static HRESULT WINAPI domdoc_put_nodeValue(
321 IXMLDOMDocument *iface,
324 domdoc *This = impl_from_IXMLDOMDocument( iface );
325 return IXMLDOMNode_put_nodeValue( This->node, value );
329 static HRESULT WINAPI domdoc_get_nodeType(
330 IXMLDOMDocument *iface,
333 domdoc *This = impl_from_IXMLDOMDocument( iface );
334 return IXMLDOMNode_get_nodeType( This->node, type );
338 static HRESULT WINAPI domdoc_get_parentNode(
339 IXMLDOMDocument *iface,
340 IXMLDOMNode** parent )
342 domdoc *This = impl_from_IXMLDOMDocument( iface );
343 return IXMLDOMNode_get_parentNode( This->node, parent );
347 static HRESULT WINAPI domdoc_get_childNodes(
348 IXMLDOMDocument *iface,
349 IXMLDOMNodeList** childList )
351 domdoc *This = impl_from_IXMLDOMDocument( iface );
352 return IXMLDOMNode_get_childNodes( This->node, childList );
356 static HRESULT WINAPI domdoc_get_firstChild(
357 IXMLDOMDocument *iface,
358 IXMLDOMNode** firstChild )
360 domdoc *This = impl_from_IXMLDOMDocument( iface );
361 return IXMLDOMNode_get_firstChild( This->node, firstChild );
365 static HRESULT WINAPI domdoc_get_lastChild(
366 IXMLDOMDocument *iface,
367 IXMLDOMNode** lastChild )
369 domdoc *This = impl_from_IXMLDOMDocument( iface );
370 return IXMLDOMNode_get_lastChild( This->node, lastChild );
374 static HRESULT WINAPI domdoc_get_previousSibling(
375 IXMLDOMDocument *iface,
376 IXMLDOMNode** previousSibling )
378 domdoc *This = impl_from_IXMLDOMDocument( iface );
379 return IXMLDOMNode_get_previousSibling( This->node, previousSibling );
383 static HRESULT WINAPI domdoc_get_nextSibling(
384 IXMLDOMDocument *iface,
385 IXMLDOMNode** nextSibling )
387 domdoc *This = impl_from_IXMLDOMDocument( iface );
388 return IXMLDOMNode_get_nextSibling( This->node, nextSibling );
392 static HRESULT WINAPI domdoc_get_attributes(
393 IXMLDOMDocument *iface,
394 IXMLDOMNamedNodeMap** attributeMap )
396 domdoc *This = impl_from_IXMLDOMDocument( iface );
397 return IXMLDOMNode_get_attributes( This->node, attributeMap );
401 static HRESULT WINAPI domdoc_insertBefore(
402 IXMLDOMDocument *iface,
403 IXMLDOMNode* newChild,
405 IXMLDOMNode** outNewChild )
407 domdoc *This = impl_from_IXMLDOMDocument( iface );
408 return IXMLDOMNode_insertBefore( This->node, newChild, refChild, outNewChild );
412 static HRESULT WINAPI domdoc_replaceChild(
413 IXMLDOMDocument *iface,
414 IXMLDOMNode* newChild,
415 IXMLDOMNode* oldChild,
416 IXMLDOMNode** outOldChild)
418 domdoc *This = impl_from_IXMLDOMDocument( iface );
419 return IXMLDOMNode_replaceChild( This->node, newChild, oldChild, outOldChild );
423 static HRESULT WINAPI domdoc_removeChild(
424 IXMLDOMDocument *iface,
425 IXMLDOMNode* childNode,
426 IXMLDOMNode** oldChild)
428 domdoc *This = impl_from_IXMLDOMDocument( iface );
429 return IXMLDOMNode_removeChild( This->node, childNode, oldChild );
433 static HRESULT WINAPI domdoc_appendChild(
434 IXMLDOMDocument *iface,
435 IXMLDOMNode* newChild,
436 IXMLDOMNode** outNewChild)
438 domdoc *This = impl_from_IXMLDOMDocument( iface );
439 return IXMLDOMNode_appendChild( This->node, newChild, outNewChild );
443 static HRESULT WINAPI domdoc_hasChildNodes(
444 IXMLDOMDocument *iface,
445 VARIANT_BOOL* hasChild)
447 domdoc *This = impl_from_IXMLDOMDocument( iface );
448 return IXMLDOMNode_hasChildNodes( This->node, hasChild );
452 static HRESULT WINAPI domdoc_get_ownerDocument(
453 IXMLDOMDocument *iface,
454 IXMLDOMDocument** DOMDocument)
456 domdoc *This = impl_from_IXMLDOMDocument( iface );
457 return IXMLDOMNode_get_ownerDocument( This->node, DOMDocument );
461 static HRESULT WINAPI domdoc_cloneNode(
462 IXMLDOMDocument *iface,
464 IXMLDOMNode** cloneRoot)
466 domdoc *This = impl_from_IXMLDOMDocument( iface );
467 return IXMLDOMNode_cloneNode( This->node, deep, cloneRoot );
471 static HRESULT WINAPI domdoc_get_nodeTypeString(
472 IXMLDOMDocument *iface,
475 domdoc *This = impl_from_IXMLDOMDocument( iface );
476 return IXMLDOMNode_get_nodeTypeString( This->node, nodeType );
480 static HRESULT WINAPI domdoc_get_text(
481 IXMLDOMDocument *iface,
484 domdoc *This = impl_from_IXMLDOMDocument( iface );
485 return IXMLDOMNode_get_text( This->node, text );
489 static HRESULT WINAPI domdoc_put_text(
490 IXMLDOMDocument *iface,
493 domdoc *This = impl_from_IXMLDOMDocument( iface );
494 return IXMLDOMNode_put_text( This->node, text );
498 static HRESULT WINAPI domdoc_get_specified(
499 IXMLDOMDocument *iface,
500 VARIANT_BOOL* isSpecified )
502 domdoc *This = impl_from_IXMLDOMDocument( iface );
503 return IXMLDOMNode_get_specified( This->node, isSpecified );
507 static HRESULT WINAPI domdoc_get_definition(
508 IXMLDOMDocument *iface,
509 IXMLDOMNode** definitionNode )
511 domdoc *This = impl_from_IXMLDOMDocument( iface );
512 return IXMLDOMNode_get_definition( This->node, definitionNode );
516 static HRESULT WINAPI domdoc_get_nodeTypedValue(
517 IXMLDOMDocument *iface,
518 VARIANT* typedValue )
520 domdoc *This = impl_from_IXMLDOMDocument( iface );
521 return IXMLDOMNode_get_nodeTypedValue( This->node, typedValue );
524 static HRESULT WINAPI domdoc_put_nodeTypedValue(
525 IXMLDOMDocument *iface,
528 domdoc *This = impl_from_IXMLDOMDocument( iface );
529 return IXMLDOMNode_put_nodeTypedValue( This->node, typedValue );
533 static HRESULT WINAPI domdoc_get_dataType(
534 IXMLDOMDocument *iface,
535 VARIANT* dataTypeName )
537 domdoc *This = impl_from_IXMLDOMDocument( iface );
538 return IXMLDOMNode_get_dataType( This->node, dataTypeName );
542 static HRESULT WINAPI domdoc_put_dataType(
543 IXMLDOMDocument *iface,
546 domdoc *This = impl_from_IXMLDOMDocument( iface );
547 return IXMLDOMNode_put_dataType( This->node, dataTypeName );
551 static HRESULT WINAPI domdoc_get_xml(
552 IXMLDOMDocument *iface,
555 domdoc *This = impl_from_IXMLDOMDocument( iface );
556 return IXMLDOMNode_get_xml( This->node, xmlString );
560 static HRESULT WINAPI domdoc_transformNode(
561 IXMLDOMDocument *iface,
562 IXMLDOMNode* styleSheet,
565 domdoc *This = impl_from_IXMLDOMDocument( iface );
566 return IXMLDOMNode_transformNode( This->node, styleSheet, xmlString );
570 static HRESULT WINAPI domdoc_selectNodes(
571 IXMLDOMDocument *iface,
573 IXMLDOMNodeList** resultList )
575 domdoc *This = impl_from_IXMLDOMDocument( iface );
576 return IXMLDOMNode_selectNodes( This->node, queryString, resultList );
580 static HRESULT WINAPI domdoc_selectSingleNode(
581 IXMLDOMDocument *iface,
583 IXMLDOMNode** resultNode )
585 domdoc *This = impl_from_IXMLDOMDocument( iface );
586 return IXMLDOMNode_selectSingleNode( This->node, queryString, resultNode );
590 static HRESULT WINAPI domdoc_get_parsed(
591 IXMLDOMDocument *iface,
592 VARIANT_BOOL* isParsed )
594 domdoc *This = impl_from_IXMLDOMDocument( iface );
595 return IXMLDOMNode_get_parsed( This->node, isParsed );
599 static HRESULT WINAPI domdoc_get_namespaceURI(
600 IXMLDOMDocument *iface,
603 domdoc *This = impl_from_IXMLDOMDocument( iface );
604 return IXMLDOMNode_get_namespaceURI( This->node, namespaceURI );
608 static HRESULT WINAPI domdoc_get_prefix(
609 IXMLDOMDocument *iface,
612 domdoc *This = impl_from_IXMLDOMDocument( iface );
613 return IXMLDOMNode_get_prefix( This->node, prefixString );
617 static HRESULT WINAPI domdoc_get_baseName(
618 IXMLDOMDocument *iface,
621 domdoc *This = impl_from_IXMLDOMDocument( iface );
622 return IXMLDOMNode_get_baseName( This->node, nameString );
626 static HRESULT WINAPI domdoc_transformNodeToObject(
627 IXMLDOMDocument *iface,
628 IXMLDOMNode* stylesheet,
629 VARIANT outputObject)
631 domdoc *This = impl_from_IXMLDOMDocument( iface );
632 return IXMLDOMNode_transformNodeToObject( This->node, stylesheet, outputObject );
636 static HRESULT WINAPI domdoc_get_doctype(
637 IXMLDOMDocument *iface,
638 IXMLDOMDocumentType** documentType )
645 static HRESULT WINAPI domdoc_get_implementation(
646 IXMLDOMDocument *iface,
647 IXMLDOMImplementation** impl )
653 static HRESULT WINAPI domdoc_get_documentElement(
654 IXMLDOMDocument *iface,
655 IXMLDOMElement** DOMElement )
657 domdoc *This = impl_from_IXMLDOMDocument( iface );
658 xmlDocPtr xmldoc = NULL;
659 xmlNodePtr root = NULL;
660 IXMLDOMNode *element_node;
667 xmldoc = get_doc( This );
669 root = xmlDocGetRootElement( xmldoc );
673 element_node = create_node( root );
674 if(!element_node) return S_FALSE;
676 hr = IXMLDOMNode_QueryInterface(element_node, &IID_IXMLDOMElement, (LPVOID*)DOMElement);
677 IXMLDOMNode_Release(element_node);
683 static HRESULT WINAPI domdoc_documentElement(
684 IXMLDOMDocument *iface,
685 IXMLDOMElement* DOMElement )
692 static HRESULT WINAPI domdoc_createElement(
693 IXMLDOMDocument *iface,
695 IXMLDOMElement** element )
702 static HRESULT WINAPI domdoc_createDocumentFragment(
703 IXMLDOMDocument *iface,
704 IXMLDOMDocumentFragment** docFrag )
711 static HRESULT WINAPI domdoc_createTextNode(
712 IXMLDOMDocument *iface,
721 static HRESULT WINAPI domdoc_createComment(
722 IXMLDOMDocument *iface,
724 IXMLDOMComment** comment )
731 static HRESULT WINAPI domdoc_createCDATASection(
732 IXMLDOMDocument *iface,
734 IXMLDOMCDATASection** cdata )
741 static HRESULT WINAPI domdoc_createProcessingInstruction(
742 IXMLDOMDocument *iface,
745 IXMLDOMProcessingInstruction** pi )
752 static HRESULT WINAPI domdoc_createAttribute(
753 IXMLDOMDocument *iface,
755 IXMLDOMAttribute** attribute )
762 static HRESULT WINAPI domdoc_createEntityReference(
763 IXMLDOMDocument *iface,
765 IXMLDOMEntityReference** entityRef )
772 static HRESULT WINAPI domdoc_getElementsByTagName(
773 IXMLDOMDocument *iface,
775 IXMLDOMNodeList** resultList )
777 domdoc *This = impl_from_IXMLDOMDocument( iface );
779 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
781 name = xmlChar_from_wchar((WCHAR*)tagName);
782 *resultList = create_filtered_nodelist((xmlNodePtr)get_doc(This), name, TRUE);
783 HeapFree(GetProcessHeap(), 0, name);
785 if(!*resultList) return S_FALSE;
789 static DOMNodeType get_node_type(VARIANT Type)
791 if(V_VT(&Type) == VT_I4)
794 FIXME("Unsupported variant type %x\n", V_VT(&Type));
798 static HRESULT WINAPI domdoc_createNode(
799 IXMLDOMDocument *iface,
805 domdoc *This = impl_from_IXMLDOMDocument( iface );
806 DOMNodeType node_type;
807 xmlNodePtr xmlnode = NULL;
810 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
812 node_type = get_node_type(Type);
813 TRACE("node_type %d\n", node_type);
815 xml_name = xmlChar_from_wchar((WCHAR*)name);
820 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
821 *node = create_node(xmlnode);
822 TRACE("created %p\n", xmlnode);
826 FIXME("unhandled node type %d\n", node_type);
830 HeapFree(GetProcessHeap(), 0, xml_name);
838 static HRESULT WINAPI domdoc_nodeFromID(
839 IXMLDOMDocument *iface,
847 static xmlDocPtr doparse( char *ptr, int len )
849 #ifdef HAVE_XMLREADMEMORY
851 * use xmlReadMemory if possible so we can suppress
852 * writing errors to stderr
854 return xmlReadMemory( ptr, len, NULL, NULL,
855 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
857 return xmlParseMemory( ptr, len );
861 static xmlDocPtr doread( LPWSTR filename )
863 xmlDocPtr xmldoc = NULL;
866 IStream *stream, *memstream;
867 WCHAR url[INTERNET_MAX_URL_LENGTH];
871 TRACE("%s\n", debugstr_w( filename ));
873 if(!PathIsURLW(filename))
875 WCHAR fullpath[MAX_PATH];
876 DWORD needed = sizeof(url)/sizeof(WCHAR);
878 if(!PathSearchAndQualifyW(filename, fullpath, sizeof(fullpath)/sizeof(WCHAR)))
880 WARN("can't find path\n");
884 if(FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0)))
886 ERR("can't create url from path\n");
892 hr = CreateBindCtx(0, &pbc);
895 hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&domdoc_bsc.lpVtbl, NULL, 0);
899 hr = CreateURLMoniker(NULL, filename, &moniker);
902 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
903 IMoniker_Release(moniker);
906 IBindCtx_Release(pbc);
911 hr = CreateStreamOnHGlobal(NULL, TRUE, &memstream);
914 IStream_Release(stream);
920 IStream_Read(stream, buf, sizeof(buf), &read);
921 hr = IStream_Write(memstream, buf, read, &written);
922 } while(SUCCEEDED(hr) && written != 0 && read != 0);
927 hr = GetHGlobalFromStream(memstream, &hglobal);
930 DWORD len = GlobalSize(hglobal);
931 char *ptr = GlobalLock(hglobal);
933 xmldoc = doparse( ptr, len );
934 GlobalUnlock(hglobal);
937 IStream_Release(memstream);
938 IStream_Release(stream);
942 static HRESULT WINAPI domdoc_load(
943 IXMLDOMDocument *iface,
945 VARIANT_BOOL* isSuccessful )
947 domdoc *This = impl_from_IXMLDOMDocument( iface );
948 LPWSTR filename = NULL;
949 xmlDocPtr xmldoc = NULL;
950 HRESULT hr = S_FALSE;
952 TRACE("type %d\n", V_VT(&xmlSource) );
954 *isSuccessful = VARIANT_FALSE;
956 assert( This->node );
958 attach_xmlnode(This->node, NULL);
960 switch( V_VT(&xmlSource) )
963 filename = V_BSTR(&xmlSource);
968 xmldoc = doread( filename );
971 This->error = E_FAIL;
974 hr = This->error = S_OK;
975 *isSuccessful = VARIANT_TRUE;
980 xmldoc = xmlNewDoc(NULL);
982 xmldoc->_private = 0;
983 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
989 static HRESULT WINAPI domdoc_get_readyState(
990 IXMLDOMDocument *iface,
998 static HRESULT WINAPI domdoc_get_parseError(
999 IXMLDOMDocument *iface,
1000 IXMLDOMParseError** errorObj )
1002 BSTR error_string = NULL;
1003 static const WCHAR err[] = {'e','r','r','o','r',0};
1004 domdoc *This = impl_from_IXMLDOMDocument( iface );
1006 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1009 error_string = SysAllocString(err);
1011 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1012 if(!*errorObj) return E_OUTOFMEMORY;
1017 static HRESULT WINAPI domdoc_get_url(
1018 IXMLDOMDocument *iface,
1026 static HRESULT WINAPI domdoc_get_async(
1027 IXMLDOMDocument *iface,
1028 VARIANT_BOOL* isAsync )
1030 domdoc *This = impl_from_IXMLDOMDocument( iface );
1032 TRACE("%p <- %d\n", isAsync, This->async);
1033 *isAsync = This->async;
1038 static HRESULT WINAPI domdoc_put_async(
1039 IXMLDOMDocument *iface,
1040 VARIANT_BOOL isAsync )
1042 domdoc *This = impl_from_IXMLDOMDocument( iface );
1044 TRACE("%d\n", isAsync);
1045 This->async = isAsync;
1050 static HRESULT WINAPI domdoc_abort(
1051 IXMLDOMDocument *iface )
1058 BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1060 UINT len, blen = SysStringLen( bstr );
1063 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1064 str = HeapAlloc( GetProcessHeap(), 0, len );
1067 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1073 static HRESULT WINAPI domdoc_loadXML(
1074 IXMLDOMDocument *iface,
1076 VARIANT_BOOL* isSuccessful )
1078 domdoc *This = impl_from_IXMLDOMDocument( iface );
1079 xmlDocPtr xmldoc = NULL;
1082 HRESULT hr = S_FALSE;
1084 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1086 assert ( This->node );
1088 attach_xmlnode( This->node, NULL );
1092 *isSuccessful = VARIANT_FALSE;
1094 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1096 xmldoc = doparse( str, len );
1097 HeapFree( GetProcessHeap(), 0, str );
1099 This->error = E_FAIL;
1102 hr = This->error = S_OK;
1103 *isSuccessful = VARIANT_TRUE;
1108 xmldoc = xmlNewDoc(NULL);
1110 xmldoc->_private = 0;
1111 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1117 static HRESULT WINAPI domdoc_save(
1118 IXMLDOMDocument *iface,
1119 VARIANT destination )
1121 domdoc *This = impl_from_IXMLDOMDocument( iface );
1128 TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
1129 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1131 if(V_VT(&destination) != VT_BSTR)
1133 FIXME("Unhandled vt %x\n", V_VT(&destination));
1137 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1138 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1139 if( handle == INVALID_HANDLE_VALUE )
1141 WARN("failed to create file\n");
1145 xmlDocDumpMemory(get_doc(This), &mem, &size);
1146 if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size)
1148 WARN("write error\n");
1153 CloseHandle(handle);
1157 static HRESULT WINAPI domdoc_get_validateOnParse(
1158 IXMLDOMDocument *iface,
1159 VARIANT_BOOL* isValidating )
1166 static HRESULT WINAPI domdoc_put_validateOnParse(
1167 IXMLDOMDocument *iface,
1168 VARIANT_BOOL isValidating )
1175 static HRESULT WINAPI domdoc_get_resolveExternals(
1176 IXMLDOMDocument *iface,
1177 VARIANT_BOOL* isResolving )
1184 static HRESULT WINAPI domdoc_put_resolveExternals(
1185 IXMLDOMDocument *iface,
1186 VARIANT_BOOL isValidating )
1193 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1194 IXMLDOMDocument *iface,
1195 VARIANT_BOOL* isPreserving )
1202 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1203 IXMLDOMDocument *iface,
1204 VARIANT_BOOL isPreserving )
1211 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1212 IXMLDOMDocument *iface,
1213 VARIANT readyStateChangeSink )
1220 static HRESULT WINAPI domdoc_put_onDataAvailable(
1221 IXMLDOMDocument *iface,
1222 VARIANT onDataAvailableSink )
1228 static HRESULT WINAPI domdoc_put_onTransformNode(
1229 IXMLDOMDocument *iface,
1230 VARIANT onTransformNodeSink )
1236 const struct IXMLDOMDocumentVtbl domdoc_vtbl =
1238 domdoc_QueryInterface,
1241 domdoc_GetTypeInfoCount,
1243 domdoc_GetIDsOfNames,
1245 domdoc_get_nodeName,
1246 domdoc_get_nodeValue,
1247 domdoc_put_nodeValue,
1248 domdoc_get_nodeType,
1249 domdoc_get_parentNode,
1250 domdoc_get_childNodes,
1251 domdoc_get_firstChild,
1252 domdoc_get_lastChild,
1253 domdoc_get_previousSibling,
1254 domdoc_get_nextSibling,
1255 domdoc_get_attributes,
1256 domdoc_insertBefore,
1257 domdoc_replaceChild,
1260 domdoc_hasChildNodes,
1261 domdoc_get_ownerDocument,
1263 domdoc_get_nodeTypeString,
1266 domdoc_get_specified,
1267 domdoc_get_definition,
1268 domdoc_get_nodeTypedValue,
1269 domdoc_put_nodeTypedValue,
1270 domdoc_get_dataType,
1271 domdoc_put_dataType,
1273 domdoc_transformNode,
1275 domdoc_selectSingleNode,
1277 domdoc_get_namespaceURI,
1279 domdoc_get_baseName,
1280 domdoc_transformNodeToObject,
1282 domdoc_get_implementation,
1283 domdoc_get_documentElement,
1284 domdoc_documentElement,
1285 domdoc_createElement,
1286 domdoc_createDocumentFragment,
1287 domdoc_createTextNode,
1288 domdoc_createComment,
1289 domdoc_createCDATASection,
1290 domdoc_createProcessingInstruction,
1291 domdoc_createAttribute,
1292 domdoc_createEntityReference,
1293 domdoc_getElementsByTagName,
1297 domdoc_get_readyState,
1298 domdoc_get_parseError,
1305 domdoc_get_validateOnParse,
1306 domdoc_put_validateOnParse,
1307 domdoc_get_resolveExternals,
1308 domdoc_put_resolveExternals,
1309 domdoc_get_preserveWhiteSpace,
1310 domdoc_put_preserveWhiteSpace,
1311 domdoc_put_onReadyStateChange,
1312 domdoc_put_onDataAvailable,
1313 domdoc_put_onTransformNode,
1316 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1322 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1324 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
1326 return E_OUTOFMEMORY;
1328 doc->lpVtbl = &domdoc_vtbl;
1333 xmldoc = xmlNewDoc(NULL);
1336 HeapFree(GetProcessHeap(), 0, doc);
1337 return E_OUTOFMEMORY;
1340 xmldoc->_private = 0;
1342 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
1346 HeapFree(GetProcessHeap(), 0, doc);
1350 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
1353 IUnknown_Release(doc->node_unk);
1354 HeapFree( GetProcessHeap(), 0, doc );
1357 /* The ref on doc->node is actually looped back into this object, so release it */
1358 IXMLDOMNode_Release(doc->node);
1360 *ppObj = &doc->lpVtbl;
1362 TRACE("returning iface %p\n", *ppObj);
1368 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1370 MESSAGE("This program tried to use a DOMDocument object, but\n"
1371 "libxml2 support was not present at compile time.\n");