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 )
765 domdoc *This = impl_from_IXMLDOMDocument( iface );
766 xmlChar *xml_target, *xml_content;
768 TRACE("%p->(%s %s %p)\n", iface, debugstr_w(target), debugstr_w(data), pi);
770 xml_target = xmlChar_from_wchar((WCHAR*)target);
771 xml_content = xmlChar_from_wchar((WCHAR*)data);
773 xmlnode = xmlNewDocPI(get_doc(This), xml_target, xml_content);
774 TRACE("created xmlptr %p\n", xmlnode);
775 *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode);
777 HeapFree(GetProcessHeap(), 0, xml_content);
778 HeapFree(GetProcessHeap(), 0, xml_target);
784 static HRESULT WINAPI domdoc_createAttribute(
785 IXMLDOMDocument *iface,
787 IXMLDOMAttribute** attribute )
794 static HRESULT WINAPI domdoc_createEntityReference(
795 IXMLDOMDocument *iface,
797 IXMLDOMEntityReference** entityRef )
804 static HRESULT WINAPI domdoc_getElementsByTagName(
805 IXMLDOMDocument *iface,
807 IXMLDOMNodeList** resultList )
809 domdoc *This = impl_from_IXMLDOMDocument( iface );
811 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
813 name = xmlChar_from_wchar((WCHAR*)tagName);
814 *resultList = create_filtered_nodelist((xmlNodePtr)get_doc(This), name, TRUE);
815 HeapFree(GetProcessHeap(), 0, name);
817 if(!*resultList) return S_FALSE;
821 static DOMNodeType get_node_type(VARIANT Type)
823 if(V_VT(&Type) == VT_I4)
826 FIXME("Unsupported variant type %x\n", V_VT(&Type));
830 static HRESULT WINAPI domdoc_createNode(
831 IXMLDOMDocument *iface,
837 domdoc *This = impl_from_IXMLDOMDocument( iface );
838 DOMNodeType node_type;
839 xmlNodePtr xmlnode = NULL;
842 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
844 node_type = get_node_type(Type);
845 TRACE("node_type %d\n", node_type);
847 xml_name = xmlChar_from_wchar((WCHAR*)name);
852 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
853 *node = create_node(xmlnode);
854 TRACE("created %p\n", xmlnode);
858 FIXME("unhandled node type %d\n", node_type);
862 HeapFree(GetProcessHeap(), 0, xml_name);
870 static HRESULT WINAPI domdoc_nodeFromID(
871 IXMLDOMDocument *iface,
879 static xmlDocPtr doparse( char *ptr, int len )
881 #ifdef HAVE_XMLREADMEMORY
883 * use xmlReadMemory if possible so we can suppress
884 * writing errors to stderr
886 return xmlReadMemory( ptr, len, NULL, NULL,
887 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
889 return xmlParseMemory( ptr, len );
893 static xmlDocPtr doread( LPWSTR filename )
895 xmlDocPtr xmldoc = NULL;
898 IStream *stream, *memstream;
899 WCHAR url[INTERNET_MAX_URL_LENGTH];
903 TRACE("%s\n", debugstr_w( filename ));
905 if(!PathIsURLW(filename))
907 WCHAR fullpath[MAX_PATH];
908 DWORD needed = sizeof(url)/sizeof(WCHAR);
910 if(!PathSearchAndQualifyW(filename, fullpath, sizeof(fullpath)/sizeof(WCHAR)))
912 WARN("can't find path\n");
916 if(FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0)))
918 ERR("can't create url from path\n");
924 hr = CreateBindCtx(0, &pbc);
927 hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&domdoc_bsc.lpVtbl, NULL, 0);
931 hr = CreateURLMoniker(NULL, filename, &moniker);
934 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
935 IMoniker_Release(moniker);
938 IBindCtx_Release(pbc);
943 hr = CreateStreamOnHGlobal(NULL, TRUE, &memstream);
946 IStream_Release(stream);
952 IStream_Read(stream, buf, sizeof(buf), &read);
953 hr = IStream_Write(memstream, buf, read, &written);
954 } while(SUCCEEDED(hr) && written != 0 && read != 0);
959 hr = GetHGlobalFromStream(memstream, &hglobal);
962 DWORD len = GlobalSize(hglobal);
963 char *ptr = GlobalLock(hglobal);
965 xmldoc = doparse( ptr, len );
966 GlobalUnlock(hglobal);
969 IStream_Release(memstream);
970 IStream_Release(stream);
974 static HRESULT WINAPI domdoc_load(
975 IXMLDOMDocument *iface,
977 VARIANT_BOOL* isSuccessful )
979 domdoc *This = impl_from_IXMLDOMDocument( iface );
980 LPWSTR filename = NULL;
981 xmlDocPtr xmldoc = NULL;
982 HRESULT hr = S_FALSE;
984 TRACE("type %d\n", V_VT(&xmlSource) );
986 *isSuccessful = VARIANT_FALSE;
988 assert( This->node );
990 attach_xmlnode(This->node, NULL);
992 switch( V_VT(&xmlSource) )
995 filename = V_BSTR(&xmlSource);
1000 xmldoc = doread( filename );
1003 This->error = E_FAIL;
1006 hr = This->error = S_OK;
1007 *isSuccessful = VARIANT_TRUE;
1012 xmldoc = xmlNewDoc(NULL);
1014 xmldoc->_private = 0;
1015 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1021 static HRESULT WINAPI domdoc_get_readyState(
1022 IXMLDOMDocument *iface,
1030 static HRESULT WINAPI domdoc_get_parseError(
1031 IXMLDOMDocument *iface,
1032 IXMLDOMParseError** errorObj )
1034 BSTR error_string = NULL;
1035 static const WCHAR err[] = {'e','r','r','o','r',0};
1036 domdoc *This = impl_from_IXMLDOMDocument( iface );
1038 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1041 error_string = SysAllocString(err);
1043 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1044 if(!*errorObj) return E_OUTOFMEMORY;
1049 static HRESULT WINAPI domdoc_get_url(
1050 IXMLDOMDocument *iface,
1058 static HRESULT WINAPI domdoc_get_async(
1059 IXMLDOMDocument *iface,
1060 VARIANT_BOOL* isAsync )
1062 domdoc *This = impl_from_IXMLDOMDocument( iface );
1064 TRACE("%p <- %d\n", isAsync, This->async);
1065 *isAsync = This->async;
1070 static HRESULT WINAPI domdoc_put_async(
1071 IXMLDOMDocument *iface,
1072 VARIANT_BOOL isAsync )
1074 domdoc *This = impl_from_IXMLDOMDocument( iface );
1076 TRACE("%d\n", isAsync);
1077 This->async = isAsync;
1082 static HRESULT WINAPI domdoc_abort(
1083 IXMLDOMDocument *iface )
1090 static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1092 UINT len, blen = SysStringLen( bstr );
1095 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1096 str = HeapAlloc( GetProcessHeap(), 0, len );
1099 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1105 static HRESULT WINAPI domdoc_loadXML(
1106 IXMLDOMDocument *iface,
1108 VARIANT_BOOL* isSuccessful )
1110 domdoc *This = impl_from_IXMLDOMDocument( iface );
1111 xmlDocPtr xmldoc = NULL;
1114 HRESULT hr = S_FALSE;
1116 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1118 assert ( This->node );
1120 attach_xmlnode( This->node, NULL );
1124 *isSuccessful = VARIANT_FALSE;
1126 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1128 xmldoc = doparse( str, len );
1129 HeapFree( GetProcessHeap(), 0, str );
1131 This->error = E_FAIL;
1134 hr = This->error = S_OK;
1135 *isSuccessful = VARIANT_TRUE;
1140 xmldoc = xmlNewDoc(NULL);
1142 xmldoc->_private = 0;
1143 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1149 static HRESULT WINAPI domdoc_save(
1150 IXMLDOMDocument *iface,
1151 VARIANT destination )
1153 domdoc *This = impl_from_IXMLDOMDocument( iface );
1160 TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
1161 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1163 if(V_VT(&destination) != VT_BSTR)
1165 FIXME("Unhandled vt %x\n", V_VT(&destination));
1169 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1170 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1171 if( handle == INVALID_HANDLE_VALUE )
1173 WARN("failed to create file\n");
1177 xmlDocDumpMemory(get_doc(This), &mem, &size);
1178 if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size)
1180 WARN("write error\n");
1185 CloseHandle(handle);
1189 static HRESULT WINAPI domdoc_get_validateOnParse(
1190 IXMLDOMDocument *iface,
1191 VARIANT_BOOL* isValidating )
1198 static HRESULT WINAPI domdoc_put_validateOnParse(
1199 IXMLDOMDocument *iface,
1200 VARIANT_BOOL isValidating )
1207 static HRESULT WINAPI domdoc_get_resolveExternals(
1208 IXMLDOMDocument *iface,
1209 VARIANT_BOOL* isResolving )
1216 static HRESULT WINAPI domdoc_put_resolveExternals(
1217 IXMLDOMDocument *iface,
1218 VARIANT_BOOL isValidating )
1225 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1226 IXMLDOMDocument *iface,
1227 VARIANT_BOOL* isPreserving )
1234 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1235 IXMLDOMDocument *iface,
1236 VARIANT_BOOL isPreserving )
1243 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1244 IXMLDOMDocument *iface,
1245 VARIANT readyStateChangeSink )
1252 static HRESULT WINAPI domdoc_put_onDataAvailable(
1253 IXMLDOMDocument *iface,
1254 VARIANT onDataAvailableSink )
1260 static HRESULT WINAPI domdoc_put_onTransformNode(
1261 IXMLDOMDocument *iface,
1262 VARIANT onTransformNodeSink )
1268 static const struct IXMLDOMDocumentVtbl domdoc_vtbl =
1270 domdoc_QueryInterface,
1273 domdoc_GetTypeInfoCount,
1275 domdoc_GetIDsOfNames,
1277 domdoc_get_nodeName,
1278 domdoc_get_nodeValue,
1279 domdoc_put_nodeValue,
1280 domdoc_get_nodeType,
1281 domdoc_get_parentNode,
1282 domdoc_get_childNodes,
1283 domdoc_get_firstChild,
1284 domdoc_get_lastChild,
1285 domdoc_get_previousSibling,
1286 domdoc_get_nextSibling,
1287 domdoc_get_attributes,
1288 domdoc_insertBefore,
1289 domdoc_replaceChild,
1292 domdoc_hasChildNodes,
1293 domdoc_get_ownerDocument,
1295 domdoc_get_nodeTypeString,
1298 domdoc_get_specified,
1299 domdoc_get_definition,
1300 domdoc_get_nodeTypedValue,
1301 domdoc_put_nodeTypedValue,
1302 domdoc_get_dataType,
1303 domdoc_put_dataType,
1305 domdoc_transformNode,
1307 domdoc_selectSingleNode,
1309 domdoc_get_namespaceURI,
1311 domdoc_get_baseName,
1312 domdoc_transformNodeToObject,
1314 domdoc_get_implementation,
1315 domdoc_get_documentElement,
1316 domdoc_documentElement,
1317 domdoc_createElement,
1318 domdoc_createDocumentFragment,
1319 domdoc_createTextNode,
1320 domdoc_createComment,
1321 domdoc_createCDATASection,
1322 domdoc_createProcessingInstruction,
1323 domdoc_createAttribute,
1324 domdoc_createEntityReference,
1325 domdoc_getElementsByTagName,
1329 domdoc_get_readyState,
1330 domdoc_get_parseError,
1337 domdoc_get_validateOnParse,
1338 domdoc_put_validateOnParse,
1339 domdoc_get_resolveExternals,
1340 domdoc_put_resolveExternals,
1341 domdoc_get_preserveWhiteSpace,
1342 domdoc_put_preserveWhiteSpace,
1343 domdoc_put_onReadyStateChange,
1344 domdoc_put_onDataAvailable,
1345 domdoc_put_onTransformNode,
1348 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1354 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1356 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
1358 return E_OUTOFMEMORY;
1360 doc->lpVtbl = &domdoc_vtbl;
1365 xmldoc = xmlNewDoc(NULL);
1368 HeapFree(GetProcessHeap(), 0, doc);
1369 return E_OUTOFMEMORY;
1372 xmldoc->_private = 0;
1374 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
1378 HeapFree(GetProcessHeap(), 0, doc);
1382 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
1385 IUnknown_Release(doc->node_unk);
1386 HeapFree( GetProcessHeap(), 0, doc );
1389 /* The ref on doc->node is actually looped back into this object, so release it */
1390 IXMLDOMNode_Release(doc->node);
1392 *ppObj = &doc->lpVtbl;
1394 TRACE("returning iface %p\n", *ppObj);
1400 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1402 MESSAGE("This program tried to use a DOMDocument object, but\n"
1403 "libxml2 support was not present at compile time.\n");