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 static 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 )
698 domdoc *This = impl_from_IXMLDOMDocument( iface );
703 TRACE("%p->(%s,%p)\n", iface, debugstr_w(tagname), element);
705 xml_name = xmlChar_from_wchar((WCHAR*)tagname);
706 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
708 TRACE("created xmlptr %p\n", xmlnode);
709 elem_unk = create_element(xmlnode, NULL);
710 HeapFree(GetProcessHeap(), 0, xml_name);
712 hr = IUnknown_QueryInterface(elem_unk, &IID_IXMLDOMElement, (void **)element);
713 IUnknown_Release(elem_unk);
714 TRACE("returning %p\n", *element);
719 static HRESULT WINAPI domdoc_createDocumentFragment(
720 IXMLDOMDocument *iface,
721 IXMLDOMDocumentFragment** docFrag )
728 static HRESULT WINAPI domdoc_createTextNode(
729 IXMLDOMDocument *iface,
738 static HRESULT WINAPI domdoc_createComment(
739 IXMLDOMDocument *iface,
741 IXMLDOMComment** comment )
748 static HRESULT WINAPI domdoc_createCDATASection(
749 IXMLDOMDocument *iface,
751 IXMLDOMCDATASection** cdata )
758 static HRESULT WINAPI domdoc_createProcessingInstruction(
759 IXMLDOMDocument *iface,
762 IXMLDOMProcessingInstruction** pi )
764 #ifdef HAVE_XMLNEWDOCPI
766 domdoc *This = impl_from_IXMLDOMDocument( iface );
767 xmlChar *xml_target, *xml_content;
769 TRACE("%p->(%s %s %p)\n", iface, debugstr_w(target), debugstr_w(data), pi);
771 xml_target = xmlChar_from_wchar((WCHAR*)target);
772 xml_content = xmlChar_from_wchar((WCHAR*)data);
774 xmlnode = xmlNewDocPI(get_doc(This), xml_target, xml_content);
775 TRACE("created xmlptr %p\n", xmlnode);
776 *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode);
778 HeapFree(GetProcessHeap(), 0, xml_content);
779 HeapFree(GetProcessHeap(), 0, xml_target);
783 FIXME("Libxml 2.6.15 or greater required.\n");
789 static HRESULT WINAPI domdoc_createAttribute(
790 IXMLDOMDocument *iface,
792 IXMLDOMAttribute** attribute )
799 static HRESULT WINAPI domdoc_createEntityReference(
800 IXMLDOMDocument *iface,
802 IXMLDOMEntityReference** entityRef )
809 static HRESULT WINAPI domdoc_getElementsByTagName(
810 IXMLDOMDocument *iface,
812 IXMLDOMNodeList** resultList )
814 domdoc *This = impl_from_IXMLDOMDocument( iface );
816 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
818 name = xmlChar_from_wchar((WCHAR*)tagName);
819 *resultList = create_filtered_nodelist((xmlNodePtr)get_doc(This), name, TRUE);
820 HeapFree(GetProcessHeap(), 0, name);
822 if(!*resultList) return S_FALSE;
826 static DOMNodeType get_node_type(VARIANT Type)
828 if(V_VT(&Type) == VT_I4)
831 FIXME("Unsupported variant type %x\n", V_VT(&Type));
835 static HRESULT WINAPI domdoc_createNode(
836 IXMLDOMDocument *iface,
842 domdoc *This = impl_from_IXMLDOMDocument( iface );
843 DOMNodeType node_type;
844 xmlNodePtr xmlnode = NULL;
847 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
849 node_type = get_node_type(Type);
850 TRACE("node_type %d\n", node_type);
852 xml_name = xmlChar_from_wchar((WCHAR*)name);
857 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
858 *node = create_node(xmlnode);
859 TRACE("created %p\n", xmlnode);
863 FIXME("unhandled node type %d\n", node_type);
867 HeapFree(GetProcessHeap(), 0, xml_name);
875 static HRESULT WINAPI domdoc_nodeFromID(
876 IXMLDOMDocument *iface,
884 static xmlDocPtr doparse( char *ptr, int len )
886 #ifdef HAVE_XMLREADMEMORY
888 * use xmlReadMemory if possible so we can suppress
889 * writing errors to stderr
891 return xmlReadMemory( ptr, len, NULL, NULL,
892 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
894 return xmlParseMemory( ptr, len );
898 static xmlDocPtr doread( LPWSTR filename )
900 xmlDocPtr xmldoc = NULL;
903 IStream *stream, *memstream;
904 WCHAR url[INTERNET_MAX_URL_LENGTH];
908 TRACE("%s\n", debugstr_w( filename ));
910 if(!PathIsURLW(filename))
912 WCHAR fullpath[MAX_PATH];
913 DWORD needed = sizeof(url)/sizeof(WCHAR);
915 if(!PathSearchAndQualifyW(filename, fullpath, sizeof(fullpath)/sizeof(WCHAR)))
917 WARN("can't find path\n");
921 if(FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0)))
923 ERR("can't create url from path\n");
929 hr = CreateBindCtx(0, &pbc);
932 hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&domdoc_bsc.lpVtbl, NULL, 0);
936 hr = CreateURLMoniker(NULL, filename, &moniker);
939 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
940 IMoniker_Release(moniker);
943 IBindCtx_Release(pbc);
948 hr = CreateStreamOnHGlobal(NULL, TRUE, &memstream);
951 IStream_Release(stream);
957 IStream_Read(stream, buf, sizeof(buf), &read);
958 hr = IStream_Write(memstream, buf, read, &written);
959 } while(SUCCEEDED(hr) && written != 0 && read != 0);
964 hr = GetHGlobalFromStream(memstream, &hglobal);
967 DWORD len = GlobalSize(hglobal);
968 char *ptr = GlobalLock(hglobal);
970 xmldoc = doparse( ptr, len );
971 GlobalUnlock(hglobal);
974 IStream_Release(memstream);
975 IStream_Release(stream);
979 static HRESULT WINAPI domdoc_load(
980 IXMLDOMDocument *iface,
982 VARIANT_BOOL* isSuccessful )
984 domdoc *This = impl_from_IXMLDOMDocument( iface );
985 LPWSTR filename = NULL;
986 xmlDocPtr xmldoc = NULL;
987 HRESULT hr = S_FALSE;
989 TRACE("type %d\n", V_VT(&xmlSource) );
991 *isSuccessful = VARIANT_FALSE;
993 assert( This->node );
995 attach_xmlnode(This->node, NULL);
997 switch( V_VT(&xmlSource) )
1000 filename = V_BSTR(&xmlSource);
1005 xmldoc = doread( filename );
1008 This->error = E_FAIL;
1011 hr = This->error = S_OK;
1012 *isSuccessful = VARIANT_TRUE;
1017 xmldoc = xmlNewDoc(NULL);
1019 xmldoc->_private = 0;
1020 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1026 static HRESULT WINAPI domdoc_get_readyState(
1027 IXMLDOMDocument *iface,
1035 static HRESULT WINAPI domdoc_get_parseError(
1036 IXMLDOMDocument *iface,
1037 IXMLDOMParseError** errorObj )
1039 BSTR error_string = NULL;
1040 static const WCHAR err[] = {'e','r','r','o','r',0};
1041 domdoc *This = impl_from_IXMLDOMDocument( iface );
1043 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1046 error_string = SysAllocString(err);
1048 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1049 if(!*errorObj) return E_OUTOFMEMORY;
1054 static HRESULT WINAPI domdoc_get_url(
1055 IXMLDOMDocument *iface,
1063 static HRESULT WINAPI domdoc_get_async(
1064 IXMLDOMDocument *iface,
1065 VARIANT_BOOL* isAsync )
1067 domdoc *This = impl_from_IXMLDOMDocument( iface );
1069 TRACE("%p <- %d\n", isAsync, This->async);
1070 *isAsync = This->async;
1075 static HRESULT WINAPI domdoc_put_async(
1076 IXMLDOMDocument *iface,
1077 VARIANT_BOOL isAsync )
1079 domdoc *This = impl_from_IXMLDOMDocument( iface );
1081 TRACE("%d\n", isAsync);
1082 This->async = isAsync;
1087 static HRESULT WINAPI domdoc_abort(
1088 IXMLDOMDocument *iface )
1095 static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1097 UINT len, blen = SysStringLen( bstr );
1100 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1101 str = HeapAlloc( GetProcessHeap(), 0, len );
1104 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1110 static HRESULT WINAPI domdoc_loadXML(
1111 IXMLDOMDocument *iface,
1113 VARIANT_BOOL* isSuccessful )
1115 domdoc *This = impl_from_IXMLDOMDocument( iface );
1116 xmlDocPtr xmldoc = NULL;
1119 HRESULT hr = S_FALSE;
1121 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1123 assert ( This->node );
1125 attach_xmlnode( This->node, NULL );
1129 *isSuccessful = VARIANT_FALSE;
1131 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1133 xmldoc = doparse( str, len );
1134 HeapFree( GetProcessHeap(), 0, str );
1136 This->error = E_FAIL;
1139 hr = This->error = S_OK;
1140 *isSuccessful = VARIANT_TRUE;
1145 xmldoc = xmlNewDoc(NULL);
1147 xmldoc->_private = 0;
1148 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1154 static HRESULT WINAPI domdoc_save(
1155 IXMLDOMDocument *iface,
1156 VARIANT destination )
1158 domdoc *This = impl_from_IXMLDOMDocument( iface );
1165 TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
1166 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1168 if(V_VT(&destination) != VT_BSTR)
1170 FIXME("Unhandled vt %x\n", V_VT(&destination));
1174 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1175 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1176 if( handle == INVALID_HANDLE_VALUE )
1178 WARN("failed to create file\n");
1182 xmlDocDumpMemory(get_doc(This), &mem, &size);
1183 if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size)
1185 WARN("write error\n");
1190 CloseHandle(handle);
1194 static HRESULT WINAPI domdoc_get_validateOnParse(
1195 IXMLDOMDocument *iface,
1196 VARIANT_BOOL* isValidating )
1203 static HRESULT WINAPI domdoc_put_validateOnParse(
1204 IXMLDOMDocument *iface,
1205 VARIANT_BOOL isValidating )
1212 static HRESULT WINAPI domdoc_get_resolveExternals(
1213 IXMLDOMDocument *iface,
1214 VARIANT_BOOL* isResolving )
1221 static HRESULT WINAPI domdoc_put_resolveExternals(
1222 IXMLDOMDocument *iface,
1223 VARIANT_BOOL isValidating )
1230 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1231 IXMLDOMDocument *iface,
1232 VARIANT_BOOL* isPreserving )
1239 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1240 IXMLDOMDocument *iface,
1241 VARIANT_BOOL isPreserving )
1248 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1249 IXMLDOMDocument *iface,
1250 VARIANT readyStateChangeSink )
1257 static HRESULT WINAPI domdoc_put_onDataAvailable(
1258 IXMLDOMDocument *iface,
1259 VARIANT onDataAvailableSink )
1265 static HRESULT WINAPI domdoc_put_onTransformNode(
1266 IXMLDOMDocument *iface,
1267 VARIANT onTransformNodeSink )
1273 static const struct IXMLDOMDocumentVtbl domdoc_vtbl =
1275 domdoc_QueryInterface,
1278 domdoc_GetTypeInfoCount,
1280 domdoc_GetIDsOfNames,
1282 domdoc_get_nodeName,
1283 domdoc_get_nodeValue,
1284 domdoc_put_nodeValue,
1285 domdoc_get_nodeType,
1286 domdoc_get_parentNode,
1287 domdoc_get_childNodes,
1288 domdoc_get_firstChild,
1289 domdoc_get_lastChild,
1290 domdoc_get_previousSibling,
1291 domdoc_get_nextSibling,
1292 domdoc_get_attributes,
1293 domdoc_insertBefore,
1294 domdoc_replaceChild,
1297 domdoc_hasChildNodes,
1298 domdoc_get_ownerDocument,
1300 domdoc_get_nodeTypeString,
1303 domdoc_get_specified,
1304 domdoc_get_definition,
1305 domdoc_get_nodeTypedValue,
1306 domdoc_put_nodeTypedValue,
1307 domdoc_get_dataType,
1308 domdoc_put_dataType,
1310 domdoc_transformNode,
1312 domdoc_selectSingleNode,
1314 domdoc_get_namespaceURI,
1316 domdoc_get_baseName,
1317 domdoc_transformNodeToObject,
1319 domdoc_get_implementation,
1320 domdoc_get_documentElement,
1321 domdoc_documentElement,
1322 domdoc_createElement,
1323 domdoc_createDocumentFragment,
1324 domdoc_createTextNode,
1325 domdoc_createComment,
1326 domdoc_createCDATASection,
1327 domdoc_createProcessingInstruction,
1328 domdoc_createAttribute,
1329 domdoc_createEntityReference,
1330 domdoc_getElementsByTagName,
1334 domdoc_get_readyState,
1335 domdoc_get_parseError,
1342 domdoc_get_validateOnParse,
1343 domdoc_put_validateOnParse,
1344 domdoc_get_resolveExternals,
1345 domdoc_put_resolveExternals,
1346 domdoc_get_preserveWhiteSpace,
1347 domdoc_put_preserveWhiteSpace,
1348 domdoc_put_onReadyStateChange,
1349 domdoc_put_onDataAvailable,
1350 domdoc_put_onTransformNode,
1353 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1359 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1361 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
1363 return E_OUTOFMEMORY;
1365 doc->lpVtbl = &domdoc_vtbl;
1370 xmldoc = xmlNewDoc(NULL);
1373 HeapFree(GetProcessHeap(), 0, doc);
1374 return E_OUTOFMEMORY;
1377 xmldoc->_private = 0;
1379 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
1383 HeapFree(GetProcessHeap(), 0, doc);
1387 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
1390 IUnknown_Release(doc->node_unk);
1391 HeapFree( GetProcessHeap(), 0, doc );
1394 /* The ref on doc->node is actually looped back into this object, so release it */
1395 IXMLDOMNode_Release(doc->node);
1397 *ppObj = &doc->lpVtbl;
1399 TRACE("returning iface %p\n", *ppObj);
1405 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1407 MESSAGE("This program tried to use a DOMDocument object, but\n"
1408 "libxml2 support was not present at compile time.\n");