msxml3: Implemented IXMLDOMCDATASection COM Object.
[wine/wine64.git] / dlls / msxml3 / domdoc.c
blob15772e5ba34b65e5d7ede97a8bebac6ba4ab48e8
1 /*
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
21 #define COBJMACROS
23 #include "config.h"
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"
33 #include "wininet.h"
34 #include "urlmon.h"
35 #include "winreg.h"
36 #include "shlwapi.h"
38 #include "wine/debug.h"
40 #include "msxml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
44 #ifdef HAVE_LIBXML2
46 static const WCHAR SZ_PROPERTY_SELECTION_LANGUAGE[] = {'S','e','l','e','c','t','i','o','n','L','a','n','g','u','a','g','e',0};
47 static const WCHAR SZ_VALUE_XPATH[] = {'X','P','a','t','h',0};
48 static const WCHAR SZ_VALUE_XSLPATTERN[] = {'X','S','L','P','a','t','t','e','r','n',0};
50 typedef struct {
51 const struct IBindStatusCallbackVtbl *lpVtbl;
52 } bsc;
54 static HRESULT WINAPI bsc_QueryInterface(
55 IBindStatusCallback *iface,
56 REFIID riid,
57 LPVOID *ppobj )
59 if (IsEqualGUID(riid, &IID_IUnknown) ||
60 IsEqualGUID(riid, &IID_IBindStatusCallback))
62 IBindStatusCallback_AddRef( iface );
63 *ppobj = iface;
64 return S_OK;
67 FIXME("interface %s not implemented\n", debugstr_guid(riid));
68 return E_NOINTERFACE;
71 static ULONG WINAPI bsc_AddRef(
72 IBindStatusCallback *iface )
74 return 2;
77 static ULONG WINAPI bsc_Release(
78 IBindStatusCallback *iface )
80 return 1;
83 static HRESULT WINAPI bsc_OnStartBinding(
84 IBindStatusCallback* iface,
85 DWORD dwReserved,
86 IBinding* pib)
88 return S_OK;
91 static HRESULT WINAPI bsc_GetPriority(
92 IBindStatusCallback* iface,
93 LONG* pnPriority)
95 return S_OK;
98 static HRESULT WINAPI bsc_OnLowResource(
99 IBindStatusCallback* iface,
100 DWORD reserved)
102 return S_OK;
105 static HRESULT WINAPI bsc_OnProgress(
106 IBindStatusCallback* iface,
107 ULONG ulProgress,
108 ULONG ulProgressMax,
109 ULONG ulStatusCode,
110 LPCWSTR szStatusText)
112 return S_OK;
115 static HRESULT WINAPI bsc_OnStopBinding(
116 IBindStatusCallback* iface,
117 HRESULT hresult,
118 LPCWSTR szError)
120 return S_OK;
123 static HRESULT WINAPI bsc_GetBindInfo(
124 IBindStatusCallback* iface,
125 DWORD* grfBINDF,
126 BINDINFO* pbindinfo)
128 *grfBINDF = BINDF_RESYNCHRONIZE;
130 return S_OK;
133 static HRESULT WINAPI bsc_OnDataAvailable(
134 IBindStatusCallback* iface,
135 DWORD grfBSCF,
136 DWORD dwSize,
137 FORMATETC* pformatetc,
138 STGMEDIUM* pstgmed)
140 return S_OK;
143 static HRESULT WINAPI bsc_OnObjectAvailable(
144 IBindStatusCallback* iface,
145 REFIID riid,
146 IUnknown* punk)
148 return S_OK;
151 static const struct IBindStatusCallbackVtbl bsc_vtbl =
153 bsc_QueryInterface,
154 bsc_AddRef,
155 bsc_Release,
156 bsc_OnStartBinding,
157 bsc_GetPriority,
158 bsc_OnLowResource,
159 bsc_OnProgress,
160 bsc_OnStopBinding,
161 bsc_GetBindInfo,
162 bsc_OnDataAvailable,
163 bsc_OnObjectAvailable
166 static bsc domdoc_bsc = { &bsc_vtbl };
168 typedef struct _domdoc
170 const struct IXMLDOMDocument2Vtbl *lpVtbl;
171 const struct IPersistStreamVtbl *lpvtblIPersistStream;
172 LONG ref;
173 VARIANT_BOOL async;
174 VARIANT_BOOL validating;
175 VARIANT_BOOL resolving;
176 VARIANT_BOOL preserving;
177 BOOL bUseXPath;
178 IUnknown *node_unk;
179 IXMLDOMNode *node;
180 IXMLDOMSchemaCollection *schema;
181 HRESULT error;
183 /* IPersistStream */
184 IStream *stream;
185 } domdoc;
187 LONG xmldoc_add_ref(xmlDocPtr doc)
189 LONG ref = InterlockedIncrement((LONG*)&doc->_private);
190 TRACE("%d\n", ref);
191 return ref;
194 LONG xmldoc_release(xmlDocPtr doc)
196 LONG ref = InterlockedDecrement((LONG*)&doc->_private);
197 TRACE("%d\n", ref);
198 if(ref == 0)
200 TRACE("freeing docptr %p\n", doc);
201 xmlFreeDoc(doc);
204 return ref;
207 static inline domdoc *impl_from_IXMLDOMDocument2( IXMLDOMDocument2 *iface )
209 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpVtbl));
212 static inline xmlDocPtr get_doc( domdoc *This )
214 return (xmlDocPtr) xmlNodePtr_from_domnode( This->node, XML_DOCUMENT_NODE );
217 static inline domdoc *impl_from_IPersistStream(IPersistStream *iface)
219 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIPersistStream));
222 /************************************************************************
223 * xmldoc implementation of IPersistStream.
225 static HRESULT WINAPI xmldoc_IPersistStream_QueryInterface(
226 IPersistStream *iface, REFIID riid, LPVOID *ppvObj)
228 domdoc *this = impl_from_IPersistStream(iface);
229 return IXMLDocument_QueryInterface((IXMLDocument *)this, riid, ppvObj);
232 static ULONG WINAPI xmldoc_IPersistStream_AddRef(
233 IPersistStream *iface)
235 domdoc *this = impl_from_IPersistStream(iface);
236 return IXMLDocument_AddRef((IXMLDocument *)this);
239 static ULONG WINAPI xmldoc_IPersistStream_Release(
240 IPersistStream *iface)
242 domdoc *this = impl_from_IPersistStream(iface);
243 return IXMLDocument_Release((IXMLDocument *)this);
246 static HRESULT WINAPI xmldoc_IPersistStream_GetClassID(
247 IPersistStream *iface, CLSID *classid)
249 FIXME("(%p,%p): stub!\n", iface, classid);
250 return E_NOTIMPL;
253 static HRESULT WINAPI xmldoc_IPersistStream_IsDirty(
254 IPersistStream *iface)
256 domdoc *This = impl_from_IPersistStream(iface);
258 FIXME("(%p->%p): stub!\n", iface, This);
260 return S_FALSE;
263 static HRESULT WINAPI xmldoc_IPersistStream_Load(
264 IPersistStream *iface, LPSTREAM pStm)
266 domdoc *This = impl_from_IPersistStream(iface);
267 HRESULT hr;
268 HGLOBAL hglobal;
269 DWORD read, written, len;
270 BYTE buf[4096];
271 char *ptr;
272 xmlDocPtr xmldoc = NULL;
274 TRACE("(%p, %p)\n", iface, pStm);
276 if (!pStm)
277 return E_INVALIDARG;
279 hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
280 if (FAILED(hr))
281 return hr;
285 IStream_Read(pStm, buf, sizeof(buf), &read);
286 hr = IStream_Write(This->stream, buf, read, &written);
287 } while(SUCCEEDED(hr) && written != 0 && read != 0);
289 if (FAILED(hr))
291 ERR("Failed to copy stream\n");
292 return hr;
295 hr = GetHGlobalFromStream(This->stream, &hglobal);
296 if (FAILED(hr))
297 return hr;
299 len = GlobalSize(hglobal);
300 ptr = GlobalLock(hglobal);
301 if (len != 0)
302 xmldoc = parse_xml(ptr, len);
303 GlobalUnlock(hglobal);
305 if (!xmldoc)
307 ERR("Failed to parse xml\n");
308 return E_FAIL;
311 attach_xmlnode( This->node, (xmlNodePtr)xmldoc );
313 return S_OK;
316 static HRESULT WINAPI xmldoc_IPersistStream_Save(
317 IPersistStream *iface, LPSTREAM pStm, BOOL fClearDirty)
319 FIXME("(%p, %p, %d): stub!\n", iface, pStm, fClearDirty);
320 return E_NOTIMPL;
323 static HRESULT WINAPI xmldoc_IPersistStream_GetSizeMax(
324 IPersistStream *iface, ULARGE_INTEGER *pcbSize)
326 TRACE("(%p, %p): stub!\n", iface, pcbSize);
327 return E_NOTIMPL;
330 static const IPersistStreamVtbl xmldoc_IPersistStream_VTable =
332 xmldoc_IPersistStream_QueryInterface,
333 xmldoc_IPersistStream_AddRef,
334 xmldoc_IPersistStream_Release,
335 xmldoc_IPersistStream_GetClassID,
336 xmldoc_IPersistStream_IsDirty,
337 xmldoc_IPersistStream_Load,
338 xmldoc_IPersistStream_Save,
339 xmldoc_IPersistStream_GetSizeMax,
342 static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument2 *iface, REFIID riid, void** ppvObject )
344 domdoc *This = impl_from_IXMLDOMDocument2( iface );
346 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
348 *ppvObject = NULL;
350 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
351 IsEqualGUID( riid, &IID_IXMLDOMDocument ) ||
352 IsEqualGUID( riid, &IID_IXMLDOMDocument2 ) )
354 *ppvObject = iface;
356 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
357 IsEqualGUID( riid, &IID_IDispatch ) )
359 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
361 else if (IsEqualGUID(&IID_IPersistStream, riid))
363 *ppvObject = (IPersistStream*)&(This->lpvtblIPersistStream);
365 else if(IsEqualGUID(&IID_IRunnableObject, riid))
367 TRACE("IID_IRunnableObject not supported returning NULL\n");
368 return E_NOINTERFACE;
370 else
372 FIXME("interface %s not implemented\n", debugstr_guid(riid));
373 return E_NOINTERFACE;
376 IXMLDOMDocument_AddRef( iface );
378 return S_OK;
382 static ULONG WINAPI domdoc_AddRef(
383 IXMLDOMDocument2 *iface )
385 domdoc *This = impl_from_IXMLDOMDocument2( iface );
386 TRACE("%p\n", This );
387 return InterlockedIncrement( &This->ref );
391 static ULONG WINAPI domdoc_Release(
392 IXMLDOMDocument2 *iface )
394 domdoc *This = impl_from_IXMLDOMDocument2( iface );
395 LONG ref;
397 TRACE("%p\n", This );
399 ref = InterlockedDecrement( &This->ref );
400 if ( ref == 0 )
402 IUnknown_Release( This->node_unk );
403 if(This->schema) IXMLDOMSchemaCollection_Release( This->schema );
404 if (This->stream) IStream_Release(This->stream);
405 HeapFree( GetProcessHeap(), 0, This );
408 return ref;
411 static HRESULT WINAPI domdoc_GetTypeInfoCount( IXMLDOMDocument2 *iface, UINT* pctinfo )
413 FIXME("\n");
414 return E_NOTIMPL;
417 static HRESULT WINAPI domdoc_GetTypeInfo(
418 IXMLDOMDocument2 *iface,
419 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
421 FIXME("\n");
422 return E_NOTIMPL;
425 static HRESULT WINAPI domdoc_GetIDsOfNames(
426 IXMLDOMDocument2 *iface,
427 REFIID riid,
428 LPOLESTR* rgszNames,
429 UINT cNames,
430 LCID lcid,
431 DISPID* rgDispId)
433 FIXME("\n");
434 return E_NOTIMPL;
438 static HRESULT WINAPI domdoc_Invoke(
439 IXMLDOMDocument2 *iface,
440 DISPID dispIdMember,
441 REFIID riid,
442 LCID lcid,
443 WORD wFlags,
444 DISPPARAMS* pDispParams,
445 VARIANT* pVarResult,
446 EXCEPINFO* pExcepInfo,
447 UINT* puArgErr)
449 FIXME("\n");
450 return E_NOTIMPL;
454 static HRESULT WINAPI domdoc_get_nodeName(
455 IXMLDOMDocument2 *iface,
456 BSTR* name )
458 domdoc *This = impl_from_IXMLDOMDocument2( iface );
459 return IXMLDOMNode_get_nodeName( This->node, name );
463 static HRESULT WINAPI domdoc_get_nodeValue(
464 IXMLDOMDocument2 *iface,
465 VARIANT* value )
467 domdoc *This = impl_from_IXMLDOMDocument2( iface );
468 return IXMLDOMNode_get_nodeValue( This->node, value );
472 static HRESULT WINAPI domdoc_put_nodeValue(
473 IXMLDOMDocument2 *iface,
474 VARIANT value)
476 domdoc *This = impl_from_IXMLDOMDocument2( iface );
477 return IXMLDOMNode_put_nodeValue( This->node, value );
481 static HRESULT WINAPI domdoc_get_nodeType(
482 IXMLDOMDocument2 *iface,
483 DOMNodeType* type )
485 domdoc *This = impl_from_IXMLDOMDocument2( iface );
486 return IXMLDOMNode_get_nodeType( This->node, type );
490 static HRESULT WINAPI domdoc_get_parentNode(
491 IXMLDOMDocument2 *iface,
492 IXMLDOMNode** parent )
494 domdoc *This = impl_from_IXMLDOMDocument2( iface );
495 return IXMLDOMNode_get_parentNode( This->node, parent );
499 static HRESULT WINAPI domdoc_get_childNodes(
500 IXMLDOMDocument2 *iface,
501 IXMLDOMNodeList** childList )
503 domdoc *This = impl_from_IXMLDOMDocument2( iface );
504 return IXMLDOMNode_get_childNodes( This->node, childList );
508 static HRESULT WINAPI domdoc_get_firstChild(
509 IXMLDOMDocument2 *iface,
510 IXMLDOMNode** firstChild )
512 domdoc *This = impl_from_IXMLDOMDocument2( iface );
513 return IXMLDOMNode_get_firstChild( This->node, firstChild );
517 static HRESULT WINAPI domdoc_get_lastChild(
518 IXMLDOMDocument2 *iface,
519 IXMLDOMNode** lastChild )
521 domdoc *This = impl_from_IXMLDOMDocument2( iface );
522 return IXMLDOMNode_get_lastChild( This->node, lastChild );
526 static HRESULT WINAPI domdoc_get_previousSibling(
527 IXMLDOMDocument2 *iface,
528 IXMLDOMNode** previousSibling )
530 domdoc *This = impl_from_IXMLDOMDocument2( iface );
531 return IXMLDOMNode_get_previousSibling( This->node, previousSibling );
535 static HRESULT WINAPI domdoc_get_nextSibling(
536 IXMLDOMDocument2 *iface,
537 IXMLDOMNode** nextSibling )
539 domdoc *This = impl_from_IXMLDOMDocument2( iface );
540 return IXMLDOMNode_get_nextSibling( This->node, nextSibling );
544 static HRESULT WINAPI domdoc_get_attributes(
545 IXMLDOMDocument2 *iface,
546 IXMLDOMNamedNodeMap** attributeMap )
548 domdoc *This = impl_from_IXMLDOMDocument2( iface );
549 return IXMLDOMNode_get_attributes( This->node, attributeMap );
553 static HRESULT WINAPI domdoc_insertBefore(
554 IXMLDOMDocument2 *iface,
555 IXMLDOMNode* newChild,
556 VARIANT refChild,
557 IXMLDOMNode** outNewChild )
559 domdoc *This = impl_from_IXMLDOMDocument2( iface );
560 return IXMLDOMNode_insertBefore( This->node, newChild, refChild, outNewChild );
564 static HRESULT WINAPI domdoc_replaceChild(
565 IXMLDOMDocument2 *iface,
566 IXMLDOMNode* newChild,
567 IXMLDOMNode* oldChild,
568 IXMLDOMNode** outOldChild)
570 domdoc *This = impl_from_IXMLDOMDocument2( iface );
571 return IXMLDOMNode_replaceChild( This->node, newChild, oldChild, outOldChild );
575 static HRESULT WINAPI domdoc_removeChild(
576 IXMLDOMDocument2 *iface,
577 IXMLDOMNode* childNode,
578 IXMLDOMNode** oldChild)
580 domdoc *This = impl_from_IXMLDOMDocument2( iface );
581 return IXMLDOMNode_removeChild( This->node, childNode, oldChild );
585 static HRESULT WINAPI domdoc_appendChild(
586 IXMLDOMDocument2 *iface,
587 IXMLDOMNode* newChild,
588 IXMLDOMNode** outNewChild)
590 domdoc *This = impl_from_IXMLDOMDocument2( iface );
591 return IXMLDOMNode_appendChild( This->node, newChild, outNewChild );
595 static HRESULT WINAPI domdoc_hasChildNodes(
596 IXMLDOMDocument2 *iface,
597 VARIANT_BOOL* hasChild)
599 domdoc *This = impl_from_IXMLDOMDocument2( iface );
600 return IXMLDOMNode_hasChildNodes( This->node, hasChild );
604 static HRESULT WINAPI domdoc_get_ownerDocument(
605 IXMLDOMDocument2 *iface,
606 IXMLDOMDocument** DOMDocument)
608 domdoc *This = impl_from_IXMLDOMDocument2( iface );
609 return IXMLDOMNode_get_ownerDocument( This->node, DOMDocument );
613 static HRESULT WINAPI domdoc_cloneNode(
614 IXMLDOMDocument2 *iface,
615 VARIANT_BOOL deep,
616 IXMLDOMNode** cloneRoot)
618 domdoc *This = impl_from_IXMLDOMDocument2( iface );
619 return IXMLDOMNode_cloneNode( This->node, deep, cloneRoot );
623 static HRESULT WINAPI domdoc_get_nodeTypeString(
624 IXMLDOMDocument2 *iface,
625 BSTR* nodeType )
627 domdoc *This = impl_from_IXMLDOMDocument2( iface );
628 return IXMLDOMNode_get_nodeTypeString( This->node, nodeType );
632 static HRESULT WINAPI domdoc_get_text(
633 IXMLDOMDocument2 *iface,
634 BSTR* text )
636 domdoc *This = impl_from_IXMLDOMDocument2( iface );
637 return IXMLDOMNode_get_text( This->node, text );
641 static HRESULT WINAPI domdoc_put_text(
642 IXMLDOMDocument2 *iface,
643 BSTR text )
645 domdoc *This = impl_from_IXMLDOMDocument2( iface );
646 return IXMLDOMNode_put_text( This->node, text );
650 static HRESULT WINAPI domdoc_get_specified(
651 IXMLDOMDocument2 *iface,
652 VARIANT_BOOL* isSpecified )
654 domdoc *This = impl_from_IXMLDOMDocument2( iface );
655 return IXMLDOMNode_get_specified( This->node, isSpecified );
659 static HRESULT WINAPI domdoc_get_definition(
660 IXMLDOMDocument2 *iface,
661 IXMLDOMNode** definitionNode )
663 domdoc *This = impl_from_IXMLDOMDocument2( iface );
664 return IXMLDOMNode_get_definition( This->node, definitionNode );
668 static HRESULT WINAPI domdoc_get_nodeTypedValue(
669 IXMLDOMDocument2 *iface,
670 VARIANT* typedValue )
672 domdoc *This = impl_from_IXMLDOMDocument2( iface );
673 return IXMLDOMNode_get_nodeTypedValue( This->node, typedValue );
676 static HRESULT WINAPI domdoc_put_nodeTypedValue(
677 IXMLDOMDocument2 *iface,
678 VARIANT typedValue )
680 domdoc *This = impl_from_IXMLDOMDocument2( iface );
681 return IXMLDOMNode_put_nodeTypedValue( This->node, typedValue );
685 static HRESULT WINAPI domdoc_get_dataType(
686 IXMLDOMDocument2 *iface,
687 VARIANT* dataTypeName )
689 domdoc *This = impl_from_IXMLDOMDocument2( iface );
690 return IXMLDOMNode_get_dataType( This->node, dataTypeName );
694 static HRESULT WINAPI domdoc_put_dataType(
695 IXMLDOMDocument2 *iface,
696 BSTR dataTypeName )
698 domdoc *This = impl_from_IXMLDOMDocument2( iface );
699 return IXMLDOMNode_put_dataType( This->node, dataTypeName );
703 static HRESULT WINAPI domdoc_get_xml(
704 IXMLDOMDocument2 *iface,
705 BSTR* xmlString )
707 domdoc *This = impl_from_IXMLDOMDocument2( iface );
708 return IXMLDOMNode_get_xml( This->node, xmlString );
712 static HRESULT WINAPI domdoc_transformNode(
713 IXMLDOMDocument2 *iface,
714 IXMLDOMNode* styleSheet,
715 BSTR* xmlString )
717 domdoc *This = impl_from_IXMLDOMDocument2( iface );
718 return IXMLDOMNode_transformNode( This->node, styleSheet, xmlString );
722 static HRESULT WINAPI domdoc_selectNodes(
723 IXMLDOMDocument2 *iface,
724 BSTR queryString,
725 IXMLDOMNodeList** resultList )
727 domdoc *This = impl_from_IXMLDOMDocument2( iface );
728 return IXMLDOMNode_selectNodes( This->node, queryString, resultList );
732 static HRESULT WINAPI domdoc_selectSingleNode(
733 IXMLDOMDocument2 *iface,
734 BSTR queryString,
735 IXMLDOMNode** resultNode )
737 domdoc *This = impl_from_IXMLDOMDocument2( iface );
738 return IXMLDOMNode_selectSingleNode( This->node, queryString, resultNode );
742 static HRESULT WINAPI domdoc_get_parsed(
743 IXMLDOMDocument2 *iface,
744 VARIANT_BOOL* isParsed )
746 domdoc *This = impl_from_IXMLDOMDocument2( iface );
747 return IXMLDOMNode_get_parsed( This->node, isParsed );
751 static HRESULT WINAPI domdoc_get_namespaceURI(
752 IXMLDOMDocument2 *iface,
753 BSTR* namespaceURI )
755 domdoc *This = impl_from_IXMLDOMDocument2( iface );
756 return IXMLDOMNode_get_namespaceURI( This->node, namespaceURI );
760 static HRESULT WINAPI domdoc_get_prefix(
761 IXMLDOMDocument2 *iface,
762 BSTR* prefixString )
764 domdoc *This = impl_from_IXMLDOMDocument2( iface );
765 return IXMLDOMNode_get_prefix( This->node, prefixString );
769 static HRESULT WINAPI domdoc_get_baseName(
770 IXMLDOMDocument2 *iface,
771 BSTR* nameString )
773 domdoc *This = impl_from_IXMLDOMDocument2( iface );
774 return IXMLDOMNode_get_baseName( This->node, nameString );
778 static HRESULT WINAPI domdoc_transformNodeToObject(
779 IXMLDOMDocument2 *iface,
780 IXMLDOMNode* stylesheet,
781 VARIANT outputObject)
783 domdoc *This = impl_from_IXMLDOMDocument2( iface );
784 return IXMLDOMNode_transformNodeToObject( This->node, stylesheet, outputObject );
788 static HRESULT WINAPI domdoc_get_doctype(
789 IXMLDOMDocument2 *iface,
790 IXMLDOMDocumentType** documentType )
792 FIXME("\n");
793 return E_NOTIMPL;
797 static HRESULT WINAPI domdoc_get_implementation(
798 IXMLDOMDocument2 *iface,
799 IXMLDOMImplementation** impl )
801 FIXME("\n");
802 return E_NOTIMPL;
805 static HRESULT WINAPI domdoc_get_documentElement(
806 IXMLDOMDocument2 *iface,
807 IXMLDOMElement** DOMElement )
809 domdoc *This = impl_from_IXMLDOMDocument2( iface );
810 xmlDocPtr xmldoc = NULL;
811 xmlNodePtr root = NULL;
812 IXMLDOMNode *element_node;
813 HRESULT hr;
815 TRACE("%p %p\n", This, This->node);
817 if(!DOMElement)
818 return E_INVALIDARG;
820 *DOMElement = NULL;
822 xmldoc = get_doc( This );
824 root = xmlDocGetRootElement( xmldoc );
825 if ( !root )
826 return S_FALSE;
828 element_node = create_node( root );
829 if(!element_node) return S_FALSE;
831 hr = IXMLDOMNode_QueryInterface(element_node, &IID_IXMLDOMElement, (LPVOID*)DOMElement);
832 IXMLDOMNode_Release(element_node);
834 return hr;
838 static HRESULT WINAPI domdoc_documentElement(
839 IXMLDOMDocument2 *iface,
840 IXMLDOMElement* DOMElement )
842 FIXME("\n");
843 return E_NOTIMPL;
847 static HRESULT WINAPI domdoc_createElement(
848 IXMLDOMDocument2 *iface,
849 BSTR tagname,
850 IXMLDOMElement** element )
852 xmlNodePtr xmlnode;
853 domdoc *This = impl_from_IXMLDOMDocument2( iface );
854 xmlChar *xml_name;
855 IUnknown *elem_unk;
856 HRESULT hr;
858 TRACE("%p->(%s,%p)\n", iface, debugstr_w(tagname), element);
860 xml_name = xmlChar_from_wchar((WCHAR*)tagname);
861 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
863 TRACE("created xmlptr %p\n", xmlnode);
864 elem_unk = create_element(xmlnode, NULL);
865 HeapFree(GetProcessHeap(), 0, xml_name);
867 hr = IUnknown_QueryInterface(elem_unk, &IID_IXMLDOMElement, (void **)element);
868 IUnknown_Release(elem_unk);
869 TRACE("returning %p\n", *element);
870 return hr;
874 static HRESULT WINAPI domdoc_createDocumentFragment(
875 IXMLDOMDocument2 *iface,
876 IXMLDOMDocumentFragment** docFrag )
878 FIXME("\n");
879 return E_NOTIMPL;
883 static HRESULT WINAPI domdoc_createTextNode(
884 IXMLDOMDocument2 *iface,
885 BSTR data,
886 IXMLDOMText** text )
888 domdoc *This = impl_from_IXMLDOMDocument2( iface );
889 xmlNodePtr xmlnode;
890 xmlChar *xml_content;
892 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), text);
894 if(!text)
895 return E_INVALIDARG;
897 *text = NULL;
899 xml_content = xmlChar_from_wchar((WCHAR*)data);
900 xmlnode = xmlNewText(xml_content);
901 HeapFree(GetProcessHeap(), 0, xml_content);
903 if(!xmlnode)
904 return E_FAIL;
906 xmlnode->doc = get_doc( This );
908 *text = (IXMLDOMText*)create_text(xmlnode);
910 return S_OK;
914 static HRESULT WINAPI domdoc_createComment(
915 IXMLDOMDocument2 *iface,
916 BSTR data,
917 IXMLDOMComment** comment )
919 domdoc *This = impl_from_IXMLDOMDocument2( iface );
920 xmlNodePtr xmlnode;
921 xmlChar *xml_content;
923 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), comment);
925 if(!comment)
926 return E_INVALIDARG;
928 *comment = NULL;
930 xml_content = xmlChar_from_wchar((WCHAR*)data);
931 xmlnode = xmlNewComment(xml_content);
932 HeapFree(GetProcessHeap(), 0, xml_content);
934 if(!xmlnode)
935 return E_FAIL;
937 xmlnode->doc = get_doc( This );
939 *comment = (IXMLDOMComment*)create_comment(xmlnode);
941 return S_OK;
945 static HRESULT WINAPI domdoc_createCDATASection(
946 IXMLDOMDocument2 *iface,
947 BSTR data,
948 IXMLDOMCDATASection** cdata )
950 domdoc *This = impl_from_IXMLDOMDocument2( iface );
951 xmlNodePtr xmlnode;
952 xmlChar *xml_content;
954 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), comment);
956 if(!cdata)
957 return E_INVALIDARG;
959 *cdata = NULL;
961 xml_content = xmlChar_from_wchar((WCHAR*)data);
962 xmlnode = xmlNewCDataBlock(get_doc( This ), xml_content, strlen( (char*)xml_content) );
963 HeapFree(GetProcessHeap(), 0, xml_content);
965 if(!xmlnode)
966 return E_FAIL;
968 xmlnode->doc = get_doc( This );
970 *cdata = (IXMLDOMCDATASection*)create_cdata(xmlnode);
972 return S_OK;
976 static HRESULT WINAPI domdoc_createProcessingInstruction(
977 IXMLDOMDocument2 *iface,
978 BSTR target,
979 BSTR data,
980 IXMLDOMProcessingInstruction** pi )
982 #ifdef HAVE_XMLNEWDOCPI
983 xmlNodePtr xmlnode;
984 domdoc *This = impl_from_IXMLDOMDocument2( iface );
985 xmlChar *xml_target, *xml_content;
987 TRACE("%p->(%s %s %p)\n", iface, debugstr_w(target), debugstr_w(data), pi);
989 if(!pi)
990 return E_INVALIDARG;
992 if(!target || lstrlenW(target) == 0)
993 return E_FAIL;
995 xml_target = xmlChar_from_wchar((WCHAR*)target);
996 xml_content = xmlChar_from_wchar((WCHAR*)data);
998 xmlnode = xmlNewDocPI(get_doc(This), xml_target, xml_content);
999 TRACE("created xmlptr %p\n", xmlnode);
1000 *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode);
1002 HeapFree(GetProcessHeap(), 0, xml_content);
1003 HeapFree(GetProcessHeap(), 0, xml_target);
1005 return S_OK;
1006 #else
1007 FIXME("Libxml 2.6.15 or greater required.\n");
1008 return E_NOTIMPL;
1009 #endif
1013 static HRESULT WINAPI domdoc_createAttribute(
1014 IXMLDOMDocument2 *iface,
1015 BSTR name,
1016 IXMLDOMAttribute** attribute )
1018 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1019 xmlNodePtr xmlnode;
1020 xmlChar *xml_name;
1022 TRACE("%p->(%s %p)\n", iface, debugstr_w(name), attribute);
1024 if(!attribute)
1025 return E_INVALIDARG;
1027 *attribute = NULL;
1029 xml_name = xmlChar_from_wchar((WCHAR*)name);
1030 xmlnode = (xmlNode *)xmlNewProp(NULL, xml_name, NULL);
1031 HeapFree(GetProcessHeap(), 0, xml_name);
1033 if(!xmlnode)
1034 return E_FAIL;
1036 xmlnode->doc = get_doc( This );
1038 *attribute = (IXMLDOMAttribute*)create_attribute(xmlnode);
1040 return S_OK;
1044 static HRESULT WINAPI domdoc_createEntityReference(
1045 IXMLDOMDocument2 *iface,
1046 BSTR name,
1047 IXMLDOMEntityReference** entityRef )
1049 FIXME("\n");
1050 return E_NOTIMPL;
1054 static HRESULT WINAPI domdoc_getElementsByTagName(
1055 IXMLDOMDocument2 *iface,
1056 BSTR tagName,
1057 IXMLDOMNodeList** resultList )
1059 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1060 LPWSTR szPattern;
1061 HRESULT hr;
1062 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1064 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(2+lstrlenW(tagName)+1));
1065 szPattern[0] = szPattern[1] = '/';
1066 lstrcpyW(szPattern + 2, tagName);
1068 hr = queryresult_create((xmlNodePtr)get_doc(This), szPattern, resultList);
1069 HeapFree(GetProcessHeap(), 0, szPattern);
1071 return hr;
1074 static DOMNodeType get_node_type(VARIANT Type)
1076 if(V_VT(&Type) == VT_I4)
1077 return V_I4(&Type);
1079 FIXME("Unsupported variant type %x\n", V_VT(&Type));
1080 return 0;
1083 static HRESULT WINAPI domdoc_createNode(
1084 IXMLDOMDocument2 *iface,
1085 VARIANT Type,
1086 BSTR name,
1087 BSTR namespaceURI,
1088 IXMLDOMNode** node )
1090 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1091 DOMNodeType node_type;
1092 xmlNodePtr xmlnode = NULL;
1093 xmlChar *xml_name;
1095 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
1097 node_type = get_node_type(Type);
1098 TRACE("node_type %d\n", node_type);
1100 xml_name = xmlChar_from_wchar((WCHAR*)name);
1102 switch(node_type)
1104 case NODE_ELEMENT:
1105 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
1106 *node = create_node(xmlnode);
1107 TRACE("created %p\n", xmlnode);
1108 break;
1110 default:
1111 FIXME("unhandled node type %d\n", node_type);
1112 break;
1115 HeapFree(GetProcessHeap(), 0, xml_name);
1117 if(xmlnode && *node)
1118 return S_OK;
1120 return E_FAIL;
1123 static HRESULT WINAPI domdoc_nodeFromID(
1124 IXMLDOMDocument2 *iface,
1125 BSTR idString,
1126 IXMLDOMNode** node )
1128 FIXME("\n");
1129 return E_NOTIMPL;
1132 static xmlDocPtr doparse( char *ptr, int len )
1134 #ifdef HAVE_XMLREADMEMORY
1136 * use xmlReadMemory if possible so we can suppress
1137 * writing errors to stderr
1139 return xmlReadMemory( ptr, len, NULL, NULL,
1140 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
1141 #else
1142 return xmlParseMemory( ptr, len );
1143 #endif
1146 static xmlDocPtr doread( LPWSTR filename )
1148 xmlDocPtr xmldoc = NULL;
1149 HRESULT hr;
1150 IBindCtx *pbc;
1151 IStream *stream, *memstream;
1152 WCHAR url[INTERNET_MAX_URL_LENGTH];
1153 BYTE buf[4096];
1154 DWORD read, written;
1156 TRACE("%s\n", debugstr_w( filename ));
1158 if(!PathIsURLW(filename))
1160 WCHAR fullpath[MAX_PATH];
1161 DWORD needed = sizeof(url)/sizeof(WCHAR);
1163 if(!PathSearchAndQualifyW(filename, fullpath, sizeof(fullpath)/sizeof(WCHAR)))
1165 WARN("can't find path\n");
1166 return NULL;
1169 if(FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0)))
1171 ERR("can't create url from path\n");
1172 return NULL;
1174 filename = url;
1177 hr = CreateBindCtx(0, &pbc);
1178 if(SUCCEEDED(hr))
1180 hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&domdoc_bsc.lpVtbl, NULL, 0);
1181 if(SUCCEEDED(hr))
1183 IMoniker *moniker;
1184 hr = CreateURLMoniker(NULL, filename, &moniker);
1185 if(SUCCEEDED(hr))
1187 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
1188 IMoniker_Release(moniker);
1191 IBindCtx_Release(pbc);
1193 if(FAILED(hr))
1194 return NULL;
1196 hr = CreateStreamOnHGlobal(NULL, TRUE, &memstream);
1197 if(FAILED(hr))
1199 IStream_Release(stream);
1200 return NULL;
1205 IStream_Read(stream, buf, sizeof(buf), &read);
1206 hr = IStream_Write(memstream, buf, read, &written);
1207 } while(SUCCEEDED(hr) && written != 0 && read != 0);
1209 if(SUCCEEDED(hr))
1211 HGLOBAL hglobal;
1212 hr = GetHGlobalFromStream(memstream, &hglobal);
1213 if(SUCCEEDED(hr))
1215 DWORD len = GlobalSize(hglobal);
1216 char *ptr = GlobalLock(hglobal);
1217 if(len != 0)
1218 xmldoc = doparse( ptr, len );
1219 GlobalUnlock(hglobal);
1222 IStream_Release(memstream);
1223 IStream_Release(stream);
1224 return xmldoc;
1227 static HRESULT WINAPI domdoc_load(
1228 IXMLDOMDocument2 *iface,
1229 VARIANT xmlSource,
1230 VARIANT_BOOL* isSuccessful )
1232 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1233 LPWSTR filename = NULL;
1234 xmlDocPtr xmldoc = NULL;
1235 HRESULT hr = S_FALSE;
1236 IXMLDOMDocument2 *pNewDoc = NULL;
1237 IStream *pStream = NULL;
1239 TRACE("type %d\n", V_VT(&xmlSource) );
1241 *isSuccessful = VARIANT_FALSE;
1243 assert( This->node );
1245 attach_xmlnode(This->node, NULL);
1247 switch( V_VT(&xmlSource) )
1249 case VT_BSTR:
1250 filename = V_BSTR(&xmlSource);
1251 break;
1252 case VT_UNKNOWN:
1253 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IXMLDOMDocument2, (void**)&pNewDoc);
1254 if(hr == S_OK)
1256 if(pNewDoc)
1258 domdoc *newDoc = impl_from_IXMLDOMDocument2( pNewDoc );
1259 xmldoc = xmlCopyDoc(get_doc(newDoc), 1);
1260 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1262 *isSuccessful = VARIANT_TRUE;
1264 return S_OK;
1267 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IStream, (void**)&pStream);
1268 if(hr == S_OK)
1270 IPersistStream *pDocStream;
1271 hr = IUnknown_QueryInterface(iface, &IID_IPersistStream, (void**)&pDocStream);
1272 if(hr == S_OK)
1274 hr = xmldoc_IPersistStream_Load(pDocStream, pStream);
1275 IStream_Release(pStream);
1276 if(hr == S_OK)
1278 *isSuccessful = VARIANT_TRUE;
1280 TRACE("Using ID_IStream to load Document\n");
1281 return S_OK;
1283 else
1285 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr);
1288 else
1290 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr);
1293 else
1295 /* ISequentialStream */
1296 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr, pNewDoc, V_UNKNOWN(&xmlSource)->lpVtbl);
1298 break;
1299 default:
1300 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource));
1303 TRACE("filename (%s)\n", debugstr_w(filename));
1305 if ( filename )
1307 xmldoc = doread( filename );
1309 if ( !xmldoc )
1310 This->error = E_FAIL;
1311 else
1313 hr = This->error = S_OK;
1314 *isSuccessful = VARIANT_TRUE;
1318 if(!xmldoc)
1319 xmldoc = xmlNewDoc(NULL);
1321 xmldoc->_private = 0;
1322 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1324 TRACE("ret (%d)\n", hr);
1326 return hr;
1330 static HRESULT WINAPI domdoc_get_readyState(
1331 IXMLDOMDocument2 *iface,
1332 long* value )
1334 FIXME("\n");
1335 return E_NOTIMPL;
1339 static HRESULT WINAPI domdoc_get_parseError(
1340 IXMLDOMDocument2 *iface,
1341 IXMLDOMParseError** errorObj )
1343 BSTR error_string = NULL;
1344 static const WCHAR err[] = {'e','r','r','o','r',0};
1345 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1347 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1349 if(This->error)
1350 error_string = SysAllocString(err);
1352 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1353 if(!*errorObj) return E_OUTOFMEMORY;
1354 return S_OK;
1358 static HRESULT WINAPI domdoc_get_url(
1359 IXMLDOMDocument2 *iface,
1360 BSTR* urlString )
1362 FIXME("\n");
1363 return E_NOTIMPL;
1367 static HRESULT WINAPI domdoc_get_async(
1368 IXMLDOMDocument2 *iface,
1369 VARIANT_BOOL* isAsync )
1371 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1373 TRACE("%p <- %d\n", isAsync, This->async);
1374 *isAsync = This->async;
1375 return S_OK;
1379 static HRESULT WINAPI domdoc_put_async(
1380 IXMLDOMDocument2 *iface,
1381 VARIANT_BOOL isAsync )
1383 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1385 TRACE("%d\n", isAsync);
1386 This->async = isAsync;
1387 return S_OK;
1391 static HRESULT WINAPI domdoc_abort(
1392 IXMLDOMDocument2 *iface )
1394 FIXME("\n");
1395 return E_NOTIMPL;
1399 static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1401 UINT len, blen = SysStringLen( bstr );
1402 LPSTR str;
1404 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1405 str = HeapAlloc( GetProcessHeap(), 0, len );
1406 if ( !str )
1407 return FALSE;
1408 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1409 *plen = len;
1410 *pstr = str;
1411 return TRUE;
1414 static HRESULT WINAPI domdoc_loadXML(
1415 IXMLDOMDocument2 *iface,
1416 BSTR bstrXML,
1417 VARIANT_BOOL* isSuccessful )
1419 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1420 xmlDocPtr xmldoc = NULL;
1421 char *str;
1422 int len;
1423 HRESULT hr = S_FALSE;
1425 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1427 assert ( This->node );
1429 attach_xmlnode( This->node, NULL );
1431 if ( isSuccessful )
1433 *isSuccessful = VARIANT_FALSE;
1435 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1437 xmldoc = doparse( str, len );
1438 HeapFree( GetProcessHeap(), 0, str );
1439 if ( !xmldoc )
1440 This->error = E_FAIL;
1441 else
1443 hr = This->error = S_OK;
1444 *isSuccessful = VARIANT_TRUE;
1448 if(!xmldoc)
1449 xmldoc = xmlNewDoc(NULL);
1451 xmldoc->_private = 0;
1452 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1454 return hr;
1458 static HRESULT WINAPI domdoc_save(
1459 IXMLDOMDocument2 *iface,
1460 VARIANT destination )
1462 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1463 HANDLE handle;
1464 xmlChar *mem;
1465 int size;
1466 HRESULT ret = S_OK;
1467 DWORD written;
1469 TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
1470 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1472 if(V_VT(&destination) != VT_BSTR)
1474 FIXME("Unhandled vt %x\n", V_VT(&destination));
1475 return S_FALSE;
1478 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1479 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1480 if( handle == INVALID_HANDLE_VALUE )
1482 WARN("failed to create file\n");
1483 return S_FALSE;
1486 xmlDocDumpMemory(get_doc(This), &mem, &size);
1487 if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size)
1489 WARN("write error\n");
1490 ret = S_FALSE;
1493 xmlFree(mem);
1494 CloseHandle(handle);
1495 return ret;
1498 static HRESULT WINAPI domdoc_get_validateOnParse(
1499 IXMLDOMDocument2 *iface,
1500 VARIANT_BOOL* isValidating )
1502 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1504 TRACE("%p <- %d\n", isValidating, This->validating);
1505 *isValidating = This->validating;
1506 return S_OK;
1510 static HRESULT WINAPI domdoc_put_validateOnParse(
1511 IXMLDOMDocument2 *iface,
1512 VARIANT_BOOL isValidating )
1514 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1516 TRACE("%d\n", isValidating);
1517 This->validating = isValidating;
1518 return S_OK;
1522 static HRESULT WINAPI domdoc_get_resolveExternals(
1523 IXMLDOMDocument2 *iface,
1524 VARIANT_BOOL* isResolving )
1526 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1528 TRACE("%p <- %d\n", isResolving, This->resolving);
1529 *isResolving = This->resolving;
1530 return S_OK;
1534 static HRESULT WINAPI domdoc_put_resolveExternals(
1535 IXMLDOMDocument2 *iface,
1536 VARIANT_BOOL isResolving )
1538 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1540 TRACE("%d\n", isResolving);
1541 This->resolving = isResolving;
1542 return S_OK;
1546 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1547 IXMLDOMDocument2 *iface,
1548 VARIANT_BOOL* isPreserving )
1550 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1552 TRACE("%p <- %d\n", isPreserving, This->preserving);
1553 *isPreserving = This->preserving;
1554 return S_OK;
1558 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1559 IXMLDOMDocument2 *iface,
1560 VARIANT_BOOL isPreserving )
1562 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1564 TRACE("%d\n", isPreserving);
1565 This->preserving = isPreserving;
1566 return S_OK;
1570 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1571 IXMLDOMDocument2 *iface,
1572 VARIANT readyStateChangeSink )
1574 FIXME("\n");
1575 return E_NOTIMPL;
1579 static HRESULT WINAPI domdoc_put_onDataAvailable(
1580 IXMLDOMDocument2 *iface,
1581 VARIANT onDataAvailableSink )
1583 FIXME("\n");
1584 return E_NOTIMPL;
1587 static HRESULT WINAPI domdoc_put_onTransformNode(
1588 IXMLDOMDocument2 *iface,
1589 VARIANT onTransformNodeSink )
1591 FIXME("\n");
1592 return E_NOTIMPL;
1595 static HRESULT WINAPI domdoc_get_namespaces(
1596 IXMLDOMDocument2* iface,
1597 IXMLDOMSchemaCollection** schemaCollection )
1599 FIXME("\n");
1600 return E_NOTIMPL;
1603 static HRESULT WINAPI domdoc_get_schemas(
1604 IXMLDOMDocument2* iface,
1605 VARIANT* var1 )
1607 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1608 HRESULT hr = S_FALSE;
1609 IXMLDOMSchemaCollection *cur_schema = This->schema;
1611 TRACE("(%p)->(%p)\n", This, var1);
1613 VariantInit(var1); /* Test shows we don't call VariantClear here */
1614 V_VT(var1) = VT_NULL;
1616 if(cur_schema)
1618 hr = IXMLDOMSchemaCollection_QueryInterface(cur_schema, &IID_IDispatch, (void**)&V_DISPATCH(var1));
1619 if(SUCCEEDED(hr))
1620 V_VT(var1) = VT_DISPATCH;
1622 return hr;
1625 static HRESULT WINAPI domdoc_putref_schemas(
1626 IXMLDOMDocument2* iface,
1627 VARIANT var1)
1629 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1630 HRESULT hr = E_FAIL;
1631 IXMLDOMSchemaCollection *new_schema = NULL;
1633 FIXME("(%p): semi-stub\n", This);
1634 switch(V_VT(&var1))
1636 case VT_UNKNOWN:
1637 hr = IUnknown_QueryInterface(V_UNKNOWN(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1638 break;
1640 case VT_DISPATCH:
1641 hr = IDispatch_QueryInterface(V_DISPATCH(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1642 break;
1644 case VT_NULL:
1645 case VT_EMPTY:
1646 hr = S_OK;
1647 break;
1649 default:
1650 WARN("Can't get schema from vt %x\n", V_VT(&var1));
1653 if(SUCCEEDED(hr))
1655 IXMLDOMSchemaCollection *old_schema = InterlockedExchangePointer((void**)&This->schema, new_schema);
1656 if(old_schema) IXMLDOMSchemaCollection_Release(old_schema);
1659 return hr;
1662 static HRESULT WINAPI domdoc_validate(
1663 IXMLDOMDocument2* iface,
1664 IXMLDOMParseError** err)
1666 FIXME("\n");
1667 return E_NOTIMPL;
1670 static HRESULT WINAPI domdoc_setProperty(
1671 IXMLDOMDocument2* iface,
1672 BSTR p,
1673 VARIANT var)
1675 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1677 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1679 VARIANT varStr;
1680 HRESULT hr;
1681 BSTR bstr;
1683 V_VT(&varStr) = VT_EMPTY;
1684 if (V_VT(&var) != VT_BSTR)
1686 if (FAILED(hr = VariantChangeType(&varStr, &var, 0, VT_BSTR)))
1687 return hr;
1688 bstr = V_BSTR(&varStr);
1690 else
1691 bstr = V_BSTR(&var);
1693 hr = S_OK;
1694 if (lstrcmpiW(bstr, SZ_VALUE_XPATH) == 0)
1695 This->bUseXPath = TRUE;
1696 else if (lstrcmpiW(bstr, SZ_VALUE_XSLPATTERN) == 0)
1697 This->bUseXPath = FALSE;
1698 else
1699 hr = E_FAIL;
1701 VariantClear(&varStr);
1702 return hr;
1705 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1706 return E_FAIL;
1709 static HRESULT WINAPI domdoc_getProperty(
1710 IXMLDOMDocument2* iface,
1711 BSTR p,
1712 VARIANT* var)
1714 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1716 if (var == NULL)
1717 return E_INVALIDARG;
1718 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1720 V_VT(var) = VT_BSTR;
1721 if (This->bUseXPath)
1722 V_BSTR(var) = SysAllocString(SZ_VALUE_XPATH);
1723 else
1724 V_BSTR(var) = SysAllocString(SZ_VALUE_XSLPATTERN);
1725 return S_OK;
1728 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1729 return E_FAIL;
1732 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl =
1734 domdoc_QueryInterface,
1735 domdoc_AddRef,
1736 domdoc_Release,
1737 domdoc_GetTypeInfoCount,
1738 domdoc_GetTypeInfo,
1739 domdoc_GetIDsOfNames,
1740 domdoc_Invoke,
1741 domdoc_get_nodeName,
1742 domdoc_get_nodeValue,
1743 domdoc_put_nodeValue,
1744 domdoc_get_nodeType,
1745 domdoc_get_parentNode,
1746 domdoc_get_childNodes,
1747 domdoc_get_firstChild,
1748 domdoc_get_lastChild,
1749 domdoc_get_previousSibling,
1750 domdoc_get_nextSibling,
1751 domdoc_get_attributes,
1752 domdoc_insertBefore,
1753 domdoc_replaceChild,
1754 domdoc_removeChild,
1755 domdoc_appendChild,
1756 domdoc_hasChildNodes,
1757 domdoc_get_ownerDocument,
1758 domdoc_cloneNode,
1759 domdoc_get_nodeTypeString,
1760 domdoc_get_text,
1761 domdoc_put_text,
1762 domdoc_get_specified,
1763 domdoc_get_definition,
1764 domdoc_get_nodeTypedValue,
1765 domdoc_put_nodeTypedValue,
1766 domdoc_get_dataType,
1767 domdoc_put_dataType,
1768 domdoc_get_xml,
1769 domdoc_transformNode,
1770 domdoc_selectNodes,
1771 domdoc_selectSingleNode,
1772 domdoc_get_parsed,
1773 domdoc_get_namespaceURI,
1774 domdoc_get_prefix,
1775 domdoc_get_baseName,
1776 domdoc_transformNodeToObject,
1777 domdoc_get_doctype,
1778 domdoc_get_implementation,
1779 domdoc_get_documentElement,
1780 domdoc_documentElement,
1781 domdoc_createElement,
1782 domdoc_createDocumentFragment,
1783 domdoc_createTextNode,
1784 domdoc_createComment,
1785 domdoc_createCDATASection,
1786 domdoc_createProcessingInstruction,
1787 domdoc_createAttribute,
1788 domdoc_createEntityReference,
1789 domdoc_getElementsByTagName,
1790 domdoc_createNode,
1791 domdoc_nodeFromID,
1792 domdoc_load,
1793 domdoc_get_readyState,
1794 domdoc_get_parseError,
1795 domdoc_get_url,
1796 domdoc_get_async,
1797 domdoc_put_async,
1798 domdoc_abort,
1799 domdoc_loadXML,
1800 domdoc_save,
1801 domdoc_get_validateOnParse,
1802 domdoc_put_validateOnParse,
1803 domdoc_get_resolveExternals,
1804 domdoc_put_resolveExternals,
1805 domdoc_get_preserveWhiteSpace,
1806 domdoc_put_preserveWhiteSpace,
1807 domdoc_put_onReadyStateChange,
1808 domdoc_put_onDataAvailable,
1809 domdoc_put_onTransformNode,
1810 domdoc_get_namespaces,
1811 domdoc_get_schemas,
1812 domdoc_putref_schemas,
1813 domdoc_validate,
1814 domdoc_setProperty,
1815 domdoc_getProperty
1818 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1820 domdoc *doc;
1821 HRESULT hr;
1822 xmlDocPtr xmldoc;
1824 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1826 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
1827 if( !doc )
1828 return E_OUTOFMEMORY;
1830 doc->lpVtbl = &domdoc_vtbl;
1831 doc->lpvtblIPersistStream = &xmldoc_IPersistStream_VTable;
1832 doc->ref = 1;
1833 doc->async = 0;
1834 doc->validating = 0;
1835 doc->resolving = 0;
1836 doc->preserving = 0;
1837 doc->bUseXPath = FALSE;
1838 doc->error = S_OK;
1839 doc->schema = NULL;
1840 doc->stream = NULL;
1842 xmldoc = xmlNewDoc(NULL);
1843 if(!xmldoc)
1845 HeapFree(GetProcessHeap(), 0, doc);
1846 return E_OUTOFMEMORY;
1849 xmldoc->_private = 0;
1851 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
1852 if(!doc->node_unk)
1854 xmlFreeDoc(xmldoc);
1855 HeapFree(GetProcessHeap(), 0, doc);
1856 return E_FAIL;
1859 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
1860 if(FAILED(hr))
1862 IUnknown_Release(doc->node_unk);
1863 HeapFree( GetProcessHeap(), 0, doc );
1864 return E_FAIL;
1866 /* The ref on doc->node is actually looped back into this object, so release it */
1867 IXMLDOMNode_Release(doc->node);
1869 *ppObj = &doc->lpVtbl;
1871 TRACE("returning iface %p\n", *ppObj);
1872 return S_OK;
1875 #else
1877 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1879 MESSAGE("This program tried to use a DOMDocument object, but\n"
1880 "libxml2 support was not present at compile time.\n");
1881 return E_NOTIMPL;
1884 #endif