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
40 #include "wine/debug.h"
42 #include "msxml_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
48 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};
49 static const WCHAR SZ_VALUE_XPATH[] = {'X','P','a','t','h',0};
50 static const WCHAR SZ_VALUE_XSLPATTERN[] = {'X','S','L','P','a','t','t','e','r','n',0};
53 const struct IBindStatusCallbackVtbl *lpVtbl;
56 static HRESULT WINAPI bsc_QueryInterface(
57 IBindStatusCallback *iface,
61 if (IsEqualGUID(riid, &IID_IUnknown) ||
62 IsEqualGUID(riid, &IID_IBindStatusCallback))
64 IBindStatusCallback_AddRef( iface );
69 FIXME("interface %s not implemented\n", debugstr_guid(riid));
73 static ULONG WINAPI bsc_AddRef(
74 IBindStatusCallback *iface )
79 static ULONG WINAPI bsc_Release(
80 IBindStatusCallback *iface )
85 static HRESULT WINAPI bsc_OnStartBinding(
86 IBindStatusCallback* iface,
93 static HRESULT WINAPI bsc_GetPriority(
94 IBindStatusCallback* iface,
100 static HRESULT WINAPI bsc_OnLowResource(
101 IBindStatusCallback* iface,
107 static HRESULT WINAPI bsc_OnProgress(
108 IBindStatusCallback* iface,
112 LPCWSTR szStatusText)
117 static HRESULT WINAPI bsc_OnStopBinding(
118 IBindStatusCallback* iface,
125 static HRESULT WINAPI bsc_GetBindInfo(
126 IBindStatusCallback* iface,
130 *grfBINDF = BINDF_RESYNCHRONIZE;
135 static HRESULT WINAPI bsc_OnDataAvailable(
136 IBindStatusCallback* iface,
139 FORMATETC* pformatetc,
145 static HRESULT WINAPI bsc_OnObjectAvailable(
146 IBindStatusCallback* iface,
153 static const struct IBindStatusCallbackVtbl bsc_vtbl =
165 bsc_OnObjectAvailable
168 static bsc domdoc_bsc = { &bsc_vtbl };
170 typedef struct _domdoc
172 const struct IXMLDOMDocument2Vtbl *lpVtbl;
173 const struct IPersistStreamVtbl *lpvtblIPersistStream;
174 const struct IObjectWithSiteVtbl *lpvtblIObjectWithSite;
175 const struct IObjectSafetyVtbl *lpvtblIObjectSafety;
178 VARIANT_BOOL validating;
179 VARIANT_BOOL resolving;
180 VARIANT_BOOL preserving;
184 IXMLDOMSchemaCollection *schema;
198 LONG xmldoc_add_ref(xmlDocPtr doc)
200 LONG ref = InterlockedIncrement((LONG*)&doc->_private);
205 LONG xmldoc_release(xmlDocPtr doc)
207 LONG ref = InterlockedDecrement((LONG*)&doc->_private);
211 TRACE("freeing docptr %p\n", doc);
218 static inline domdoc *impl_from_IXMLDOMDocument2( IXMLDOMDocument2 *iface )
220 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpVtbl));
223 static inline xmlDocPtr get_doc( domdoc *This )
225 return (xmlDocPtr) xmlNodePtr_from_domnode( This->node, XML_DOCUMENT_NODE );
228 static inline domdoc *impl_from_IPersistStream(IPersistStream *iface)
230 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIPersistStream));
233 static inline domdoc *impl_from_IObjectWithSite(IObjectWithSite *iface)
235 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIObjectWithSite));
238 static inline domdoc *impl_from_IObjectSafety(IObjectSafety *iface)
240 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIObjectSafety));
244 /************************************************************************
245 * xmldoc implementation of IPersistStream.
247 static HRESULT WINAPI xmldoc_IPersistStream_QueryInterface(
248 IPersistStream *iface, REFIID riid, LPVOID *ppvObj)
250 domdoc *this = impl_from_IPersistStream(iface);
251 return IXMLDocument_QueryInterface((IXMLDocument *)this, riid, ppvObj);
254 static ULONG WINAPI xmldoc_IPersistStream_AddRef(
255 IPersistStream *iface)
257 domdoc *this = impl_from_IPersistStream(iface);
258 return IXMLDocument_AddRef((IXMLDocument *)this);
261 static ULONG WINAPI xmldoc_IPersistStream_Release(
262 IPersistStream *iface)
264 domdoc *this = impl_from_IPersistStream(iface);
265 return IXMLDocument_Release((IXMLDocument *)this);
268 static HRESULT WINAPI xmldoc_IPersistStream_GetClassID(
269 IPersistStream *iface, CLSID *classid)
271 TRACE("(%p,%p): stub!\n", iface, classid);
276 *classid = CLSID_DOMDocument2;
281 static HRESULT WINAPI xmldoc_IPersistStream_IsDirty(
282 IPersistStream *iface)
284 domdoc *This = impl_from_IPersistStream(iface);
286 FIXME("(%p->%p): stub!\n", iface, This);
291 static HRESULT WINAPI xmldoc_IPersistStream_Load(
292 IPersistStream *iface, LPSTREAM pStm)
294 domdoc *This = impl_from_IPersistStream(iface);
297 DWORD read, written, len;
300 xmlDocPtr xmldoc = NULL;
302 TRACE("(%p, %p)\n", iface, pStm);
307 hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
313 IStream_Read(pStm, buf, sizeof(buf), &read);
314 hr = IStream_Write(This->stream, buf, read, &written);
315 } while(SUCCEEDED(hr) && written != 0 && read != 0);
319 ERR("Failed to copy stream\n");
323 hr = GetHGlobalFromStream(This->stream, &hglobal);
327 len = GlobalSize(hglobal);
328 ptr = GlobalLock(hglobal);
330 xmldoc = parse_xml(ptr, len);
331 GlobalUnlock(hglobal);
335 ERR("Failed to parse xml\n");
339 attach_xmlnode( This->node, (xmlNodePtr)xmldoc );
344 static HRESULT WINAPI xmldoc_IPersistStream_Save(
345 IPersistStream *iface, LPSTREAM pStm, BOOL fClearDirty)
347 FIXME("(%p, %p, %d): stub!\n", iface, pStm, fClearDirty);
351 static HRESULT WINAPI xmldoc_IPersistStream_GetSizeMax(
352 IPersistStream *iface, ULARGE_INTEGER *pcbSize)
354 TRACE("(%p, %p): stub!\n", iface, pcbSize);
358 static const IPersistStreamVtbl xmldoc_IPersistStream_VTable =
360 xmldoc_IPersistStream_QueryInterface,
361 xmldoc_IPersistStream_AddRef,
362 xmldoc_IPersistStream_Release,
363 xmldoc_IPersistStream_GetClassID,
364 xmldoc_IPersistStream_IsDirty,
365 xmldoc_IPersistStream_Load,
366 xmldoc_IPersistStream_Save,
367 xmldoc_IPersistStream_GetSizeMax,
370 static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument2 *iface, REFIID riid, void** ppvObject )
372 domdoc *This = impl_from_IXMLDOMDocument2( iface );
374 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
378 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
379 IsEqualGUID( riid, &IID_IDispatch ) ||
380 IsEqualGUID( riid, &IID_IXMLDOMDocument ) ||
381 IsEqualGUID( riid, &IID_IXMLDOMDocument2 ) )
385 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
387 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
389 else if (IsEqualGUID(&IID_IPersistStream, riid))
391 *ppvObject = (IPersistStream*)&(This->lpvtblIPersistStream);
393 else if (IsEqualGUID(&IID_IObjectWithSite, riid))
395 *ppvObject = (IObjectWithSite*)&(This->lpvtblIObjectWithSite);
397 else if(IsEqualGUID(&IID_IRunnableObject, riid))
399 TRACE("IID_IRunnableObject not supported returning NULL\n");
400 return E_NOINTERFACE;
404 FIXME("interface %s not implemented\n", debugstr_guid(riid));
405 return E_NOINTERFACE;
408 IXMLDOMDocument_AddRef( iface );
414 static ULONG WINAPI domdoc_AddRef(
415 IXMLDOMDocument2 *iface )
417 domdoc *This = impl_from_IXMLDOMDocument2( iface );
418 TRACE("%p\n", This );
419 return InterlockedIncrement( &This->ref );
423 static ULONG WINAPI domdoc_Release(
424 IXMLDOMDocument2 *iface )
426 domdoc *This = impl_from_IXMLDOMDocument2( iface );
429 TRACE("%p\n", This );
431 ref = InterlockedDecrement( &This->ref );
435 IUnknown_Release( This->site );
436 IUnknown_Release( This->node_unk );
437 if(This->schema) IXMLDOMSchemaCollection_Release( This->schema );
438 if (This->stream) IStream_Release(This->stream);
439 HeapFree( GetProcessHeap(), 0, This );
445 static HRESULT WINAPI domdoc_GetTypeInfoCount( IXMLDOMDocument2 *iface, UINT* pctinfo )
447 domdoc *This = impl_from_IXMLDOMDocument2( iface );
449 TRACE("(%p)->(%p)\n", This, pctinfo);
456 static HRESULT WINAPI domdoc_GetTypeInfo(
457 IXMLDOMDocument2 *iface,
458 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
460 domdoc *This = impl_from_IXMLDOMDocument2( iface );
463 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
465 hr = get_typeinfo(IXMLDOMDocument2_tid, ppTInfo);
470 static HRESULT WINAPI domdoc_GetIDsOfNames(
471 IXMLDOMDocument2 *iface,
478 domdoc *This = impl_from_IXMLDOMDocument2( iface );
482 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
485 if(!rgszNames || cNames == 0 || !rgDispId)
488 hr = get_typeinfo(IXMLDOMDocument2_tid, &typeinfo);
491 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
492 ITypeInfo_Release(typeinfo);
499 static HRESULT WINAPI domdoc_Invoke(
500 IXMLDOMDocument2 *iface,
505 DISPPARAMS* pDispParams,
507 EXCEPINFO* pExcepInfo,
510 domdoc *This = impl_from_IXMLDOMDocument2( iface );
514 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
515 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
517 hr = get_typeinfo(IXMLDOMDocument2_tid, &typeinfo);
520 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
521 pVarResult, pExcepInfo, puArgErr);
522 ITypeInfo_Release(typeinfo);
529 static HRESULT WINAPI domdoc_get_nodeName(
530 IXMLDOMDocument2 *iface,
533 domdoc *This = impl_from_IXMLDOMDocument2( iface );
534 return IXMLDOMNode_get_nodeName( This->node, name );
538 static HRESULT WINAPI domdoc_get_nodeValue(
539 IXMLDOMDocument2 *iface,
542 domdoc *This = impl_from_IXMLDOMDocument2( iface );
543 return IXMLDOMNode_get_nodeValue( This->node, value );
547 static HRESULT WINAPI domdoc_put_nodeValue(
548 IXMLDOMDocument2 *iface,
551 domdoc *This = impl_from_IXMLDOMDocument2( iface );
552 return IXMLDOMNode_put_nodeValue( This->node, value );
556 static HRESULT WINAPI domdoc_get_nodeType(
557 IXMLDOMDocument2 *iface,
560 domdoc *This = impl_from_IXMLDOMDocument2( iface );
561 return IXMLDOMNode_get_nodeType( This->node, type );
565 static HRESULT WINAPI domdoc_get_parentNode(
566 IXMLDOMDocument2 *iface,
567 IXMLDOMNode** parent )
569 domdoc *This = impl_from_IXMLDOMDocument2( iface );
570 return IXMLDOMNode_get_parentNode( This->node, parent );
574 static HRESULT WINAPI domdoc_get_childNodes(
575 IXMLDOMDocument2 *iface,
576 IXMLDOMNodeList** childList )
578 domdoc *This = impl_from_IXMLDOMDocument2( iface );
579 return IXMLDOMNode_get_childNodes( This->node, childList );
583 static HRESULT WINAPI domdoc_get_firstChild(
584 IXMLDOMDocument2 *iface,
585 IXMLDOMNode** firstChild )
587 domdoc *This = impl_from_IXMLDOMDocument2( iface );
588 return IXMLDOMNode_get_firstChild( This->node, firstChild );
592 static HRESULT WINAPI domdoc_get_lastChild(
593 IXMLDOMDocument2 *iface,
594 IXMLDOMNode** lastChild )
596 domdoc *This = impl_from_IXMLDOMDocument2( iface );
597 return IXMLDOMNode_get_lastChild( This->node, lastChild );
601 static HRESULT WINAPI domdoc_get_previousSibling(
602 IXMLDOMDocument2 *iface,
603 IXMLDOMNode** previousSibling )
605 domdoc *This = impl_from_IXMLDOMDocument2( iface );
606 return IXMLDOMNode_get_previousSibling( This->node, previousSibling );
610 static HRESULT WINAPI domdoc_get_nextSibling(
611 IXMLDOMDocument2 *iface,
612 IXMLDOMNode** nextSibling )
614 domdoc *This = impl_from_IXMLDOMDocument2( iface );
615 return IXMLDOMNode_get_nextSibling( This->node, nextSibling );
619 static HRESULT WINAPI domdoc_get_attributes(
620 IXMLDOMDocument2 *iface,
621 IXMLDOMNamedNodeMap** attributeMap )
623 domdoc *This = impl_from_IXMLDOMDocument2( iface );
624 return IXMLDOMNode_get_attributes( This->node, attributeMap );
628 static HRESULT WINAPI domdoc_insertBefore(
629 IXMLDOMDocument2 *iface,
630 IXMLDOMNode* newChild,
632 IXMLDOMNode** outNewChild )
634 domdoc *This = impl_from_IXMLDOMDocument2( iface );
635 return IXMLDOMNode_insertBefore( This->node, newChild, refChild, outNewChild );
639 static HRESULT WINAPI domdoc_replaceChild(
640 IXMLDOMDocument2 *iface,
641 IXMLDOMNode* newChild,
642 IXMLDOMNode* oldChild,
643 IXMLDOMNode** outOldChild)
645 domdoc *This = impl_from_IXMLDOMDocument2( iface );
646 return IXMLDOMNode_replaceChild( This->node, newChild, oldChild, outOldChild );
650 static HRESULT WINAPI domdoc_removeChild(
651 IXMLDOMDocument2 *iface,
652 IXMLDOMNode* childNode,
653 IXMLDOMNode** oldChild)
655 domdoc *This = impl_from_IXMLDOMDocument2( iface );
656 return IXMLDOMNode_removeChild( This->node, childNode, oldChild );
660 static HRESULT WINAPI domdoc_appendChild(
661 IXMLDOMDocument2 *iface,
662 IXMLDOMNode* newChild,
663 IXMLDOMNode** outNewChild)
665 domdoc *This = impl_from_IXMLDOMDocument2( iface );
666 return IXMLDOMNode_appendChild( This->node, newChild, outNewChild );
670 static HRESULT WINAPI domdoc_hasChildNodes(
671 IXMLDOMDocument2 *iface,
672 VARIANT_BOOL* hasChild)
674 domdoc *This = impl_from_IXMLDOMDocument2( iface );
675 return IXMLDOMNode_hasChildNodes( This->node, hasChild );
679 static HRESULT WINAPI domdoc_get_ownerDocument(
680 IXMLDOMDocument2 *iface,
681 IXMLDOMDocument** DOMDocument)
683 domdoc *This = impl_from_IXMLDOMDocument2( iface );
684 return IXMLDOMNode_get_ownerDocument( This->node, DOMDocument );
688 static HRESULT WINAPI domdoc_cloneNode(
689 IXMLDOMDocument2 *iface,
691 IXMLDOMNode** cloneRoot)
693 domdoc *This = impl_from_IXMLDOMDocument2( iface );
694 return IXMLDOMNode_cloneNode( This->node, deep, cloneRoot );
698 static HRESULT WINAPI domdoc_get_nodeTypeString(
699 IXMLDOMDocument2 *iface,
702 domdoc *This = impl_from_IXMLDOMDocument2( iface );
703 return IXMLDOMNode_get_nodeTypeString( This->node, nodeType );
707 static HRESULT WINAPI domdoc_get_text(
708 IXMLDOMDocument2 *iface,
711 domdoc *This = impl_from_IXMLDOMDocument2( iface );
712 return IXMLDOMNode_get_text( This->node, text );
716 static HRESULT WINAPI domdoc_put_text(
717 IXMLDOMDocument2 *iface,
720 domdoc *This = impl_from_IXMLDOMDocument2( iface );
721 return IXMLDOMNode_put_text( This->node, text );
725 static HRESULT WINAPI domdoc_get_specified(
726 IXMLDOMDocument2 *iface,
727 VARIANT_BOOL* isSpecified )
729 domdoc *This = impl_from_IXMLDOMDocument2( iface );
730 return IXMLDOMNode_get_specified( This->node, isSpecified );
734 static HRESULT WINAPI domdoc_get_definition(
735 IXMLDOMDocument2 *iface,
736 IXMLDOMNode** definitionNode )
738 domdoc *This = impl_from_IXMLDOMDocument2( iface );
739 return IXMLDOMNode_get_definition( This->node, definitionNode );
743 static HRESULT WINAPI domdoc_get_nodeTypedValue(
744 IXMLDOMDocument2 *iface,
745 VARIANT* typedValue )
747 domdoc *This = impl_from_IXMLDOMDocument2( iface );
748 return IXMLDOMNode_get_nodeTypedValue( This->node, typedValue );
751 static HRESULT WINAPI domdoc_put_nodeTypedValue(
752 IXMLDOMDocument2 *iface,
755 domdoc *This = impl_from_IXMLDOMDocument2( iface );
756 return IXMLDOMNode_put_nodeTypedValue( This->node, typedValue );
760 static HRESULT WINAPI domdoc_get_dataType(
761 IXMLDOMDocument2 *iface,
762 VARIANT* dataTypeName )
764 domdoc *This = impl_from_IXMLDOMDocument2( iface );
765 return IXMLDOMNode_get_dataType( This->node, dataTypeName );
769 static HRESULT WINAPI domdoc_put_dataType(
770 IXMLDOMDocument2 *iface,
773 domdoc *This = impl_from_IXMLDOMDocument2( iface );
774 return IXMLDOMNode_put_dataType( This->node, dataTypeName );
778 static HRESULT WINAPI domdoc_get_xml(
779 IXMLDOMDocument2 *iface,
782 domdoc *This = impl_from_IXMLDOMDocument2( iface );
783 return IXMLDOMNode_get_xml( This->node, xmlString );
787 static HRESULT WINAPI domdoc_transformNode(
788 IXMLDOMDocument2 *iface,
789 IXMLDOMNode* styleSheet,
792 domdoc *This = impl_from_IXMLDOMDocument2( iface );
793 return IXMLDOMNode_transformNode( This->node, styleSheet, xmlString );
797 static HRESULT WINAPI domdoc_selectNodes(
798 IXMLDOMDocument2 *iface,
800 IXMLDOMNodeList** resultList )
802 domdoc *This = impl_from_IXMLDOMDocument2( iface );
803 return IXMLDOMNode_selectNodes( This->node, queryString, resultList );
807 static HRESULT WINAPI domdoc_selectSingleNode(
808 IXMLDOMDocument2 *iface,
810 IXMLDOMNode** resultNode )
812 domdoc *This = impl_from_IXMLDOMDocument2( iface );
813 return IXMLDOMNode_selectSingleNode( This->node, queryString, resultNode );
817 static HRESULT WINAPI domdoc_get_parsed(
818 IXMLDOMDocument2 *iface,
819 VARIANT_BOOL* isParsed )
821 domdoc *This = impl_from_IXMLDOMDocument2( iface );
822 return IXMLDOMNode_get_parsed( This->node, isParsed );
826 static HRESULT WINAPI domdoc_get_namespaceURI(
827 IXMLDOMDocument2 *iface,
830 domdoc *This = impl_from_IXMLDOMDocument2( iface );
831 return IXMLDOMNode_get_namespaceURI( This->node, namespaceURI );
835 static HRESULT WINAPI domdoc_get_prefix(
836 IXMLDOMDocument2 *iface,
839 domdoc *This = impl_from_IXMLDOMDocument2( iface );
840 return IXMLDOMNode_get_prefix( This->node, prefixString );
844 static HRESULT WINAPI domdoc_get_baseName(
845 IXMLDOMDocument2 *iface,
848 domdoc *This = impl_from_IXMLDOMDocument2( iface );
849 return IXMLDOMNode_get_baseName( This->node, nameString );
853 static HRESULT WINAPI domdoc_transformNodeToObject(
854 IXMLDOMDocument2 *iface,
855 IXMLDOMNode* stylesheet,
856 VARIANT outputObject)
858 domdoc *This = impl_from_IXMLDOMDocument2( iface );
859 return IXMLDOMNode_transformNodeToObject( This->node, stylesheet, outputObject );
863 static HRESULT WINAPI domdoc_get_doctype(
864 IXMLDOMDocument2 *iface,
865 IXMLDOMDocumentType** documentType )
872 static HRESULT WINAPI domdoc_get_implementation(
873 IXMLDOMDocument2 *iface,
874 IXMLDOMImplementation** impl )
879 *impl = (IXMLDOMImplementation*)create_doc_Implementation();
884 static HRESULT WINAPI domdoc_get_documentElement(
885 IXMLDOMDocument2 *iface,
886 IXMLDOMElement** DOMElement )
888 domdoc *This = impl_from_IXMLDOMDocument2( iface );
889 xmlDocPtr xmldoc = NULL;
890 xmlNodePtr root = NULL;
891 IXMLDOMNode *element_node;
894 TRACE("%p %p\n", This, This->node);
901 xmldoc = get_doc( This );
903 root = xmlDocGetRootElement( xmldoc );
907 element_node = create_node( root );
908 if(!element_node) return S_FALSE;
910 hr = IXMLDOMNode_QueryInterface(element_node, &IID_IXMLDOMElement, (LPVOID*)DOMElement);
911 IXMLDOMNode_Release(element_node);
917 static HRESULT WINAPI domdoc_documentElement(
918 IXMLDOMDocument2 *iface,
919 IXMLDOMElement* DOMElement )
926 static HRESULT WINAPI domdoc_createElement(
927 IXMLDOMDocument2 *iface,
929 IXMLDOMElement** element )
932 domdoc *This = impl_from_IXMLDOMDocument2( iface );
937 TRACE("%p->(%s,%p)\n", iface, debugstr_w(tagname), element);
939 xml_name = xmlChar_from_wchar((WCHAR*)tagname);
940 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
942 TRACE("created xmlptr %p\n", xmlnode);
943 elem_unk = create_element(xmlnode, NULL);
944 HeapFree(GetProcessHeap(), 0, xml_name);
946 hr = IUnknown_QueryInterface(elem_unk, &IID_IXMLDOMElement, (void **)element);
947 IUnknown_Release(elem_unk);
948 TRACE("returning %p\n", *element);
953 static HRESULT WINAPI domdoc_createDocumentFragment(
954 IXMLDOMDocument2 *iface,
955 IXMLDOMDocumentFragment** docFrag )
957 domdoc *This = impl_from_IXMLDOMDocument2( iface );
960 TRACE("%p\n", iface);
967 xmlnode = xmlNewDocFragment(get_doc( This ) );
972 xmlnode->doc = get_doc( This );
974 *docFrag = (IXMLDOMDocumentFragment*)create_doc_fragment(xmlnode);
980 static HRESULT WINAPI domdoc_createTextNode(
981 IXMLDOMDocument2 *iface,
985 domdoc *This = impl_from_IXMLDOMDocument2( iface );
987 xmlChar *xml_content;
989 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), text);
996 xml_content = xmlChar_from_wchar((WCHAR*)data);
997 xmlnode = xmlNewText(xml_content);
998 HeapFree(GetProcessHeap(), 0, xml_content);
1003 xmlnode->doc = get_doc( This );
1005 *text = (IXMLDOMText*)create_text(xmlnode);
1011 static HRESULT WINAPI domdoc_createComment(
1012 IXMLDOMDocument2 *iface,
1014 IXMLDOMComment** comment )
1016 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1018 xmlChar *xml_content;
1020 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), comment);
1023 return E_INVALIDARG;
1027 xml_content = xmlChar_from_wchar((WCHAR*)data);
1028 xmlnode = xmlNewComment(xml_content);
1029 HeapFree(GetProcessHeap(), 0, xml_content);
1034 xmlnode->doc = get_doc( This );
1036 *comment = (IXMLDOMComment*)create_comment(xmlnode);
1042 static HRESULT WINAPI domdoc_createCDATASection(
1043 IXMLDOMDocument2 *iface,
1045 IXMLDOMCDATASection** cdata )
1047 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1049 xmlChar *xml_content;
1051 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), cdata);
1054 return E_INVALIDARG;
1058 xml_content = xmlChar_from_wchar((WCHAR*)data);
1059 xmlnode = xmlNewCDataBlock(get_doc( This ), xml_content, strlen( (char*)xml_content) );
1060 HeapFree(GetProcessHeap(), 0, xml_content);
1065 xmlnode->doc = get_doc( This );
1067 *cdata = (IXMLDOMCDATASection*)create_cdata(xmlnode);
1073 static HRESULT WINAPI domdoc_createProcessingInstruction(
1074 IXMLDOMDocument2 *iface,
1077 IXMLDOMProcessingInstruction** pi )
1079 #ifdef HAVE_XMLNEWDOCPI
1081 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1082 xmlChar *xml_target, *xml_content;
1084 TRACE("%p->(%s %s %p)\n", iface, debugstr_w(target), debugstr_w(data), pi);
1087 return E_INVALIDARG;
1089 if(!target || lstrlenW(target) == 0)
1092 xml_target = xmlChar_from_wchar((WCHAR*)target);
1093 xml_content = xmlChar_from_wchar((WCHAR*)data);
1095 xmlnode = xmlNewDocPI(get_doc(This), xml_target, xml_content);
1096 TRACE("created xmlptr %p\n", xmlnode);
1097 *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode);
1099 HeapFree(GetProcessHeap(), 0, xml_content);
1100 HeapFree(GetProcessHeap(), 0, xml_target);
1104 FIXME("Libxml 2.6.15 or greater required.\n");
1110 static HRESULT WINAPI domdoc_createAttribute(
1111 IXMLDOMDocument2 *iface,
1113 IXMLDOMAttribute** attribute )
1115 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1119 TRACE("%p->(%s %p)\n", iface, debugstr_w(name), attribute);
1122 return E_INVALIDARG;
1126 xml_name = xmlChar_from_wchar((WCHAR*)name);
1127 xmlnode = (xmlNode *)xmlNewProp(NULL, xml_name, NULL);
1128 HeapFree(GetProcessHeap(), 0, xml_name);
1133 xmlnode->doc = get_doc( This );
1135 *attribute = (IXMLDOMAttribute*)create_attribute(xmlnode);
1141 static HRESULT WINAPI domdoc_createEntityReference(
1142 IXMLDOMDocument2 *iface,
1144 IXMLDOMEntityReference** entityRef )
1146 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1150 TRACE("%p\n", iface);
1153 return E_INVALIDARG;
1157 xml_name = xmlChar_from_wchar((WCHAR*)name);
1158 xmlnode = xmlNewReference(get_doc( This ), xml_name );
1159 HeapFree(GetProcessHeap(), 0, xml_name);
1164 xmlnode->doc = get_doc( This );
1166 *entityRef = (IXMLDOMEntityReference*)create_doc_entity_ref(xmlnode);
1172 static HRESULT WINAPI domdoc_getElementsByTagName(
1173 IXMLDOMDocument2 *iface,
1175 IXMLDOMNodeList** resultList )
1177 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1180 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1182 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(2+lstrlenW(tagName)+1));
1183 szPattern[0] = szPattern[1] = '/';
1184 lstrcpyW(szPattern + 2, tagName);
1186 hr = queryresult_create((xmlNodePtr)get_doc(This), szPattern, resultList);
1187 HeapFree(GetProcessHeap(), 0, szPattern);
1192 static DOMNodeType get_node_type(VARIANT Type)
1194 if(V_VT(&Type) == VT_I4)
1197 FIXME("Unsupported variant type %x\n", V_VT(&Type));
1201 static HRESULT WINAPI domdoc_createNode(
1202 IXMLDOMDocument2 *iface,
1206 IXMLDOMNode** node )
1208 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1209 DOMNodeType node_type;
1210 xmlNodePtr xmlnode = NULL;
1213 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
1215 node_type = get_node_type(Type);
1216 TRACE("node_type %d\n", node_type);
1218 xml_name = xmlChar_from_wchar((WCHAR*)name);
1223 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
1224 *node = create_node(xmlnode);
1225 TRACE("created %p\n", xmlnode);
1229 FIXME("unhandled node type %d\n", node_type);
1233 HeapFree(GetProcessHeap(), 0, xml_name);
1235 if(xmlnode && *node)
1241 static HRESULT WINAPI domdoc_nodeFromID(
1242 IXMLDOMDocument2 *iface,
1244 IXMLDOMNode** node )
1250 static xmlDocPtr doparse( char *ptr, int len )
1252 #ifdef HAVE_XMLREADMEMORY
1254 * use xmlReadMemory if possible so we can suppress
1255 * writing errors to stderr
1257 return xmlReadMemory( ptr, len, NULL, NULL,
1258 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
1260 return xmlParseMemory( ptr, len );
1264 static xmlDocPtr doread( LPWSTR filename )
1266 xmlDocPtr xmldoc = NULL;
1269 IStream *stream, *memstream;
1270 WCHAR url[INTERNET_MAX_URL_LENGTH];
1272 DWORD read, written;
1274 TRACE("%s\n", debugstr_w( filename ));
1276 if(!PathIsURLW(filename))
1278 WCHAR fullpath[MAX_PATH];
1279 DWORD needed = sizeof(url)/sizeof(WCHAR);
1281 if(!PathSearchAndQualifyW(filename, fullpath, sizeof(fullpath)/sizeof(WCHAR)))
1283 WARN("can't find path\n");
1287 if(FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0)))
1289 ERR("can't create url from path\n");
1295 hr = CreateBindCtx(0, &pbc);
1298 hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&domdoc_bsc.lpVtbl, NULL, 0);
1302 hr = CreateURLMoniker(NULL, filename, &moniker);
1305 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
1306 IMoniker_Release(moniker);
1309 IBindCtx_Release(pbc);
1314 hr = CreateStreamOnHGlobal(NULL, TRUE, &memstream);
1317 IStream_Release(stream);
1323 IStream_Read(stream, buf, sizeof(buf), &read);
1324 hr = IStream_Write(memstream, buf, read, &written);
1325 } while(SUCCEEDED(hr) && written != 0 && read != 0);
1330 hr = GetHGlobalFromStream(memstream, &hglobal);
1333 DWORD len = GlobalSize(hglobal);
1334 char *ptr = GlobalLock(hglobal);
1336 xmldoc = doparse( ptr, len );
1337 GlobalUnlock(hglobal);
1340 IStream_Release(memstream);
1341 IStream_Release(stream);
1345 static HRESULT WINAPI domdoc_load(
1346 IXMLDOMDocument2 *iface,
1348 VARIANT_BOOL* isSuccessful )
1350 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1351 LPWSTR filename = NULL;
1352 xmlDocPtr xmldoc = NULL;
1353 HRESULT hr = S_FALSE;
1354 IXMLDOMDocument2 *pNewDoc = NULL;
1355 IStream *pStream = NULL;
1357 TRACE("type %d\n", V_VT(&xmlSource) );
1359 *isSuccessful = VARIANT_FALSE;
1361 assert( This->node );
1363 attach_xmlnode(This->node, NULL);
1365 switch( V_VT(&xmlSource) )
1368 filename = V_BSTR(&xmlSource);
1371 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IXMLDOMDocument2, (void**)&pNewDoc);
1376 domdoc *newDoc = impl_from_IXMLDOMDocument2( pNewDoc );
1377 xmldoc = xmlCopyDoc(get_doc(newDoc), 1);
1378 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1380 *isSuccessful = VARIANT_TRUE;
1385 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IStream, (void**)&pStream);
1388 IPersistStream *pDocStream;
1389 hr = IUnknown_QueryInterface(iface, &IID_IPersistStream, (void**)&pDocStream);
1392 hr = xmldoc_IPersistStream_Load(pDocStream, pStream);
1393 IStream_Release(pStream);
1396 *isSuccessful = VARIANT_TRUE;
1398 TRACE("Using ID_IStream to load Document\n");
1403 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr);
1408 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr);
1413 /* ISequentialStream */
1414 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr, pNewDoc, V_UNKNOWN(&xmlSource)->lpVtbl);
1418 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource));
1421 TRACE("filename (%s)\n", debugstr_w(filename));
1425 xmldoc = doread( filename );
1428 This->error = E_FAIL;
1431 hr = This->error = S_OK;
1432 *isSuccessful = VARIANT_TRUE;
1437 xmldoc = xmlNewDoc(NULL);
1439 xmldoc->_private = 0;
1440 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1442 TRACE("ret (%d)\n", hr);
1448 static HRESULT WINAPI domdoc_get_readyState(
1449 IXMLDOMDocument2 *iface,
1457 static HRESULT WINAPI domdoc_get_parseError(
1458 IXMLDOMDocument2 *iface,
1459 IXMLDOMParseError** errorObj )
1461 BSTR error_string = NULL;
1462 static const WCHAR err[] = {'e','r','r','o','r',0};
1463 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1465 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1468 error_string = SysAllocString(err);
1470 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1471 if(!*errorObj) return E_OUTOFMEMORY;
1476 static HRESULT WINAPI domdoc_get_url(
1477 IXMLDOMDocument2 *iface,
1485 static HRESULT WINAPI domdoc_get_async(
1486 IXMLDOMDocument2 *iface,
1487 VARIANT_BOOL* isAsync )
1489 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1491 TRACE("%p <- %d\n", isAsync, This->async);
1492 *isAsync = This->async;
1497 static HRESULT WINAPI domdoc_put_async(
1498 IXMLDOMDocument2 *iface,
1499 VARIANT_BOOL isAsync )
1501 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1503 TRACE("%d\n", isAsync);
1504 This->async = isAsync;
1509 static HRESULT WINAPI domdoc_abort(
1510 IXMLDOMDocument2 *iface )
1517 static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1519 UINT len, blen = SysStringLen( bstr );
1522 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1523 str = HeapAlloc( GetProcessHeap(), 0, len );
1526 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1532 static HRESULT WINAPI domdoc_loadXML(
1533 IXMLDOMDocument2 *iface,
1535 VARIANT_BOOL* isSuccessful )
1537 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1538 xmlDocPtr xmldoc = NULL;
1541 HRESULT hr = S_FALSE;
1543 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1545 assert ( This->node );
1547 attach_xmlnode( This->node, NULL );
1551 *isSuccessful = VARIANT_FALSE;
1553 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1555 xmldoc = doparse( str, len );
1556 HeapFree( GetProcessHeap(), 0, str );
1558 This->error = E_FAIL;
1561 hr = This->error = S_OK;
1562 *isSuccessful = VARIANT_TRUE;
1567 xmldoc = xmlNewDoc(NULL);
1569 xmldoc->_private = 0;
1570 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1576 static HRESULT WINAPI domdoc_save(
1577 IXMLDOMDocument2 *iface,
1578 VARIANT destination )
1580 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1587 TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
1588 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1590 if(V_VT(&destination) != VT_BSTR && V_VT(&destination) != VT_UNKNOWN)
1592 FIXME("Unhandled vt %d\n", V_VT(&destination));
1596 if(V_VT(&destination) == VT_UNKNOWN)
1598 IUnknown *pUnk = V_UNKNOWN(&destination);
1599 IXMLDOMDocument *pDocument;
1601 ret = IXMLDOMDocument_QueryInterface(pUnk, &IID_IXMLDOMDocument2, (void**)&pDocument);
1605 VARIANT_BOOL bSuccessful;
1607 ret = IXMLDOMDocument_get_xml(iface, &bXML);
1610 ret = IXMLDOMDocument_loadXML(pDocument, bXML, &bSuccessful);
1612 SysFreeString(bXML);
1615 IXMLDOMDocument_Release(pDocument);
1621 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1622 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1623 if( handle == INVALID_HANDLE_VALUE )
1625 WARN("failed to create file\n");
1629 xmlDocDumpMemory(get_doc(This), &mem, &size);
1630 if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size)
1632 WARN("write error\n");
1637 CloseHandle(handle);
1641 static HRESULT WINAPI domdoc_get_validateOnParse(
1642 IXMLDOMDocument2 *iface,
1643 VARIANT_BOOL* isValidating )
1645 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1647 TRACE("%p <- %d\n", isValidating, This->validating);
1648 *isValidating = This->validating;
1653 static HRESULT WINAPI domdoc_put_validateOnParse(
1654 IXMLDOMDocument2 *iface,
1655 VARIANT_BOOL isValidating )
1657 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1659 TRACE("%d\n", isValidating);
1660 This->validating = isValidating;
1665 static HRESULT WINAPI domdoc_get_resolveExternals(
1666 IXMLDOMDocument2 *iface,
1667 VARIANT_BOOL* isResolving )
1669 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1671 TRACE("%p <- %d\n", isResolving, This->resolving);
1672 *isResolving = This->resolving;
1677 static HRESULT WINAPI domdoc_put_resolveExternals(
1678 IXMLDOMDocument2 *iface,
1679 VARIANT_BOOL isResolving )
1681 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1683 TRACE("%d\n", isResolving);
1684 This->resolving = isResolving;
1689 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1690 IXMLDOMDocument2 *iface,
1691 VARIANT_BOOL* isPreserving )
1693 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1695 TRACE("%p <- %d\n", isPreserving, This->preserving);
1696 *isPreserving = This->preserving;
1701 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1702 IXMLDOMDocument2 *iface,
1703 VARIANT_BOOL isPreserving )
1705 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1707 TRACE("%d\n", isPreserving);
1708 This->preserving = isPreserving;
1713 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1714 IXMLDOMDocument2 *iface,
1715 VARIANT readyStateChangeSink )
1722 static HRESULT WINAPI domdoc_put_onDataAvailable(
1723 IXMLDOMDocument2 *iface,
1724 VARIANT onDataAvailableSink )
1730 static HRESULT WINAPI domdoc_put_onTransformNode(
1731 IXMLDOMDocument2 *iface,
1732 VARIANT onTransformNodeSink )
1738 static HRESULT WINAPI domdoc_get_namespaces(
1739 IXMLDOMDocument2* iface,
1740 IXMLDOMSchemaCollection** schemaCollection )
1746 static HRESULT WINAPI domdoc_get_schemas(
1747 IXMLDOMDocument2* iface,
1750 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1751 HRESULT hr = S_FALSE;
1752 IXMLDOMSchemaCollection *cur_schema = This->schema;
1754 TRACE("(%p)->(%p)\n", This, var1);
1756 VariantInit(var1); /* Test shows we don't call VariantClear here */
1757 V_VT(var1) = VT_NULL;
1761 hr = IXMLDOMSchemaCollection_QueryInterface(cur_schema, &IID_IDispatch, (void**)&V_DISPATCH(var1));
1763 V_VT(var1) = VT_DISPATCH;
1768 static HRESULT WINAPI domdoc_putref_schemas(
1769 IXMLDOMDocument2* iface,
1772 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1773 HRESULT hr = E_FAIL;
1774 IXMLDOMSchemaCollection *new_schema = NULL;
1776 FIXME("(%p): semi-stub\n", This);
1780 hr = IUnknown_QueryInterface(V_UNKNOWN(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1784 hr = IDispatch_QueryInterface(V_DISPATCH(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1793 WARN("Can't get schema from vt %x\n", V_VT(&var1));
1798 IXMLDOMSchemaCollection *old_schema = InterlockedExchangePointer((void**)&This->schema, new_schema);
1799 if(old_schema) IXMLDOMSchemaCollection_Release(old_schema);
1805 static HRESULT WINAPI domdoc_validate(
1806 IXMLDOMDocument2* iface,
1807 IXMLDOMParseError** err)
1813 static HRESULT WINAPI domdoc_setProperty(
1814 IXMLDOMDocument2* iface,
1818 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1820 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1826 V_VT(&varStr) = VT_EMPTY;
1827 if (V_VT(&var) != VT_BSTR)
1829 if (FAILED(hr = VariantChangeType(&varStr, &var, 0, VT_BSTR)))
1831 bstr = V_BSTR(&varStr);
1834 bstr = V_BSTR(&var);
1837 if (lstrcmpiW(bstr, SZ_VALUE_XPATH) == 0)
1838 This->bUseXPath = TRUE;
1839 else if (lstrcmpiW(bstr, SZ_VALUE_XSLPATTERN) == 0)
1840 This->bUseXPath = FALSE;
1844 VariantClear(&varStr);
1848 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1852 static HRESULT WINAPI domdoc_getProperty(
1853 IXMLDOMDocument2* iface,
1857 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1860 return E_INVALIDARG;
1861 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1863 V_VT(var) = VT_BSTR;
1864 if (This->bUseXPath)
1865 V_BSTR(var) = SysAllocString(SZ_VALUE_XPATH);
1867 V_BSTR(var) = SysAllocString(SZ_VALUE_XSLPATTERN);
1871 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1875 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl =
1877 domdoc_QueryInterface,
1880 domdoc_GetTypeInfoCount,
1882 domdoc_GetIDsOfNames,
1884 domdoc_get_nodeName,
1885 domdoc_get_nodeValue,
1886 domdoc_put_nodeValue,
1887 domdoc_get_nodeType,
1888 domdoc_get_parentNode,
1889 domdoc_get_childNodes,
1890 domdoc_get_firstChild,
1891 domdoc_get_lastChild,
1892 domdoc_get_previousSibling,
1893 domdoc_get_nextSibling,
1894 domdoc_get_attributes,
1895 domdoc_insertBefore,
1896 domdoc_replaceChild,
1899 domdoc_hasChildNodes,
1900 domdoc_get_ownerDocument,
1902 domdoc_get_nodeTypeString,
1905 domdoc_get_specified,
1906 domdoc_get_definition,
1907 domdoc_get_nodeTypedValue,
1908 domdoc_put_nodeTypedValue,
1909 domdoc_get_dataType,
1910 domdoc_put_dataType,
1912 domdoc_transformNode,
1914 domdoc_selectSingleNode,
1916 domdoc_get_namespaceURI,
1918 domdoc_get_baseName,
1919 domdoc_transformNodeToObject,
1921 domdoc_get_implementation,
1922 domdoc_get_documentElement,
1923 domdoc_documentElement,
1924 domdoc_createElement,
1925 domdoc_createDocumentFragment,
1926 domdoc_createTextNode,
1927 domdoc_createComment,
1928 domdoc_createCDATASection,
1929 domdoc_createProcessingInstruction,
1930 domdoc_createAttribute,
1931 domdoc_createEntityReference,
1932 domdoc_getElementsByTagName,
1936 domdoc_get_readyState,
1937 domdoc_get_parseError,
1944 domdoc_get_validateOnParse,
1945 domdoc_put_validateOnParse,
1946 domdoc_get_resolveExternals,
1947 domdoc_put_resolveExternals,
1948 domdoc_get_preserveWhiteSpace,
1949 domdoc_put_preserveWhiteSpace,
1950 domdoc_put_onReadyStateChange,
1951 domdoc_put_onDataAvailable,
1952 domdoc_put_onTransformNode,
1953 domdoc_get_namespaces,
1955 domdoc_putref_schemas,
1961 /* xmldoc implementation of IObjectWithSite */
1962 static HRESULT WINAPI
1963 xmldoc_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
1965 domdoc *This = impl_from_IObjectWithSite(iface);
1966 return IXMLDocument_QueryInterface( (IXMLDocument *)This, riid, ppvObject );
1970 xmldoc_ObjectWithSite_AddRef( IObjectWithSite* iface )
1972 domdoc *This = impl_from_IObjectWithSite(iface);
1973 return IXMLDocument_AddRef((IXMLDocument *)This);
1977 xmldoc_ObjectWithSite_Release( IObjectWithSite* iface )
1979 domdoc *This = impl_from_IObjectWithSite(iface);
1980 return IXMLDocument_Release((IXMLDocument *)This);
1983 static HRESULT WINAPI
1984 xmldoc_GetSite( IObjectWithSite *iface, REFIID iid, void ** ppvSite )
1986 domdoc *This = impl_from_IObjectWithSite(iface);
1988 TRACE("%p %s %p\n", This, debugstr_guid( iid ), ppvSite );
1993 return IUnknown_QueryInterface( This->site, iid, ppvSite );
1996 static HRESULT WINAPI
1997 xmldoc_SetSite( IObjectWithSite *iface, IUnknown *punk )
1999 domdoc *This = impl_from_IObjectWithSite(iface);
2001 TRACE("%p %p\n", iface, punk);
2007 IUnknown_Release( This->site );
2015 IUnknown_AddRef( punk );
2018 IUnknown_Release( This->site );
2025 static const IObjectWithSiteVtbl domdocObjectSite =
2027 xmldoc_ObjectWithSite_QueryInterface,
2028 xmldoc_ObjectWithSite_AddRef,
2029 xmldoc_ObjectWithSite_Release,
2034 static HRESULT WINAPI xmldoc_Safety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
2036 domdoc *This = impl_from_IObjectSafety(iface);
2037 return IXMLDocument_QueryInterface( (IXMLDocument *)This, riid, ppv );
2040 static ULONG WINAPI xmldoc_Safety_AddRef(IObjectSafety *iface)
2042 domdoc *This = impl_from_IObjectSafety(iface);
2043 return IXMLDocument_AddRef((IXMLDocument *)This);
2046 static ULONG WINAPI xmldoc_Safety_Release(IObjectSafety *iface)
2048 domdoc *This = impl_from_IObjectSafety(iface);
2049 return IXMLDocument_Release((IXMLDocument *)This);
2052 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER)
2054 static HRESULT WINAPI xmldoc_Safety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
2055 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
2057 domdoc *This = impl_from_IObjectSafety(iface);
2059 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
2061 if(!pdwSupportedOptions || !pdwEnabledOptions)
2064 *pdwSupportedOptions = SUPPORTED_OPTIONS;
2065 *pdwEnabledOptions = This->safeopt;
2070 static HRESULT WINAPI xmldoc_Safety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
2071 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
2073 domdoc *This = impl_from_IObjectSafety(iface);
2075 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
2077 if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
2080 This->safeopt = dwEnabledOptions & dwEnabledOptions;
2084 static const IObjectSafetyVtbl domdocObjectSafetyVtbl = {
2085 xmldoc_Safety_QueryInterface,
2086 xmldoc_Safety_AddRef,
2087 xmldoc_Safety_Release,
2088 xmldoc_Safety_GetInterfaceSafetyOptions,
2089 xmldoc_Safety_SetInterfaceSafetyOptions
2092 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2098 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2100 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
2102 return E_OUTOFMEMORY;
2104 doc->lpVtbl = &domdoc_vtbl;
2105 doc->lpvtblIPersistStream = &xmldoc_IPersistStream_VTable;
2106 doc->lpvtblIObjectWithSite = &domdocObjectSite;
2107 doc->lpvtblIObjectSafety = &domdocObjectSafetyVtbl;
2110 doc->validating = 0;
2112 doc->preserving = 0;
2113 doc->bUseXPath = FALSE;
2120 xmldoc = xmlNewDoc(NULL);
2123 HeapFree(GetProcessHeap(), 0, doc);
2124 return E_OUTOFMEMORY;
2127 xmldoc->_private = 0;
2129 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
2133 HeapFree(GetProcessHeap(), 0, doc);
2137 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
2140 IUnknown_Release(doc->node_unk);
2141 HeapFree( GetProcessHeap(), 0, doc );
2144 /* The ref on doc->node is actually looped back into this object, so release it */
2145 IXMLDOMNode_Release(doc->node);
2147 *ppObj = &doc->lpVtbl;
2149 TRACE("returning iface %p\n", *ppObj);
2155 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2157 MESSAGE("This program tried to use a DOMDocument object, but\n"
2158 "libxml2 support was not present at compile time.\n");