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
22 #define NONAMELESSUNION
41 #include "wine/debug.h"
43 #include "msxml_private.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
49 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};
50 static const WCHAR SZ_VALUE_XPATH[] = {'X','P','a','t','h',0};
51 static const WCHAR SZ_VALUE_XSLPATTERN[] = {'X','S','L','P','a','t','t','e','r','n',0};
53 typedef struct _domdoc
55 const struct IXMLDOMDocument2Vtbl *lpVtbl;
56 const struct IPersistStreamVtbl *lpvtblIPersistStream;
57 const struct IObjectWithSiteVtbl *lpvtblIObjectWithSite;
58 const struct IObjectSafetyVtbl *lpvtblIObjectSafety;
61 VARIANT_BOOL validating;
62 VARIANT_BOOL resolving;
63 VARIANT_BOOL preserving;
67 IXMLDOMSchemaCollection *schema;
84 static xmlDocPtr doparse( char *ptr, int len )
86 #ifdef HAVE_XMLREADMEMORY
88 * use xmlReadMemory if possible so we can suppress
89 * writing errors to stderr
91 return xmlReadMemory( ptr, len, NULL, NULL,
92 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
94 return xmlParseMemory( ptr, len );
98 LONG xmldoc_add_ref(xmlDocPtr doc)
100 LONG ref = InterlockedIncrement((LONG*)&doc->_private);
105 LONG xmldoc_release(xmlDocPtr doc)
107 LONG ref = InterlockedDecrement((LONG*)&doc->_private);
111 TRACE("freeing docptr %p\n", doc);
118 static inline domdoc *impl_from_IXMLDOMDocument2( IXMLDOMDocument2 *iface )
120 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpVtbl));
123 static inline xmlDocPtr get_doc( domdoc *This )
125 return (xmlDocPtr) xmlNodePtr_from_domnode( This->node, XML_DOCUMENT_NODE );
128 static inline domdoc *impl_from_IPersistStream(IPersistStream *iface)
130 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIPersistStream));
133 static inline domdoc *impl_from_IObjectWithSite(IObjectWithSite *iface)
135 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIObjectWithSite));
138 static inline domdoc *impl_from_IObjectSafety(IObjectSafety *iface)
140 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIObjectSafety));
144 /************************************************************************
145 * xmldoc implementation of IPersistStream.
147 static HRESULT WINAPI xmldoc_IPersistStream_QueryInterface(
148 IPersistStream *iface, REFIID riid, LPVOID *ppvObj)
150 domdoc *this = impl_from_IPersistStream(iface);
151 return IXMLDocument_QueryInterface((IXMLDocument *)this, riid, ppvObj);
154 static ULONG WINAPI xmldoc_IPersistStream_AddRef(
155 IPersistStream *iface)
157 domdoc *this = impl_from_IPersistStream(iface);
158 return IXMLDocument_AddRef((IXMLDocument *)this);
161 static ULONG WINAPI xmldoc_IPersistStream_Release(
162 IPersistStream *iface)
164 domdoc *this = impl_from_IPersistStream(iface);
165 return IXMLDocument_Release((IXMLDocument *)this);
168 static HRESULT WINAPI xmldoc_IPersistStream_GetClassID(
169 IPersistStream *iface, CLSID *classid)
171 TRACE("(%p,%p): stub!\n", iface, classid);
176 *classid = CLSID_DOMDocument2;
181 static HRESULT WINAPI xmldoc_IPersistStream_IsDirty(
182 IPersistStream *iface)
184 domdoc *This = impl_from_IPersistStream(iface);
186 FIXME("(%p->%p): stub!\n", iface, This);
191 static HRESULT WINAPI xmldoc_IPersistStream_Load(
192 IPersistStream *iface, LPSTREAM pStm)
194 domdoc *This = impl_from_IPersistStream(iface);
197 DWORD read, written, len;
200 xmlDocPtr xmldoc = NULL;
202 TRACE("(%p, %p)\n", iface, pStm);
207 hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
213 IStream_Read(pStm, buf, sizeof(buf), &read);
214 hr = IStream_Write(This->stream, buf, read, &written);
215 } while(SUCCEEDED(hr) && written != 0 && read != 0);
219 ERR("Failed to copy stream\n");
223 hr = GetHGlobalFromStream(This->stream, &hglobal);
227 len = GlobalSize(hglobal);
228 ptr = GlobalLock(hglobal);
230 xmldoc = parse_xml(ptr, len);
231 GlobalUnlock(hglobal);
235 ERR("Failed to parse xml\n");
239 attach_xmlnode( This->node, (xmlNodePtr)xmldoc );
244 static HRESULT WINAPI xmldoc_IPersistStream_Save(
245 IPersistStream *iface, LPSTREAM pStm, BOOL fClearDirty)
247 FIXME("(%p, %p, %d): stub!\n", iface, pStm, fClearDirty);
251 static HRESULT WINAPI xmldoc_IPersistStream_GetSizeMax(
252 IPersistStream *iface, ULARGE_INTEGER *pcbSize)
254 TRACE("(%p, %p): stub!\n", iface, pcbSize);
258 static const IPersistStreamVtbl xmldoc_IPersistStream_VTable =
260 xmldoc_IPersistStream_QueryInterface,
261 xmldoc_IPersistStream_AddRef,
262 xmldoc_IPersistStream_Release,
263 xmldoc_IPersistStream_GetClassID,
264 xmldoc_IPersistStream_IsDirty,
265 xmldoc_IPersistStream_Load,
266 xmldoc_IPersistStream_Save,
267 xmldoc_IPersistStream_GetSizeMax,
270 static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument2 *iface, REFIID riid, void** ppvObject )
272 domdoc *This = impl_from_IXMLDOMDocument2( iface );
274 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
278 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
279 IsEqualGUID( riid, &IID_IDispatch ) ||
280 IsEqualGUID( riid, &IID_IXMLDOMDocument ) ||
281 IsEqualGUID( riid, &IID_IXMLDOMDocument2 ) )
285 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
287 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
289 else if (IsEqualGUID(&IID_IPersistStream, riid))
291 *ppvObject = (IPersistStream*)&(This->lpvtblIPersistStream);
293 else if (IsEqualGUID(&IID_IObjectWithSite, riid))
295 *ppvObject = (IObjectWithSite*)&(This->lpvtblIObjectWithSite);
297 else if(dispex_query_interface(&This->dispex, riid, ppvObject))
299 return *ppvObject ? S_OK : E_NOINTERFACE;
301 else if(IsEqualGUID(&IID_IRunnableObject, riid))
303 TRACE("IID_IRunnableObject not supported returning NULL\n");
304 return E_NOINTERFACE;
308 FIXME("interface %s not implemented\n", debugstr_guid(riid));
309 return E_NOINTERFACE;
312 IXMLDOMDocument_AddRef( iface );
318 static ULONG WINAPI domdoc_AddRef(
319 IXMLDOMDocument2 *iface )
321 domdoc *This = impl_from_IXMLDOMDocument2( iface );
322 TRACE("%p\n", This );
323 return InterlockedIncrement( &This->ref );
327 static ULONG WINAPI domdoc_Release(
328 IXMLDOMDocument2 *iface )
330 domdoc *This = impl_from_IXMLDOMDocument2( iface );
333 TRACE("%p\n", This );
335 ref = InterlockedDecrement( &This->ref );
339 detach_bsc(This->bsc);
342 IUnknown_Release( This->site );
343 IUnknown_Release( This->node_unk );
344 if(This->schema) IXMLDOMSchemaCollection_Release( This->schema );
345 if (This->stream) IStream_Release(This->stream);
346 HeapFree( GetProcessHeap(), 0, This );
352 static HRESULT WINAPI domdoc_GetTypeInfoCount( IXMLDOMDocument2 *iface, UINT* pctinfo )
354 domdoc *This = impl_from_IXMLDOMDocument2( iface );
356 TRACE("(%p)->(%p)\n", This, pctinfo);
363 static HRESULT WINAPI domdoc_GetTypeInfo(
364 IXMLDOMDocument2 *iface,
365 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
367 domdoc *This = impl_from_IXMLDOMDocument2( iface );
370 TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
372 hr = get_typeinfo(IXMLDOMDocument2_tid, ppTInfo);
377 static HRESULT WINAPI domdoc_GetIDsOfNames(
378 IXMLDOMDocument2 *iface,
385 domdoc *This = impl_from_IXMLDOMDocument2( iface );
389 TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
392 if(!rgszNames || cNames == 0 || !rgDispId)
395 hr = get_typeinfo(IXMLDOMDocument2_tid, &typeinfo);
398 hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
399 ITypeInfo_Release(typeinfo);
406 static HRESULT WINAPI domdoc_Invoke(
407 IXMLDOMDocument2 *iface,
412 DISPPARAMS* pDispParams,
414 EXCEPINFO* pExcepInfo,
417 domdoc *This = impl_from_IXMLDOMDocument2( iface );
421 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
422 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
424 hr = get_typeinfo(IXMLDOMDocument2_tid, &typeinfo);
427 hr = ITypeInfo_Invoke(typeinfo, &(This->lpVtbl), dispIdMember, wFlags, pDispParams,
428 pVarResult, pExcepInfo, puArgErr);
429 ITypeInfo_Release(typeinfo);
436 static HRESULT WINAPI domdoc_get_nodeName(
437 IXMLDOMDocument2 *iface,
440 domdoc *This = impl_from_IXMLDOMDocument2( iface );
441 return IXMLDOMNode_get_nodeName( This->node, name );
445 static HRESULT WINAPI domdoc_get_nodeValue(
446 IXMLDOMDocument2 *iface,
449 domdoc *This = impl_from_IXMLDOMDocument2( iface );
450 return IXMLDOMNode_get_nodeValue( This->node, value );
454 static HRESULT WINAPI domdoc_put_nodeValue(
455 IXMLDOMDocument2 *iface,
458 domdoc *This = impl_from_IXMLDOMDocument2( iface );
459 return IXMLDOMNode_put_nodeValue( This->node, value );
463 static HRESULT WINAPI domdoc_get_nodeType(
464 IXMLDOMDocument2 *iface,
467 domdoc *This = impl_from_IXMLDOMDocument2( iface );
468 return IXMLDOMNode_get_nodeType( This->node, type );
472 static HRESULT WINAPI domdoc_get_parentNode(
473 IXMLDOMDocument2 *iface,
474 IXMLDOMNode** parent )
476 domdoc *This = impl_from_IXMLDOMDocument2( iface );
477 return IXMLDOMNode_get_parentNode( This->node, parent );
481 static HRESULT WINAPI domdoc_get_childNodes(
482 IXMLDOMDocument2 *iface,
483 IXMLDOMNodeList** childList )
485 domdoc *This = impl_from_IXMLDOMDocument2( iface );
486 return IXMLDOMNode_get_childNodes( This->node, childList );
490 static HRESULT WINAPI domdoc_get_firstChild(
491 IXMLDOMDocument2 *iface,
492 IXMLDOMNode** firstChild )
494 domdoc *This = impl_from_IXMLDOMDocument2( iface );
495 return IXMLDOMNode_get_firstChild( This->node, firstChild );
499 static HRESULT WINAPI domdoc_get_lastChild(
500 IXMLDOMDocument2 *iface,
501 IXMLDOMNode** lastChild )
503 domdoc *This = impl_from_IXMLDOMDocument2( iface );
504 return IXMLDOMNode_get_lastChild( This->node, lastChild );
508 static HRESULT WINAPI domdoc_get_previousSibling(
509 IXMLDOMDocument2 *iface,
510 IXMLDOMNode** previousSibling )
512 domdoc *This = impl_from_IXMLDOMDocument2( iface );
513 return IXMLDOMNode_get_previousSibling( This->node, previousSibling );
517 static HRESULT WINAPI domdoc_get_nextSibling(
518 IXMLDOMDocument2 *iface,
519 IXMLDOMNode** nextSibling )
521 domdoc *This = impl_from_IXMLDOMDocument2( iface );
522 return IXMLDOMNode_get_nextSibling( This->node, nextSibling );
526 static HRESULT WINAPI domdoc_get_attributes(
527 IXMLDOMDocument2 *iface,
528 IXMLDOMNamedNodeMap** attributeMap )
530 domdoc *This = impl_from_IXMLDOMDocument2( iface );
531 return IXMLDOMNode_get_attributes( This->node, attributeMap );
535 static HRESULT WINAPI domdoc_insertBefore(
536 IXMLDOMDocument2 *iface,
537 IXMLDOMNode* newChild,
539 IXMLDOMNode** outNewChild )
541 domdoc *This = impl_from_IXMLDOMDocument2( iface );
542 return IXMLDOMNode_insertBefore( This->node, newChild, refChild, outNewChild );
546 static HRESULT WINAPI domdoc_replaceChild(
547 IXMLDOMDocument2 *iface,
548 IXMLDOMNode* newChild,
549 IXMLDOMNode* oldChild,
550 IXMLDOMNode** outOldChild)
552 domdoc *This = impl_from_IXMLDOMDocument2( iface );
553 return IXMLDOMNode_replaceChild( This->node, newChild, oldChild, outOldChild );
557 static HRESULT WINAPI domdoc_removeChild(
558 IXMLDOMDocument2 *iface,
559 IXMLDOMNode* childNode,
560 IXMLDOMNode** oldChild)
562 domdoc *This = impl_from_IXMLDOMDocument2( iface );
563 return IXMLDOMNode_removeChild( This->node, childNode, oldChild );
567 static HRESULT WINAPI domdoc_appendChild(
568 IXMLDOMDocument2 *iface,
569 IXMLDOMNode* newChild,
570 IXMLDOMNode** outNewChild)
572 domdoc *This = impl_from_IXMLDOMDocument2( iface );
573 return IXMLDOMNode_appendChild( This->node, newChild, outNewChild );
577 static HRESULT WINAPI domdoc_hasChildNodes(
578 IXMLDOMDocument2 *iface,
579 VARIANT_BOOL* hasChild)
581 domdoc *This = impl_from_IXMLDOMDocument2( iface );
582 return IXMLDOMNode_hasChildNodes( This->node, hasChild );
586 static HRESULT WINAPI domdoc_get_ownerDocument(
587 IXMLDOMDocument2 *iface,
588 IXMLDOMDocument** DOMDocument)
590 domdoc *This = impl_from_IXMLDOMDocument2( iface );
591 return IXMLDOMNode_get_ownerDocument( This->node, DOMDocument );
595 static HRESULT WINAPI domdoc_cloneNode(
596 IXMLDOMDocument2 *iface,
598 IXMLDOMNode** cloneRoot)
600 domdoc *This = impl_from_IXMLDOMDocument2( iface );
601 return IXMLDOMNode_cloneNode( This->node, deep, cloneRoot );
605 static HRESULT WINAPI domdoc_get_nodeTypeString(
606 IXMLDOMDocument2 *iface,
609 domdoc *This = impl_from_IXMLDOMDocument2( iface );
610 return IXMLDOMNode_get_nodeTypeString( This->node, nodeType );
614 static HRESULT WINAPI domdoc_get_text(
615 IXMLDOMDocument2 *iface,
618 domdoc *This = impl_from_IXMLDOMDocument2( iface );
619 return IXMLDOMNode_get_text( This->node, text );
623 static HRESULT WINAPI domdoc_put_text(
624 IXMLDOMDocument2 *iface,
627 domdoc *This = impl_from_IXMLDOMDocument2( iface );
628 return IXMLDOMNode_put_text( This->node, text );
632 static HRESULT WINAPI domdoc_get_specified(
633 IXMLDOMDocument2 *iface,
634 VARIANT_BOOL* isSpecified )
636 domdoc *This = impl_from_IXMLDOMDocument2( iface );
637 return IXMLDOMNode_get_specified( This->node, isSpecified );
641 static HRESULT WINAPI domdoc_get_definition(
642 IXMLDOMDocument2 *iface,
643 IXMLDOMNode** definitionNode )
645 domdoc *This = impl_from_IXMLDOMDocument2( iface );
646 return IXMLDOMNode_get_definition( This->node, definitionNode );
650 static HRESULT WINAPI domdoc_get_nodeTypedValue(
651 IXMLDOMDocument2 *iface,
652 VARIANT* typedValue )
654 domdoc *This = impl_from_IXMLDOMDocument2( iface );
655 return IXMLDOMNode_get_nodeTypedValue( This->node, typedValue );
658 static HRESULT WINAPI domdoc_put_nodeTypedValue(
659 IXMLDOMDocument2 *iface,
662 domdoc *This = impl_from_IXMLDOMDocument2( iface );
663 return IXMLDOMNode_put_nodeTypedValue( This->node, typedValue );
667 static HRESULT WINAPI domdoc_get_dataType(
668 IXMLDOMDocument2 *iface,
669 VARIANT* dataTypeName )
671 domdoc *This = impl_from_IXMLDOMDocument2( iface );
672 return IXMLDOMNode_get_dataType( This->node, dataTypeName );
676 static HRESULT WINAPI domdoc_put_dataType(
677 IXMLDOMDocument2 *iface,
680 domdoc *This = impl_from_IXMLDOMDocument2( iface );
681 return IXMLDOMNode_put_dataType( This->node, dataTypeName );
685 static HRESULT WINAPI domdoc_get_xml(
686 IXMLDOMDocument2 *iface,
689 domdoc *This = impl_from_IXMLDOMDocument2( iface );
690 return IXMLDOMNode_get_xml( This->node, xmlString );
694 static HRESULT WINAPI domdoc_transformNode(
695 IXMLDOMDocument2 *iface,
696 IXMLDOMNode* styleSheet,
699 domdoc *This = impl_from_IXMLDOMDocument2( iface );
700 return IXMLDOMNode_transformNode( This->node, styleSheet, xmlString );
704 static HRESULT WINAPI domdoc_selectNodes(
705 IXMLDOMDocument2 *iface,
707 IXMLDOMNodeList** resultList )
709 domdoc *This = impl_from_IXMLDOMDocument2( iface );
710 return IXMLDOMNode_selectNodes( This->node, queryString, resultList );
714 static HRESULT WINAPI domdoc_selectSingleNode(
715 IXMLDOMDocument2 *iface,
717 IXMLDOMNode** resultNode )
719 domdoc *This = impl_from_IXMLDOMDocument2( iface );
720 return IXMLDOMNode_selectSingleNode( This->node, queryString, resultNode );
724 static HRESULT WINAPI domdoc_get_parsed(
725 IXMLDOMDocument2 *iface,
726 VARIANT_BOOL* isParsed )
728 domdoc *This = impl_from_IXMLDOMDocument2( iface );
729 return IXMLDOMNode_get_parsed( This->node, isParsed );
733 static HRESULT WINAPI domdoc_get_namespaceURI(
734 IXMLDOMDocument2 *iface,
737 domdoc *This = impl_from_IXMLDOMDocument2( iface );
738 return IXMLDOMNode_get_namespaceURI( This->node, namespaceURI );
742 static HRESULT WINAPI domdoc_get_prefix(
743 IXMLDOMDocument2 *iface,
746 domdoc *This = impl_from_IXMLDOMDocument2( iface );
747 return IXMLDOMNode_get_prefix( This->node, prefixString );
751 static HRESULT WINAPI domdoc_get_baseName(
752 IXMLDOMDocument2 *iface,
755 domdoc *This = impl_from_IXMLDOMDocument2( iface );
756 return IXMLDOMNode_get_baseName( This->node, nameString );
760 static HRESULT WINAPI domdoc_transformNodeToObject(
761 IXMLDOMDocument2 *iface,
762 IXMLDOMNode* stylesheet,
763 VARIANT outputObject)
765 domdoc *This = impl_from_IXMLDOMDocument2( iface );
766 return IXMLDOMNode_transformNodeToObject( This->node, stylesheet, outputObject );
770 static HRESULT WINAPI domdoc_get_doctype(
771 IXMLDOMDocument2 *iface,
772 IXMLDOMDocumentType** documentType )
779 static HRESULT WINAPI domdoc_get_implementation(
780 IXMLDOMDocument2 *iface,
781 IXMLDOMImplementation** impl )
786 *impl = (IXMLDOMImplementation*)create_doc_Implementation();
791 static HRESULT WINAPI domdoc_get_documentElement(
792 IXMLDOMDocument2 *iface,
793 IXMLDOMElement** DOMElement )
795 domdoc *This = impl_from_IXMLDOMDocument2( iface );
796 xmlDocPtr xmldoc = NULL;
797 xmlNodePtr root = NULL;
798 IXMLDOMNode *element_node;
801 TRACE("%p %p\n", This, This->node);
808 xmldoc = get_doc( This );
810 root = xmlDocGetRootElement( xmldoc );
814 element_node = create_node( root );
815 if(!element_node) return S_FALSE;
817 hr = IXMLDOMNode_QueryInterface(element_node, &IID_IXMLDOMElement, (LPVOID*)DOMElement);
818 IXMLDOMNode_Release(element_node);
824 static HRESULT WINAPI domdoc_put_documentElement(
825 IXMLDOMDocument2 *iface,
826 IXMLDOMElement* DOMElement )
828 domdoc *This = impl_from_IXMLDOMDocument2( iface );
829 IXMLDOMNode *elementNode;
833 TRACE("(%p)->(%p)\n", This, DOMElement);
835 hr = IXMLDOMElement_QueryInterface( DOMElement, &IID_IXMLDOMNode, (void**)&elementNode );
839 xmlNode = impl_from_IXMLDOMNode( elementNode );
840 xmlDocSetRootElement( get_doc(This), xmlNode->node);
841 IXMLDOMNode_Release( elementNode );
847 static HRESULT WINAPI domdoc_createElement(
848 IXMLDOMDocument2 *iface,
850 IXMLDOMElement** element )
853 domdoc *This = impl_from_IXMLDOMDocument2( iface );
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);
874 static HRESULT WINAPI domdoc_createDocumentFragment(
875 IXMLDOMDocument2 *iface,
876 IXMLDOMDocumentFragment** docFrag )
878 domdoc *This = impl_from_IXMLDOMDocument2( iface );
881 TRACE("%p\n", iface);
888 xmlnode = xmlNewDocFragment(get_doc( This ) );
893 xmlnode->doc = get_doc( This );
895 *docFrag = (IXMLDOMDocumentFragment*)create_doc_fragment(xmlnode);
901 static HRESULT WINAPI domdoc_createTextNode(
902 IXMLDOMDocument2 *iface,
906 domdoc *This = impl_from_IXMLDOMDocument2( iface );
908 xmlChar *xml_content;
910 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), text);
917 xml_content = xmlChar_from_wchar((WCHAR*)data);
918 xmlnode = xmlNewText(xml_content);
919 HeapFree(GetProcessHeap(), 0, xml_content);
924 xmlnode->doc = get_doc( This );
926 *text = (IXMLDOMText*)create_text(xmlnode);
932 static HRESULT WINAPI domdoc_createComment(
933 IXMLDOMDocument2 *iface,
935 IXMLDOMComment** comment )
937 domdoc *This = impl_from_IXMLDOMDocument2( iface );
939 xmlChar *xml_content;
941 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), comment);
948 xml_content = xmlChar_from_wchar((WCHAR*)data);
949 xmlnode = xmlNewComment(xml_content);
950 HeapFree(GetProcessHeap(), 0, xml_content);
955 xmlnode->doc = get_doc( This );
957 *comment = (IXMLDOMComment*)create_comment(xmlnode);
963 static HRESULT WINAPI domdoc_createCDATASection(
964 IXMLDOMDocument2 *iface,
966 IXMLDOMCDATASection** cdata )
968 domdoc *This = impl_from_IXMLDOMDocument2( iface );
970 xmlChar *xml_content;
972 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), cdata);
979 xml_content = xmlChar_from_wchar((WCHAR*)data);
980 xmlnode = xmlNewCDataBlock(get_doc( This ), xml_content, strlen( (char*)xml_content) );
981 HeapFree(GetProcessHeap(), 0, xml_content);
986 xmlnode->doc = get_doc( This );
988 *cdata = (IXMLDOMCDATASection*)create_cdata(xmlnode);
994 static HRESULT WINAPI domdoc_createProcessingInstruction(
995 IXMLDOMDocument2 *iface,
998 IXMLDOMProcessingInstruction** pi )
1000 #ifdef HAVE_XMLNEWDOCPI
1002 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1003 xmlChar *xml_target, *xml_content;
1005 TRACE("%p->(%s %s %p)\n", iface, debugstr_w(target), debugstr_w(data), pi);
1008 return E_INVALIDARG;
1010 if(!target || lstrlenW(target) == 0)
1013 xml_target = xmlChar_from_wchar((WCHAR*)target);
1014 xml_content = xmlChar_from_wchar((WCHAR*)data);
1016 xmlnode = xmlNewDocPI(get_doc(This), xml_target, xml_content);
1017 TRACE("created xmlptr %p\n", xmlnode);
1018 *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode);
1020 HeapFree(GetProcessHeap(), 0, xml_content);
1021 HeapFree(GetProcessHeap(), 0, xml_target);
1025 FIXME("Libxml 2.6.15 or greater required.\n");
1031 static HRESULT WINAPI domdoc_createAttribute(
1032 IXMLDOMDocument2 *iface,
1034 IXMLDOMAttribute** attribute )
1036 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1040 TRACE("%p->(%s %p)\n", iface, debugstr_w(name), attribute);
1043 return E_INVALIDARG;
1047 xml_name = xmlChar_from_wchar((WCHAR*)name);
1048 xmlnode = (xmlNode *)xmlNewProp(NULL, xml_name, NULL);
1049 HeapFree(GetProcessHeap(), 0, xml_name);
1054 xmlnode->doc = get_doc( This );
1056 *attribute = (IXMLDOMAttribute*)create_attribute(xmlnode);
1062 static HRESULT WINAPI domdoc_createEntityReference(
1063 IXMLDOMDocument2 *iface,
1065 IXMLDOMEntityReference** entityRef )
1067 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1071 TRACE("%p\n", iface);
1074 return E_INVALIDARG;
1078 xml_name = xmlChar_from_wchar((WCHAR*)name);
1079 xmlnode = xmlNewReference(get_doc( This ), xml_name );
1080 HeapFree(GetProcessHeap(), 0, xml_name);
1085 xmlnode->doc = get_doc( This );
1087 *entityRef = (IXMLDOMEntityReference*)create_doc_entity_ref(xmlnode);
1093 static HRESULT WINAPI domdoc_getElementsByTagName(
1094 IXMLDOMDocument2 *iface,
1096 IXMLDOMNodeList** resultList )
1098 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1101 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1103 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(2+lstrlenW(tagName)+1));
1104 szPattern[0] = szPattern[1] = '/';
1105 lstrcpyW(szPattern + 2, tagName);
1107 hr = queryresult_create((xmlNodePtr)get_doc(This), szPattern, resultList);
1108 HeapFree(GetProcessHeap(), 0, szPattern);
1113 static HRESULT get_node_type(VARIANT Type, DOMNodeType * type)
1119 hr = VariantChangeType(&tmp, &Type, 0, VT_I4);
1121 return E_INVALIDARG;
1128 static HRESULT WINAPI domdoc_createNode(
1129 IXMLDOMDocument2 *iface,
1133 IXMLDOMNode** node )
1135 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1136 DOMNodeType node_type;
1137 xmlNodePtr xmlnode = NULL;
1141 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
1143 hr = get_node_type(Type, &node_type);
1147 TRACE("node_type %d\n", node_type);
1149 xml_name = xmlChar_from_wchar((WCHAR*)name);
1154 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
1155 *node = create_node(xmlnode);
1156 TRACE("created %p\n", xmlnode);
1158 case NODE_ATTRIBUTE:
1159 xmlnode = (xmlNode *)xmlNewProp(NULL, xml_name, NULL);
1162 xmlnode->doc = get_doc( This );
1164 *node = (IXMLDOMNode*)create_attribute(xmlnode);
1167 TRACE("created %p\n", xmlnode);
1171 FIXME("unhandled node type %d\n", node_type);
1175 HeapFree(GetProcessHeap(), 0, xml_name);
1177 if(xmlnode && *node)
1183 static HRESULT WINAPI domdoc_nodeFromID(
1184 IXMLDOMDocument2 *iface,
1186 IXMLDOMNode** node )
1192 static HRESULT domdoc_onDataAvailable(void *obj, char *ptr, DWORD len)
1197 xmldoc = doparse( ptr, len );
1199 xmldoc->_private = 0;
1200 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1206 static HRESULT doread( domdoc *This, LPWSTR filename )
1211 hr = bind_url(filename, domdoc_onDataAvailable, This, &bsc);
1216 detach_bsc(This->bsc);
1222 static HRESULT WINAPI domdoc_load(
1223 IXMLDOMDocument2 *iface,
1225 VARIANT_BOOL* isSuccessful )
1227 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1228 LPWSTR filename = NULL;
1229 HRESULT hr = S_FALSE;
1230 IXMLDOMDocument2 *pNewDoc = NULL;
1231 IStream *pStream = NULL;
1234 TRACE("type %d\n", V_VT(&xmlSource) );
1236 *isSuccessful = VARIANT_FALSE;
1238 assert( This->node );
1240 attach_xmlnode(This->node, NULL);
1242 switch( V_VT(&xmlSource) )
1245 filename = V_BSTR(&xmlSource);
1248 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IXMLDOMDocument2, (void**)&pNewDoc);
1253 domdoc *newDoc = impl_from_IXMLDOMDocument2( pNewDoc );
1254 xmldoc = xmlCopyDoc(get_doc(newDoc), 1);
1255 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1257 *isSuccessful = VARIANT_TRUE;
1262 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IStream, (void**)&pStream);
1265 IPersistStream *pDocStream;
1266 hr = IUnknown_QueryInterface(iface, &IID_IPersistStream, (void**)&pDocStream);
1269 hr = xmldoc_IPersistStream_Load(pDocStream, pStream);
1270 IStream_Release(pStream);
1273 *isSuccessful = VARIANT_TRUE;
1275 TRACE("Using ID_IStream to load Document\n");
1280 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr);
1285 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr);
1290 /* ISequentialStream */
1291 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr, pNewDoc, V_UNKNOWN(&xmlSource)->lpVtbl);
1295 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource));
1298 TRACE("filename (%s)\n", debugstr_w(filename));
1302 hr = doread( This, filename );
1305 This->error = E_FAIL;
1308 hr = This->error = S_OK;
1309 *isSuccessful = VARIANT_TRUE;
1313 if(!filename || FAILED(hr)) {
1314 xmldoc = xmlNewDoc(NULL);
1315 xmldoc->_private = 0;
1316 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1320 TRACE("ret (%d)\n", hr);
1326 static HRESULT WINAPI domdoc_get_readyState(
1327 IXMLDOMDocument2 *iface,
1335 static HRESULT WINAPI domdoc_get_parseError(
1336 IXMLDOMDocument2 *iface,
1337 IXMLDOMParseError** errorObj )
1339 BSTR error_string = NULL;
1340 static const WCHAR err[] = {'e','r','r','o','r',0};
1341 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1343 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1346 error_string = SysAllocString(err);
1348 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1349 if(!*errorObj) return E_OUTOFMEMORY;
1354 static HRESULT WINAPI domdoc_get_url(
1355 IXMLDOMDocument2 *iface,
1363 static HRESULT WINAPI domdoc_get_async(
1364 IXMLDOMDocument2 *iface,
1365 VARIANT_BOOL* isAsync )
1367 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1369 TRACE("%p <- %d\n", isAsync, This->async);
1370 *isAsync = This->async;
1375 static HRESULT WINAPI domdoc_put_async(
1376 IXMLDOMDocument2 *iface,
1377 VARIANT_BOOL isAsync )
1379 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1381 TRACE("%d\n", isAsync);
1382 This->async = isAsync;
1387 static HRESULT WINAPI domdoc_abort(
1388 IXMLDOMDocument2 *iface )
1395 static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1397 UINT len, blen = SysStringLen( bstr );
1400 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1401 str = HeapAlloc( GetProcessHeap(), 0, len );
1404 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1410 static HRESULT WINAPI domdoc_loadXML(
1411 IXMLDOMDocument2 *iface,
1413 VARIANT_BOOL* isSuccessful )
1415 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1416 xmlDocPtr xmldoc = NULL;
1419 HRESULT hr = S_FALSE;
1421 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1423 assert ( This->node );
1425 attach_xmlnode( This->node, NULL );
1429 *isSuccessful = VARIANT_FALSE;
1431 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1433 xmldoc = doparse( str, len );
1434 HeapFree( GetProcessHeap(), 0, str );
1436 This->error = E_FAIL;
1439 hr = This->error = S_OK;
1440 *isSuccessful = VARIANT_TRUE;
1445 xmldoc = xmlNewDoc(NULL);
1447 xmldoc->_private = 0;
1448 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1454 static HRESULT WINAPI domdoc_save(
1455 IXMLDOMDocument2 *iface,
1456 VARIANT destination )
1458 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1465 TRACE("(%p)->(var(vt %d, %s))\n", This, V_VT(&destination),
1466 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1468 if(V_VT(&destination) != VT_BSTR && V_VT(&destination) != VT_UNKNOWN)
1470 FIXME("Unhandled vt %d\n", V_VT(&destination));
1474 if(V_VT(&destination) == VT_UNKNOWN)
1476 IUnknown *pUnk = V_UNKNOWN(&destination);
1477 IXMLDOMDocument *pDocument;
1479 ret = IXMLDOMDocument_QueryInterface(pUnk, &IID_IXMLDOMDocument2, (void**)&pDocument);
1483 VARIANT_BOOL bSuccessful;
1485 ret = IXMLDOMDocument_get_xml(iface, &bXML);
1488 ret = IXMLDOMDocument_loadXML(pDocument, bXML, &bSuccessful);
1490 SysFreeString(bXML);
1493 IXMLDOMDocument_Release(pDocument);
1496 TRACE("ret %d\n", ret);
1501 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1502 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1503 if( handle == INVALID_HANDLE_VALUE )
1505 WARN("failed to create file\n");
1509 xmlDocDumpMemory(get_doc(This), &mem, &size);
1512 * libxml2 always adds XML declaration on top of the file and one for each processing instruction node in DOM tree.
1513 * MSXML adds XML declaration only for processing instruction nodes.
1514 * We skip the first XML declaration generated by libxml2 to get exactly what we need.
1517 if(size > 2 && p[0] == '<' && p[1] == '?') {
1518 while(p < mem+size && (p[0] != '?' || p[1] != '>'))
1521 while(p < mem+size && isspace(*p))
1526 if(!WriteFile(handle, p, (DWORD)size, &written, NULL) || written != (DWORD)size)
1528 WARN("write error\n");
1533 CloseHandle(handle);
1537 static HRESULT WINAPI domdoc_get_validateOnParse(
1538 IXMLDOMDocument2 *iface,
1539 VARIANT_BOOL* isValidating )
1541 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1543 TRACE("%p <- %d\n", isValidating, This->validating);
1544 *isValidating = This->validating;
1549 static HRESULT WINAPI domdoc_put_validateOnParse(
1550 IXMLDOMDocument2 *iface,
1551 VARIANT_BOOL isValidating )
1553 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1555 TRACE("%d\n", isValidating);
1556 This->validating = isValidating;
1561 static HRESULT WINAPI domdoc_get_resolveExternals(
1562 IXMLDOMDocument2 *iface,
1563 VARIANT_BOOL* isResolving )
1565 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1567 TRACE("%p <- %d\n", isResolving, This->resolving);
1568 *isResolving = This->resolving;
1573 static HRESULT WINAPI domdoc_put_resolveExternals(
1574 IXMLDOMDocument2 *iface,
1575 VARIANT_BOOL isResolving )
1577 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1579 TRACE("%d\n", isResolving);
1580 This->resolving = isResolving;
1585 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1586 IXMLDOMDocument2 *iface,
1587 VARIANT_BOOL* isPreserving )
1589 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1591 TRACE("%p <- %d\n", isPreserving, This->preserving);
1592 *isPreserving = This->preserving;
1597 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1598 IXMLDOMDocument2 *iface,
1599 VARIANT_BOOL isPreserving )
1601 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1603 TRACE("%d\n", isPreserving);
1604 This->preserving = isPreserving;
1609 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1610 IXMLDOMDocument2 *iface,
1611 VARIANT readyStateChangeSink )
1618 static HRESULT WINAPI domdoc_put_onDataAvailable(
1619 IXMLDOMDocument2 *iface,
1620 VARIANT onDataAvailableSink )
1626 static HRESULT WINAPI domdoc_put_onTransformNode(
1627 IXMLDOMDocument2 *iface,
1628 VARIANT onTransformNodeSink )
1634 static HRESULT WINAPI domdoc_get_namespaces(
1635 IXMLDOMDocument2* iface,
1636 IXMLDOMSchemaCollection** schemaCollection )
1642 static HRESULT WINAPI domdoc_get_schemas(
1643 IXMLDOMDocument2* iface,
1646 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1647 HRESULT hr = S_FALSE;
1648 IXMLDOMSchemaCollection *cur_schema = This->schema;
1650 TRACE("(%p)->(%p)\n", This, var1);
1652 VariantInit(var1); /* Test shows we don't call VariantClear here */
1653 V_VT(var1) = VT_NULL;
1657 hr = IXMLDOMSchemaCollection_QueryInterface(cur_schema, &IID_IDispatch, (void**)&V_DISPATCH(var1));
1659 V_VT(var1) = VT_DISPATCH;
1664 static HRESULT WINAPI domdoc_putref_schemas(
1665 IXMLDOMDocument2* iface,
1668 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1669 HRESULT hr = E_FAIL;
1670 IXMLDOMSchemaCollection *new_schema = NULL;
1672 FIXME("(%p): semi-stub\n", This);
1676 hr = IUnknown_QueryInterface(V_UNKNOWN(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1680 hr = IDispatch_QueryInterface(V_DISPATCH(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1689 WARN("Can't get schema from vt %x\n", V_VT(&var1));
1694 IXMLDOMSchemaCollection *old_schema = InterlockedExchangePointer((void**)&This->schema, new_schema);
1695 if(old_schema) IXMLDOMSchemaCollection_Release(old_schema);
1701 static HRESULT WINAPI domdoc_validate(
1702 IXMLDOMDocument2* iface,
1703 IXMLDOMParseError** err)
1709 static HRESULT WINAPI domdoc_setProperty(
1710 IXMLDOMDocument2* iface,
1714 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1716 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1722 V_VT(&varStr) = VT_EMPTY;
1723 if (V_VT(&var) != VT_BSTR)
1725 if (FAILED(hr = VariantChangeType(&varStr, &var, 0, VT_BSTR)))
1727 bstr = V_BSTR(&varStr);
1730 bstr = V_BSTR(&var);
1733 if (lstrcmpiW(bstr, SZ_VALUE_XPATH) == 0)
1734 This->bUseXPath = TRUE;
1735 else if (lstrcmpiW(bstr, SZ_VALUE_XSLPATTERN) == 0)
1736 This->bUseXPath = FALSE;
1740 VariantClear(&varStr);
1744 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1748 static HRESULT WINAPI domdoc_getProperty(
1749 IXMLDOMDocument2* iface,
1753 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1756 return E_INVALIDARG;
1757 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1759 V_VT(var) = VT_BSTR;
1760 if (This->bUseXPath)
1761 V_BSTR(var) = SysAllocString(SZ_VALUE_XPATH);
1763 V_BSTR(var) = SysAllocString(SZ_VALUE_XSLPATTERN);
1767 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1771 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl =
1773 domdoc_QueryInterface,
1776 domdoc_GetTypeInfoCount,
1778 domdoc_GetIDsOfNames,
1780 domdoc_get_nodeName,
1781 domdoc_get_nodeValue,
1782 domdoc_put_nodeValue,
1783 domdoc_get_nodeType,
1784 domdoc_get_parentNode,
1785 domdoc_get_childNodes,
1786 domdoc_get_firstChild,
1787 domdoc_get_lastChild,
1788 domdoc_get_previousSibling,
1789 domdoc_get_nextSibling,
1790 domdoc_get_attributes,
1791 domdoc_insertBefore,
1792 domdoc_replaceChild,
1795 domdoc_hasChildNodes,
1796 domdoc_get_ownerDocument,
1798 domdoc_get_nodeTypeString,
1801 domdoc_get_specified,
1802 domdoc_get_definition,
1803 domdoc_get_nodeTypedValue,
1804 domdoc_put_nodeTypedValue,
1805 domdoc_get_dataType,
1806 domdoc_put_dataType,
1808 domdoc_transformNode,
1810 domdoc_selectSingleNode,
1812 domdoc_get_namespaceURI,
1814 domdoc_get_baseName,
1815 domdoc_transformNodeToObject,
1817 domdoc_get_implementation,
1818 domdoc_get_documentElement,
1819 domdoc_put_documentElement,
1820 domdoc_createElement,
1821 domdoc_createDocumentFragment,
1822 domdoc_createTextNode,
1823 domdoc_createComment,
1824 domdoc_createCDATASection,
1825 domdoc_createProcessingInstruction,
1826 domdoc_createAttribute,
1827 domdoc_createEntityReference,
1828 domdoc_getElementsByTagName,
1832 domdoc_get_readyState,
1833 domdoc_get_parseError,
1840 domdoc_get_validateOnParse,
1841 domdoc_put_validateOnParse,
1842 domdoc_get_resolveExternals,
1843 domdoc_put_resolveExternals,
1844 domdoc_get_preserveWhiteSpace,
1845 domdoc_put_preserveWhiteSpace,
1846 domdoc_put_onReadyStateChange,
1847 domdoc_put_onDataAvailable,
1848 domdoc_put_onTransformNode,
1849 domdoc_get_namespaces,
1851 domdoc_putref_schemas,
1857 /* xmldoc implementation of IObjectWithSite */
1858 static HRESULT WINAPI
1859 xmldoc_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
1861 domdoc *This = impl_from_IObjectWithSite(iface);
1862 return IXMLDocument_QueryInterface( (IXMLDocument *)This, riid, ppvObject );
1866 xmldoc_ObjectWithSite_AddRef( IObjectWithSite* iface )
1868 domdoc *This = impl_from_IObjectWithSite(iface);
1869 return IXMLDocument_AddRef((IXMLDocument *)This);
1873 xmldoc_ObjectWithSite_Release( IObjectWithSite* iface )
1875 domdoc *This = impl_from_IObjectWithSite(iface);
1876 return IXMLDocument_Release((IXMLDocument *)This);
1879 static HRESULT WINAPI
1880 xmldoc_GetSite( IObjectWithSite *iface, REFIID iid, void ** ppvSite )
1882 domdoc *This = impl_from_IObjectWithSite(iface);
1884 TRACE("%p %s %p\n", This, debugstr_guid( iid ), ppvSite );
1889 return IUnknown_QueryInterface( This->site, iid, ppvSite );
1892 static HRESULT WINAPI
1893 xmldoc_SetSite( IObjectWithSite *iface, IUnknown *punk )
1895 domdoc *This = impl_from_IObjectWithSite(iface);
1897 TRACE("%p %p\n", iface, punk);
1903 IUnknown_Release( This->site );
1911 IUnknown_AddRef( punk );
1914 IUnknown_Release( This->site );
1921 static const IObjectWithSiteVtbl domdocObjectSite =
1923 xmldoc_ObjectWithSite_QueryInterface,
1924 xmldoc_ObjectWithSite_AddRef,
1925 xmldoc_ObjectWithSite_Release,
1930 static HRESULT WINAPI xmldoc_Safety_QueryInterface(IObjectSafety *iface, REFIID riid, void **ppv)
1932 domdoc *This = impl_from_IObjectSafety(iface);
1933 return IXMLDocument_QueryInterface( (IXMLDocument *)This, riid, ppv );
1936 static ULONG WINAPI xmldoc_Safety_AddRef(IObjectSafety *iface)
1938 domdoc *This = impl_from_IObjectSafety(iface);
1939 return IXMLDocument_AddRef((IXMLDocument *)This);
1942 static ULONG WINAPI xmldoc_Safety_Release(IObjectSafety *iface)
1944 domdoc *This = impl_from_IObjectSafety(iface);
1945 return IXMLDocument_Release((IXMLDocument *)This);
1948 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER)
1950 static HRESULT WINAPI xmldoc_Safety_GetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1951 DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions)
1953 domdoc *This = impl_from_IObjectSafety(iface);
1955 TRACE("(%p)->(%s %p %p)\n", This, debugstr_guid(riid), pdwSupportedOptions, pdwEnabledOptions);
1957 if(!pdwSupportedOptions || !pdwEnabledOptions)
1960 *pdwSupportedOptions = SUPPORTED_OPTIONS;
1961 *pdwEnabledOptions = This->safeopt;
1966 static HRESULT WINAPI xmldoc_Safety_SetInterfaceSafetyOptions(IObjectSafety *iface, REFIID riid,
1967 DWORD dwOptionSetMask, DWORD dwEnabledOptions)
1969 domdoc *This = impl_from_IObjectSafety(iface);
1971 TRACE("(%p)->(%s %x %x)\n", This, debugstr_guid(riid), dwOptionSetMask, dwEnabledOptions);
1973 if(dwOptionSetMask & ~SUPPORTED_OPTIONS)
1976 This->safeopt = dwEnabledOptions & dwEnabledOptions;
1980 static const IObjectSafetyVtbl domdocObjectSafetyVtbl = {
1981 xmldoc_Safety_QueryInterface,
1982 xmldoc_Safety_AddRef,
1983 xmldoc_Safety_Release,
1984 xmldoc_Safety_GetInterfaceSafetyOptions,
1985 xmldoc_Safety_SetInterfaceSafetyOptions
1989 static const tid_t domdoc_iface_tids[] = {
1991 IXMLDOMDocument_tid,
1992 IXMLDOMDocument2_tid,
1995 static dispex_static_data_t domdoc_dispex = {
1997 IXMLDOMDocument2_tid,
2002 HRESULT DOMDocument_create_from_xmldoc(xmlDocPtr xmldoc, IXMLDOMDocument2 **document)
2007 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
2009 return E_OUTOFMEMORY;
2011 doc->lpVtbl = &domdoc_vtbl;
2012 doc->lpvtblIPersistStream = &xmldoc_IPersistStream_VTable;
2013 doc->lpvtblIObjectWithSite = &domdocObjectSite;
2014 doc->lpvtblIObjectSafety = &domdocObjectSafetyVtbl;
2017 doc->validating = 0;
2019 doc->preserving = 0;
2020 doc->bUseXPath = FALSE;
2028 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
2031 HeapFree(GetProcessHeap(), 0, doc);
2035 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
2038 IUnknown_Release(doc->node_unk);
2039 HeapFree( GetProcessHeap(), 0, doc );
2043 init_dispex(&doc->dispex, (IUnknown*)&doc->lpVtbl, &domdoc_dispex);
2045 /* The ref on doc->node is actually looped back into this object, so release it */
2046 IXMLDOMNode_Release(doc->node);
2048 *document = (IXMLDOMDocument2*)&doc->lpVtbl;
2050 TRACE("returning iface %p\n", *document);
2054 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2059 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
2061 xmldoc = xmlNewDoc(NULL);
2063 return E_OUTOFMEMORY;
2065 xmldoc->_private = 0;
2067 hr = DOMDocument_create_from_xmldoc(xmldoc, (IXMLDOMDocument2**)ppObj);
2074 IUnknown* create_domdoc( xmlNodePtr document )
2079 TRACE("(%p)\n", document);
2081 hr = DOMDocument_create_from_xmldoc((xmlDocPtr)document, (IXMLDOMDocument2**)&pObj);
2085 return (IUnknown*)pObj;
2090 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
2092 MESSAGE("This program tried to use a DOMDocument object, but\n"
2093 "libxml2 support was not present at compile time.\n");