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};
52 typedef struct bsc_t bsc_t
;
54 typedef struct _domdoc
56 const struct IXMLDOMDocument2Vtbl
*lpVtbl
;
57 const struct IPersistStreamVtbl
*lpvtblIPersistStream
;
58 const struct IObjectWithSiteVtbl
*lpvtblIObjectWithSite
;
59 const struct IObjectSafetyVtbl
*lpvtblIObjectSafety
;
62 VARIANT_BOOL validating
;
63 VARIANT_BOOL resolving
;
64 VARIANT_BOOL preserving
;
68 IXMLDOMSchemaCollection
*schema
;
83 const struct IBindStatusCallbackVtbl
*lpVtbl
;
92 static inline bsc_t
*impl_from_IBindStatusCallback( IBindStatusCallback
*iface
)
94 return (bsc_t
*)((char*)iface
- FIELD_OFFSET(bsc_t
, lpVtbl
));
97 static xmlDocPtr
doparse( char *ptr
, int len
)
99 #ifdef HAVE_XMLREADMEMORY
101 * use xmlReadMemory if possible so we can suppress
102 * writing errors to stderr
104 return xmlReadMemory( ptr
, len
, NULL
, NULL
,
105 XML_PARSE_NOERROR
| XML_PARSE_NOWARNING
| XML_PARSE_NOBLANKS
);
107 return xmlParseMemory( ptr
, len
);
111 static HRESULT WINAPI
bsc_QueryInterface(
112 IBindStatusCallback
*iface
,
116 if (IsEqualGUID(riid
, &IID_IUnknown
) ||
117 IsEqualGUID(riid
, &IID_IBindStatusCallback
))
119 IBindStatusCallback_AddRef( iface
);
124 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
125 return E_NOINTERFACE
;
128 static ULONG WINAPI
bsc_AddRef(
129 IBindStatusCallback
*iface
)
131 bsc_t
*This
= impl_from_IBindStatusCallback(iface
);
132 LONG ref
= InterlockedIncrement(&This
->ref
);
134 TRACE("(%p) ref=%d\n", This
, ref
);
139 static ULONG WINAPI
bsc_Release(
140 IBindStatusCallback
*iface
)
142 bsc_t
*This
= impl_from_IBindStatusCallback(iface
);
143 LONG ref
= InterlockedDecrement(&This
->ref
);
145 TRACE("(%p) ref=%d\n", This
, ref
);
149 IBinding_Release(This
->binding
);
150 if(This
->doc
&& This
->doc
->bsc
== This
)
151 This
->doc
->bsc
= NULL
;
153 IStream_Release(This
->memstream
);
154 HeapFree(GetProcessHeap(), 0, This
);
160 static HRESULT WINAPI
bsc_OnStartBinding(
161 IBindStatusCallback
* iface
,
165 bsc_t
*This
= impl_from_IBindStatusCallback(iface
);
168 TRACE("(%p)->(%x %p)\n", This
, dwReserved
, pib
);
171 IBindStatusCallback_AddRef(pib
);
173 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &This
->memstream
);
180 static HRESULT WINAPI
bsc_GetPriority(
181 IBindStatusCallback
* iface
,
187 static HRESULT WINAPI
bsc_OnLowResource(
188 IBindStatusCallback
* iface
,
194 static HRESULT WINAPI
bsc_OnProgress(
195 IBindStatusCallback
* iface
,
199 LPCWSTR szStatusText
)
204 static HRESULT WINAPI
bsc_OnStopBinding(
205 IBindStatusCallback
* iface
,
209 bsc_t
*This
= impl_from_IBindStatusCallback(iface
);
212 TRACE("(%p)->(%08x %s)\n", This
, hresult
, debugstr_w(szError
));
215 IBinding_Release(This
->binding
);
216 This
->binding
= NULL
;
219 if(This
->doc
&& SUCCEEDED(hresult
)) {
221 hr
= GetHGlobalFromStream(This
->memstream
, &hglobal
);
224 DWORD len
= GlobalSize(hglobal
);
225 char *ptr
= GlobalLock(hglobal
);
228 xmldoc
= doparse( ptr
, len
);
230 xmldoc
->_private
= 0;
231 attach_xmlnode(This
->doc
->node
, (xmlNodePtr
) xmldoc
);
234 GlobalUnlock(hglobal
);
241 static HRESULT WINAPI
bsc_GetBindInfo(
242 IBindStatusCallback
* iface
,
246 *grfBINDF
= BINDF_RESYNCHRONIZE
;
251 static HRESULT WINAPI
bsc_OnDataAvailable(
252 IBindStatusCallback
* iface
,
255 FORMATETC
* pformatetc
,
258 bsc_t
*This
= impl_from_IBindStatusCallback(iface
);
263 TRACE("(%p)->(%x %d %p %p)\n", This
, grfBSCF
, dwSize
, pformatetc
, pstgmed
);
267 hr
= IStream_Read(pstgmed
->pstm
, buf
, sizeof(buf
), &read
);
271 hr
= IStream_Write(This
->memstream
, buf
, read
, &written
);
272 } while(SUCCEEDED(hr
) && written
!= 0 && read
!= 0);
277 static HRESULT WINAPI
bsc_OnObjectAvailable(
278 IBindStatusCallback
* iface
,
285 static const struct IBindStatusCallbackVtbl bsc_vtbl
=
297 bsc_OnObjectAvailable
300 static bsc_t
*create_bsc(domdoc
*doc
)
302 bsc_t
*bsc
= HeapAlloc(GetProcessHeap(), 0, sizeof(bsc
));
304 bsc
->lpVtbl
= &bsc_vtbl
;
312 LONG
xmldoc_add_ref(xmlDocPtr doc
)
314 LONG ref
= InterlockedIncrement((LONG
*)&doc
->_private
);
319 LONG
xmldoc_release(xmlDocPtr doc
)
321 LONG ref
= InterlockedDecrement((LONG
*)&doc
->_private
);
325 TRACE("freeing docptr %p\n", doc
);
332 static inline domdoc
*impl_from_IXMLDOMDocument2( IXMLDOMDocument2
*iface
)
334 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpVtbl
));
337 static inline xmlDocPtr
get_doc( domdoc
*This
)
339 return (xmlDocPtr
) xmlNodePtr_from_domnode( This
->node
, XML_DOCUMENT_NODE
);
342 static inline domdoc
*impl_from_IPersistStream(IPersistStream
*iface
)
344 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpvtblIPersistStream
));
347 static inline domdoc
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
349 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpvtblIObjectWithSite
));
352 static inline domdoc
*impl_from_IObjectSafety(IObjectSafety
*iface
)
354 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpvtblIObjectSafety
));
358 /************************************************************************
359 * xmldoc implementation of IPersistStream.
361 static HRESULT WINAPI
xmldoc_IPersistStream_QueryInterface(
362 IPersistStream
*iface
, REFIID riid
, LPVOID
*ppvObj
)
364 domdoc
*this = impl_from_IPersistStream(iface
);
365 return IXMLDocument_QueryInterface((IXMLDocument
*)this, riid
, ppvObj
);
368 static ULONG WINAPI
xmldoc_IPersistStream_AddRef(
369 IPersistStream
*iface
)
371 domdoc
*this = impl_from_IPersistStream(iface
);
372 return IXMLDocument_AddRef((IXMLDocument
*)this);
375 static ULONG WINAPI
xmldoc_IPersistStream_Release(
376 IPersistStream
*iface
)
378 domdoc
*this = impl_from_IPersistStream(iface
);
379 return IXMLDocument_Release((IXMLDocument
*)this);
382 static HRESULT WINAPI
xmldoc_IPersistStream_GetClassID(
383 IPersistStream
*iface
, CLSID
*classid
)
385 TRACE("(%p,%p): stub!\n", iface
, classid
);
390 *classid
= CLSID_DOMDocument2
;
395 static HRESULT WINAPI
xmldoc_IPersistStream_IsDirty(
396 IPersistStream
*iface
)
398 domdoc
*This
= impl_from_IPersistStream(iface
);
400 FIXME("(%p->%p): stub!\n", iface
, This
);
405 static HRESULT WINAPI
xmldoc_IPersistStream_Load(
406 IPersistStream
*iface
, LPSTREAM pStm
)
408 domdoc
*This
= impl_from_IPersistStream(iface
);
411 DWORD read
, written
, len
;
414 xmlDocPtr xmldoc
= NULL
;
416 TRACE("(%p, %p)\n", iface
, pStm
);
421 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &This
->stream
);
427 IStream_Read(pStm
, buf
, sizeof(buf
), &read
);
428 hr
= IStream_Write(This
->stream
, buf
, read
, &written
);
429 } while(SUCCEEDED(hr
) && written
!= 0 && read
!= 0);
433 ERR("Failed to copy stream\n");
437 hr
= GetHGlobalFromStream(This
->stream
, &hglobal
);
441 len
= GlobalSize(hglobal
);
442 ptr
= GlobalLock(hglobal
);
444 xmldoc
= parse_xml(ptr
, len
);
445 GlobalUnlock(hglobal
);
449 ERR("Failed to parse xml\n");
453 attach_xmlnode( This
->node
, (xmlNodePtr
)xmldoc
);
458 static HRESULT WINAPI
xmldoc_IPersistStream_Save(
459 IPersistStream
*iface
, LPSTREAM pStm
, BOOL fClearDirty
)
461 FIXME("(%p, %p, %d): stub!\n", iface
, pStm
, fClearDirty
);
465 static HRESULT WINAPI
xmldoc_IPersistStream_GetSizeMax(
466 IPersistStream
*iface
, ULARGE_INTEGER
*pcbSize
)
468 TRACE("(%p, %p): stub!\n", iface
, pcbSize
);
472 static const IPersistStreamVtbl xmldoc_IPersistStream_VTable
=
474 xmldoc_IPersistStream_QueryInterface
,
475 xmldoc_IPersistStream_AddRef
,
476 xmldoc_IPersistStream_Release
,
477 xmldoc_IPersistStream_GetClassID
,
478 xmldoc_IPersistStream_IsDirty
,
479 xmldoc_IPersistStream_Load
,
480 xmldoc_IPersistStream_Save
,
481 xmldoc_IPersistStream_GetSizeMax
,
484 static HRESULT WINAPI
domdoc_QueryInterface( IXMLDOMDocument2
*iface
, REFIID riid
, void** ppvObject
)
486 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
488 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
492 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
493 IsEqualGUID( riid
, &IID_IDispatch
) ||
494 IsEqualGUID( riid
, &IID_IXMLDOMDocument
) ||
495 IsEqualGUID( riid
, &IID_IXMLDOMDocument2
) )
499 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
501 return IUnknown_QueryInterface(This
->node_unk
, riid
, ppvObject
);
503 else if (IsEqualGUID(&IID_IPersistStream
, riid
))
505 *ppvObject
= (IPersistStream
*)&(This
->lpvtblIPersistStream
);
507 else if (IsEqualGUID(&IID_IObjectWithSite
, riid
))
509 *ppvObject
= (IObjectWithSite
*)&(This
->lpvtblIObjectWithSite
);
511 else if(IsEqualGUID(&IID_IRunnableObject
, riid
))
513 TRACE("IID_IRunnableObject not supported returning NULL\n");
514 return E_NOINTERFACE
;
518 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
519 return E_NOINTERFACE
;
522 IXMLDOMDocument_AddRef( iface
);
528 static ULONG WINAPI
domdoc_AddRef(
529 IXMLDOMDocument2
*iface
)
531 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
532 TRACE("%p\n", This
);
533 return InterlockedIncrement( &This
->ref
);
537 static ULONG WINAPI
domdoc_Release(
538 IXMLDOMDocument2
*iface
)
540 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
543 TRACE("%p\n", This
);
545 ref
= InterlockedDecrement( &This
->ref
);
549 if(This
->bsc
->binding
)
550 IBinding_Abort(This
->bsc
->binding
);
551 This
->bsc
->doc
= NULL
;
552 IBindStatusCallback_Release((IBindStatusCallback
*)&This
->bsc
->lpVtbl
);
556 IUnknown_Release( This
->site
);
557 IUnknown_Release( This
->node_unk
);
558 if(This
->schema
) IXMLDOMSchemaCollection_Release( This
->schema
);
559 if (This
->stream
) IStream_Release(This
->stream
);
560 HeapFree( GetProcessHeap(), 0, This
);
566 static HRESULT WINAPI
domdoc_GetTypeInfoCount( IXMLDOMDocument2
*iface
, UINT
* pctinfo
)
568 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
570 TRACE("(%p)->(%p)\n", This
, pctinfo
);
577 static HRESULT WINAPI
domdoc_GetTypeInfo(
578 IXMLDOMDocument2
*iface
,
579 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
581 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
584 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
586 hr
= get_typeinfo(IXMLDOMDocument2_tid
, ppTInfo
);
591 static HRESULT WINAPI
domdoc_GetIDsOfNames(
592 IXMLDOMDocument2
*iface
,
599 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
603 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
606 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
609 hr
= get_typeinfo(IXMLDOMDocument2_tid
, &typeinfo
);
612 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
613 ITypeInfo_Release(typeinfo
);
620 static HRESULT WINAPI
domdoc_Invoke(
621 IXMLDOMDocument2
*iface
,
626 DISPPARAMS
* pDispParams
,
628 EXCEPINFO
* pExcepInfo
,
631 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
635 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
636 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
638 hr
= get_typeinfo(IXMLDOMDocument2_tid
, &typeinfo
);
641 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
642 pVarResult
, pExcepInfo
, puArgErr
);
643 ITypeInfo_Release(typeinfo
);
650 static HRESULT WINAPI
domdoc_get_nodeName(
651 IXMLDOMDocument2
*iface
,
654 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
655 return IXMLDOMNode_get_nodeName( This
->node
, name
);
659 static HRESULT WINAPI
domdoc_get_nodeValue(
660 IXMLDOMDocument2
*iface
,
663 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
664 return IXMLDOMNode_get_nodeValue( This
->node
, value
);
668 static HRESULT WINAPI
domdoc_put_nodeValue(
669 IXMLDOMDocument2
*iface
,
672 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
673 return IXMLDOMNode_put_nodeValue( This
->node
, value
);
677 static HRESULT WINAPI
domdoc_get_nodeType(
678 IXMLDOMDocument2
*iface
,
681 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
682 return IXMLDOMNode_get_nodeType( This
->node
, type
);
686 static HRESULT WINAPI
domdoc_get_parentNode(
687 IXMLDOMDocument2
*iface
,
688 IXMLDOMNode
** parent
)
690 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
691 return IXMLDOMNode_get_parentNode( This
->node
, parent
);
695 static HRESULT WINAPI
domdoc_get_childNodes(
696 IXMLDOMDocument2
*iface
,
697 IXMLDOMNodeList
** childList
)
699 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
700 return IXMLDOMNode_get_childNodes( This
->node
, childList
);
704 static HRESULT WINAPI
domdoc_get_firstChild(
705 IXMLDOMDocument2
*iface
,
706 IXMLDOMNode
** firstChild
)
708 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
709 return IXMLDOMNode_get_firstChild( This
->node
, firstChild
);
713 static HRESULT WINAPI
domdoc_get_lastChild(
714 IXMLDOMDocument2
*iface
,
715 IXMLDOMNode
** lastChild
)
717 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
718 return IXMLDOMNode_get_lastChild( This
->node
, lastChild
);
722 static HRESULT WINAPI
domdoc_get_previousSibling(
723 IXMLDOMDocument2
*iface
,
724 IXMLDOMNode
** previousSibling
)
726 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
727 return IXMLDOMNode_get_previousSibling( This
->node
, previousSibling
);
731 static HRESULT WINAPI
domdoc_get_nextSibling(
732 IXMLDOMDocument2
*iface
,
733 IXMLDOMNode
** nextSibling
)
735 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
736 return IXMLDOMNode_get_nextSibling( This
->node
, nextSibling
);
740 static HRESULT WINAPI
domdoc_get_attributes(
741 IXMLDOMDocument2
*iface
,
742 IXMLDOMNamedNodeMap
** attributeMap
)
744 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
745 return IXMLDOMNode_get_attributes( This
->node
, attributeMap
);
749 static HRESULT WINAPI
domdoc_insertBefore(
750 IXMLDOMDocument2
*iface
,
751 IXMLDOMNode
* newChild
,
753 IXMLDOMNode
** outNewChild
)
755 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
756 return IXMLDOMNode_insertBefore( This
->node
, newChild
, refChild
, outNewChild
);
760 static HRESULT WINAPI
domdoc_replaceChild(
761 IXMLDOMDocument2
*iface
,
762 IXMLDOMNode
* newChild
,
763 IXMLDOMNode
* oldChild
,
764 IXMLDOMNode
** outOldChild
)
766 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
767 return IXMLDOMNode_replaceChild( This
->node
, newChild
, oldChild
, outOldChild
);
771 static HRESULT WINAPI
domdoc_removeChild(
772 IXMLDOMDocument2
*iface
,
773 IXMLDOMNode
* childNode
,
774 IXMLDOMNode
** oldChild
)
776 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
777 return IXMLDOMNode_removeChild( This
->node
, childNode
, oldChild
);
781 static HRESULT WINAPI
domdoc_appendChild(
782 IXMLDOMDocument2
*iface
,
783 IXMLDOMNode
* newChild
,
784 IXMLDOMNode
** outNewChild
)
786 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
787 return IXMLDOMNode_appendChild( This
->node
, newChild
, outNewChild
);
791 static HRESULT WINAPI
domdoc_hasChildNodes(
792 IXMLDOMDocument2
*iface
,
793 VARIANT_BOOL
* hasChild
)
795 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
796 return IXMLDOMNode_hasChildNodes( This
->node
, hasChild
);
800 static HRESULT WINAPI
domdoc_get_ownerDocument(
801 IXMLDOMDocument2
*iface
,
802 IXMLDOMDocument
** DOMDocument
)
804 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
805 return IXMLDOMNode_get_ownerDocument( This
->node
, DOMDocument
);
809 static HRESULT WINAPI
domdoc_cloneNode(
810 IXMLDOMDocument2
*iface
,
812 IXMLDOMNode
** cloneRoot
)
814 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
815 return IXMLDOMNode_cloneNode( This
->node
, deep
, cloneRoot
);
819 static HRESULT WINAPI
domdoc_get_nodeTypeString(
820 IXMLDOMDocument2
*iface
,
823 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
824 return IXMLDOMNode_get_nodeTypeString( This
->node
, nodeType
);
828 static HRESULT WINAPI
domdoc_get_text(
829 IXMLDOMDocument2
*iface
,
832 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
833 return IXMLDOMNode_get_text( This
->node
, text
);
837 static HRESULT WINAPI
domdoc_put_text(
838 IXMLDOMDocument2
*iface
,
841 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
842 return IXMLDOMNode_put_text( This
->node
, text
);
846 static HRESULT WINAPI
domdoc_get_specified(
847 IXMLDOMDocument2
*iface
,
848 VARIANT_BOOL
* isSpecified
)
850 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
851 return IXMLDOMNode_get_specified( This
->node
, isSpecified
);
855 static HRESULT WINAPI
domdoc_get_definition(
856 IXMLDOMDocument2
*iface
,
857 IXMLDOMNode
** definitionNode
)
859 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
860 return IXMLDOMNode_get_definition( This
->node
, definitionNode
);
864 static HRESULT WINAPI
domdoc_get_nodeTypedValue(
865 IXMLDOMDocument2
*iface
,
866 VARIANT
* typedValue
)
868 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
869 return IXMLDOMNode_get_nodeTypedValue( This
->node
, typedValue
);
872 static HRESULT WINAPI
domdoc_put_nodeTypedValue(
873 IXMLDOMDocument2
*iface
,
876 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
877 return IXMLDOMNode_put_nodeTypedValue( This
->node
, typedValue
);
881 static HRESULT WINAPI
domdoc_get_dataType(
882 IXMLDOMDocument2
*iface
,
883 VARIANT
* dataTypeName
)
885 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
886 return IXMLDOMNode_get_dataType( This
->node
, dataTypeName
);
890 static HRESULT WINAPI
domdoc_put_dataType(
891 IXMLDOMDocument2
*iface
,
894 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
895 return IXMLDOMNode_put_dataType( This
->node
, dataTypeName
);
899 static HRESULT WINAPI
domdoc_get_xml(
900 IXMLDOMDocument2
*iface
,
903 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
904 return IXMLDOMNode_get_xml( This
->node
, xmlString
);
908 static HRESULT WINAPI
domdoc_transformNode(
909 IXMLDOMDocument2
*iface
,
910 IXMLDOMNode
* styleSheet
,
913 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
914 return IXMLDOMNode_transformNode( This
->node
, styleSheet
, xmlString
);
918 static HRESULT WINAPI
domdoc_selectNodes(
919 IXMLDOMDocument2
*iface
,
921 IXMLDOMNodeList
** resultList
)
923 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
924 return IXMLDOMNode_selectNodes( This
->node
, queryString
, resultList
);
928 static HRESULT WINAPI
domdoc_selectSingleNode(
929 IXMLDOMDocument2
*iface
,
931 IXMLDOMNode
** resultNode
)
933 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
934 return IXMLDOMNode_selectSingleNode( This
->node
, queryString
, resultNode
);
938 static HRESULT WINAPI
domdoc_get_parsed(
939 IXMLDOMDocument2
*iface
,
940 VARIANT_BOOL
* isParsed
)
942 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
943 return IXMLDOMNode_get_parsed( This
->node
, isParsed
);
947 static HRESULT WINAPI
domdoc_get_namespaceURI(
948 IXMLDOMDocument2
*iface
,
951 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
952 return IXMLDOMNode_get_namespaceURI( This
->node
, namespaceURI
);
956 static HRESULT WINAPI
domdoc_get_prefix(
957 IXMLDOMDocument2
*iface
,
960 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
961 return IXMLDOMNode_get_prefix( This
->node
, prefixString
);
965 static HRESULT WINAPI
domdoc_get_baseName(
966 IXMLDOMDocument2
*iface
,
969 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
970 return IXMLDOMNode_get_baseName( This
->node
, nameString
);
974 static HRESULT WINAPI
domdoc_transformNodeToObject(
975 IXMLDOMDocument2
*iface
,
976 IXMLDOMNode
* stylesheet
,
977 VARIANT outputObject
)
979 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
980 return IXMLDOMNode_transformNodeToObject( This
->node
, stylesheet
, outputObject
);
984 static HRESULT WINAPI
domdoc_get_doctype(
985 IXMLDOMDocument2
*iface
,
986 IXMLDOMDocumentType
** documentType
)
993 static HRESULT WINAPI
domdoc_get_implementation(
994 IXMLDOMDocument2
*iface
,
995 IXMLDOMImplementation
** impl
)
1000 *impl
= (IXMLDOMImplementation
*)create_doc_Implementation();
1005 static HRESULT WINAPI
domdoc_get_documentElement(
1006 IXMLDOMDocument2
*iface
,
1007 IXMLDOMElement
** DOMElement
)
1009 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1010 xmlDocPtr xmldoc
= NULL
;
1011 xmlNodePtr root
= NULL
;
1012 IXMLDOMNode
*element_node
;
1015 TRACE("%p %p\n", This
, This
->node
);
1018 return E_INVALIDARG
;
1022 xmldoc
= get_doc( This
);
1024 root
= xmlDocGetRootElement( xmldoc
);
1028 element_node
= create_node( root
);
1029 if(!element_node
) return S_FALSE
;
1031 hr
= IXMLDOMNode_QueryInterface(element_node
, &IID_IXMLDOMElement
, (LPVOID
*)DOMElement
);
1032 IXMLDOMNode_Release(element_node
);
1038 static HRESULT WINAPI
domdoc_put_documentElement(
1039 IXMLDOMDocument2
*iface
,
1040 IXMLDOMElement
* DOMElement
)
1042 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1043 IXMLDOMNode
*elementNode
;
1047 TRACE("(%p)->(%p)\n", This
, DOMElement
);
1049 hr
= IXMLDOMElement_QueryInterface( DOMElement
, &IID_IXMLDOMNode
, (void**)&elementNode
);
1053 xmlNode
= impl_from_IXMLDOMNode( elementNode
);
1054 xmlDocSetRootElement( get_doc(This
), xmlNode
->node
);
1055 IXMLDOMNode_Release( elementNode
);
1061 static HRESULT WINAPI
domdoc_createElement(
1062 IXMLDOMDocument2
*iface
,
1064 IXMLDOMElement
** element
)
1067 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1072 TRACE("%p->(%s,%p)\n", iface
, debugstr_w(tagname
), element
);
1074 xml_name
= xmlChar_from_wchar((WCHAR
*)tagname
);
1075 xmlnode
= xmlNewDocNode(get_doc(This
), NULL
, xml_name
, NULL
);
1077 TRACE("created xmlptr %p\n", xmlnode
);
1078 elem_unk
= create_element(xmlnode
, NULL
);
1079 HeapFree(GetProcessHeap(), 0, xml_name
);
1081 hr
= IUnknown_QueryInterface(elem_unk
, &IID_IXMLDOMElement
, (void **)element
);
1082 IUnknown_Release(elem_unk
);
1083 TRACE("returning %p\n", *element
);
1088 static HRESULT WINAPI
domdoc_createDocumentFragment(
1089 IXMLDOMDocument2
*iface
,
1090 IXMLDOMDocumentFragment
** docFrag
)
1092 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1095 TRACE("%p\n", iface
);
1098 return E_INVALIDARG
;
1102 xmlnode
= xmlNewDocFragment(get_doc( This
) );
1107 xmlnode
->doc
= get_doc( This
);
1109 *docFrag
= (IXMLDOMDocumentFragment
*)create_doc_fragment(xmlnode
);
1115 static HRESULT WINAPI
domdoc_createTextNode(
1116 IXMLDOMDocument2
*iface
,
1118 IXMLDOMText
** text
)
1120 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1122 xmlChar
*xml_content
;
1124 TRACE("%p->(%s %p)\n", iface
, debugstr_w(data
), text
);
1127 return E_INVALIDARG
;
1131 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
1132 xmlnode
= xmlNewText(xml_content
);
1133 HeapFree(GetProcessHeap(), 0, xml_content
);
1138 xmlnode
->doc
= get_doc( This
);
1140 *text
= (IXMLDOMText
*)create_text(xmlnode
);
1146 static HRESULT WINAPI
domdoc_createComment(
1147 IXMLDOMDocument2
*iface
,
1149 IXMLDOMComment
** comment
)
1151 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1153 xmlChar
*xml_content
;
1155 TRACE("%p->(%s %p)\n", iface
, debugstr_w(data
), comment
);
1158 return E_INVALIDARG
;
1162 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
1163 xmlnode
= xmlNewComment(xml_content
);
1164 HeapFree(GetProcessHeap(), 0, xml_content
);
1169 xmlnode
->doc
= get_doc( This
);
1171 *comment
= (IXMLDOMComment
*)create_comment(xmlnode
);
1177 static HRESULT WINAPI
domdoc_createCDATASection(
1178 IXMLDOMDocument2
*iface
,
1180 IXMLDOMCDATASection
** cdata
)
1182 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1184 xmlChar
*xml_content
;
1186 TRACE("%p->(%s %p)\n", iface
, debugstr_w(data
), cdata
);
1189 return E_INVALIDARG
;
1193 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
1194 xmlnode
= xmlNewCDataBlock(get_doc( This
), xml_content
, strlen( (char*)xml_content
) );
1195 HeapFree(GetProcessHeap(), 0, xml_content
);
1200 xmlnode
->doc
= get_doc( This
);
1202 *cdata
= (IXMLDOMCDATASection
*)create_cdata(xmlnode
);
1208 static HRESULT WINAPI
domdoc_createProcessingInstruction(
1209 IXMLDOMDocument2
*iface
,
1212 IXMLDOMProcessingInstruction
** pi
)
1214 #ifdef HAVE_XMLNEWDOCPI
1216 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1217 xmlChar
*xml_target
, *xml_content
;
1219 TRACE("%p->(%s %s %p)\n", iface
, debugstr_w(target
), debugstr_w(data
), pi
);
1222 return E_INVALIDARG
;
1224 if(!target
|| lstrlenW(target
) == 0)
1227 xml_target
= xmlChar_from_wchar((WCHAR
*)target
);
1228 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
1230 xmlnode
= xmlNewDocPI(get_doc(This
), xml_target
, xml_content
);
1231 TRACE("created xmlptr %p\n", xmlnode
);
1232 *pi
= (IXMLDOMProcessingInstruction
*)create_pi(xmlnode
);
1234 HeapFree(GetProcessHeap(), 0, xml_content
);
1235 HeapFree(GetProcessHeap(), 0, xml_target
);
1239 FIXME("Libxml 2.6.15 or greater required.\n");
1245 static HRESULT WINAPI
domdoc_createAttribute(
1246 IXMLDOMDocument2
*iface
,
1248 IXMLDOMAttribute
** attribute
)
1250 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1254 TRACE("%p->(%s %p)\n", iface
, debugstr_w(name
), attribute
);
1257 return E_INVALIDARG
;
1261 xml_name
= xmlChar_from_wchar((WCHAR
*)name
);
1262 xmlnode
= (xmlNode
*)xmlNewProp(NULL
, xml_name
, NULL
);
1263 HeapFree(GetProcessHeap(), 0, xml_name
);
1268 xmlnode
->doc
= get_doc( This
);
1270 *attribute
= (IXMLDOMAttribute
*)create_attribute(xmlnode
);
1276 static HRESULT WINAPI
domdoc_createEntityReference(
1277 IXMLDOMDocument2
*iface
,
1279 IXMLDOMEntityReference
** entityRef
)
1281 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1285 TRACE("%p\n", iface
);
1288 return E_INVALIDARG
;
1292 xml_name
= xmlChar_from_wchar((WCHAR
*)name
);
1293 xmlnode
= xmlNewReference(get_doc( This
), xml_name
);
1294 HeapFree(GetProcessHeap(), 0, xml_name
);
1299 xmlnode
->doc
= get_doc( This
);
1301 *entityRef
= (IXMLDOMEntityReference
*)create_doc_entity_ref(xmlnode
);
1307 static HRESULT WINAPI
domdoc_getElementsByTagName(
1308 IXMLDOMDocument2
*iface
,
1310 IXMLDOMNodeList
** resultList
)
1312 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1315 TRACE("(%p)->(%s, %p)\n", This
, debugstr_w(tagName
), resultList
);
1317 szPattern
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(2+lstrlenW(tagName
)+1));
1318 szPattern
[0] = szPattern
[1] = '/';
1319 lstrcpyW(szPattern
+ 2, tagName
);
1321 hr
= queryresult_create((xmlNodePtr
)get_doc(This
), szPattern
, resultList
);
1322 HeapFree(GetProcessHeap(), 0, szPattern
);
1327 static DOMNodeType
get_node_type(VARIANT Type
)
1329 if(V_VT(&Type
) == VT_I4
)
1332 FIXME("Unsupported variant type %x\n", V_VT(&Type
));
1336 static HRESULT WINAPI
domdoc_createNode(
1337 IXMLDOMDocument2
*iface
,
1341 IXMLDOMNode
** node
)
1343 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1344 DOMNodeType node_type
;
1345 xmlNodePtr xmlnode
= NULL
;
1348 TRACE("(%p)->(type,%s,%s,%p)\n", This
, debugstr_w(name
), debugstr_w(namespaceURI
), node
);
1350 node_type
= get_node_type(Type
);
1351 TRACE("node_type %d\n", node_type
);
1353 xml_name
= xmlChar_from_wchar((WCHAR
*)name
);
1358 xmlnode
= xmlNewDocNode(get_doc(This
), NULL
, xml_name
, NULL
);
1359 *node
= create_node(xmlnode
);
1360 TRACE("created %p\n", xmlnode
);
1362 case NODE_ATTRIBUTE
:
1363 xmlnode
= (xmlNode
*)xmlNewProp(NULL
, xml_name
, NULL
);
1366 xmlnode
->doc
= get_doc( This
);
1368 *node
= (IXMLDOMNode
*)create_attribute(xmlnode
);
1371 TRACE("created %p\n", xmlnode
);
1375 FIXME("unhandled node type %d\n", node_type
);
1379 HeapFree(GetProcessHeap(), 0, xml_name
);
1381 if(xmlnode
&& *node
)
1387 static HRESULT WINAPI
domdoc_nodeFromID(
1388 IXMLDOMDocument2
*iface
,
1390 IXMLDOMNode
** node
)
1396 static HRESULT
doread( domdoc
*This
, LPWSTR filename
)
1400 WCHAR url
[INTERNET_MAX_URL_LENGTH
];
1402 TRACE("%s\n", debugstr_w( filename
));
1404 if(!PathIsURLW(filename
))
1406 WCHAR fullpath
[MAX_PATH
];
1407 DWORD needed
= sizeof(url
)/sizeof(WCHAR
);
1409 if(!PathSearchAndQualifyW(filename
, fullpath
, sizeof(fullpath
)/sizeof(WCHAR
)))
1411 WARN("can't find path\n");
1415 if(FAILED(UrlCreateFromPathW(fullpath
, url
, &needed
, 0)))
1417 ERR("can't create url from path\n");
1423 hr
= CreateBindCtx(0, &pbc
);
1427 if(This
->bsc
->binding
)
1428 IBinding_Abort(This
->bsc
->binding
);
1429 This
->bsc
->doc
= NULL
;
1430 IBindStatusCallback_Release((IBindStatusCallback
*)&This
->bsc
->lpVtbl
);
1433 This
->bsc
= create_bsc(This
);
1435 hr
= RegisterBindStatusCallback(pbc
, (IBindStatusCallback
*)&This
->bsc
->lpVtbl
, NULL
, 0);
1439 hr
= CreateURLMoniker(NULL
, filename
, &moniker
);
1443 hr
= IMoniker_BindToStorage(moniker
, pbc
, NULL
, &IID_IStream
, (LPVOID
*)&stream
);
1444 IMoniker_Release(moniker
);
1446 IStream_Release(stream
);
1449 IBindCtx_Release(pbc
);
1455 static HRESULT WINAPI
domdoc_load(
1456 IXMLDOMDocument2
*iface
,
1458 VARIANT_BOOL
* isSuccessful
)
1460 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1461 LPWSTR filename
= NULL
;
1462 HRESULT hr
= S_FALSE
;
1463 IXMLDOMDocument2
*pNewDoc
= NULL
;
1464 IStream
*pStream
= NULL
;
1467 TRACE("type %d\n", V_VT(&xmlSource
) );
1469 *isSuccessful
= VARIANT_FALSE
;
1471 assert( This
->node
);
1473 attach_xmlnode(This
->node
, NULL
);
1475 switch( V_VT(&xmlSource
) )
1478 filename
= V_BSTR(&xmlSource
);
1481 hr
= IUnknown_QueryInterface(V_UNKNOWN(&xmlSource
), &IID_IXMLDOMDocument2
, (void**)&pNewDoc
);
1486 domdoc
*newDoc
= impl_from_IXMLDOMDocument2( pNewDoc
);
1487 xmldoc
= xmlCopyDoc(get_doc(newDoc
), 1);
1488 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1490 *isSuccessful
= VARIANT_TRUE
;
1495 hr
= IUnknown_QueryInterface(V_UNKNOWN(&xmlSource
), &IID_IStream
, (void**)&pStream
);
1498 IPersistStream
*pDocStream
;
1499 hr
= IUnknown_QueryInterface(iface
, &IID_IPersistStream
, (void**)&pDocStream
);
1502 hr
= xmldoc_IPersistStream_Load(pDocStream
, pStream
);
1503 IStream_Release(pStream
);
1506 *isSuccessful
= VARIANT_TRUE
;
1508 TRACE("Using ID_IStream to load Document\n");
1513 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr
);
1518 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr
);
1523 /* ISequentialStream */
1524 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr
, pNewDoc
, V_UNKNOWN(&xmlSource
)->lpVtbl
);
1528 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource
));
1531 TRACE("filename (%s)\n", debugstr_w(filename
));
1535 hr
= doread( This
, filename
);
1538 This
->error
= E_FAIL
;
1541 hr
= This
->error
= S_OK
;
1542 *isSuccessful
= VARIANT_TRUE
;
1546 if(!filename
|| FAILED(hr
)) {
1547 xmldoc
= xmlNewDoc(NULL
);
1548 xmldoc
->_private
= 0;
1549 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1553 TRACE("ret (%d)\n", hr
);
1559 static HRESULT WINAPI
domdoc_get_readyState(
1560 IXMLDOMDocument2
*iface
,
1568 static HRESULT WINAPI
domdoc_get_parseError(
1569 IXMLDOMDocument2
*iface
,
1570 IXMLDOMParseError
** errorObj
)
1572 BSTR error_string
= NULL
;
1573 static const WCHAR err
[] = {'e','r','r','o','r',0};
1574 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1576 FIXME("(%p)->(%p): creating a dummy parseError\n", iface
, errorObj
);
1579 error_string
= SysAllocString(err
);
1581 *errorObj
= create_parseError(This
->error
, NULL
, error_string
, NULL
, 0, 0, 0);
1582 if(!*errorObj
) return E_OUTOFMEMORY
;
1587 static HRESULT WINAPI
domdoc_get_url(
1588 IXMLDOMDocument2
*iface
,
1596 static HRESULT WINAPI
domdoc_get_async(
1597 IXMLDOMDocument2
*iface
,
1598 VARIANT_BOOL
* isAsync
)
1600 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1602 TRACE("%p <- %d\n", isAsync
, This
->async
);
1603 *isAsync
= This
->async
;
1608 static HRESULT WINAPI
domdoc_put_async(
1609 IXMLDOMDocument2
*iface
,
1610 VARIANT_BOOL isAsync
)
1612 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1614 TRACE("%d\n", isAsync
);
1615 This
->async
= isAsync
;
1620 static HRESULT WINAPI
domdoc_abort(
1621 IXMLDOMDocument2
*iface
)
1628 static BOOL
bstr_to_utf8( BSTR bstr
, char **pstr
, int *plen
)
1630 UINT len
, blen
= SysStringLen( bstr
);
1633 len
= WideCharToMultiByte( CP_UTF8
, 0, bstr
, blen
, NULL
, 0, NULL
, NULL
);
1634 str
= HeapAlloc( GetProcessHeap(), 0, len
);
1637 WideCharToMultiByte( CP_UTF8
, 0, bstr
, blen
, str
, len
, NULL
, NULL
);
1643 static HRESULT WINAPI
domdoc_loadXML(
1644 IXMLDOMDocument2
*iface
,
1646 VARIANT_BOOL
* isSuccessful
)
1648 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1649 xmlDocPtr xmldoc
= NULL
;
1652 HRESULT hr
= S_FALSE
;
1654 TRACE("%p %s %p\n", This
, debugstr_w( bstrXML
), isSuccessful
);
1656 assert ( This
->node
);
1658 attach_xmlnode( This
->node
, NULL
);
1662 *isSuccessful
= VARIANT_FALSE
;
1664 if ( bstrXML
&& bstr_to_utf8( bstrXML
, &str
, &len
) )
1666 xmldoc
= doparse( str
, len
);
1667 HeapFree( GetProcessHeap(), 0, str
);
1669 This
->error
= E_FAIL
;
1672 hr
= This
->error
= S_OK
;
1673 *isSuccessful
= VARIANT_TRUE
;
1678 xmldoc
= xmlNewDoc(NULL
);
1680 xmldoc
->_private
= 0;
1681 attach_xmlnode( This
->node
, (xmlNodePtr
) xmldoc
);
1687 static HRESULT WINAPI
domdoc_save(
1688 IXMLDOMDocument2
*iface
,
1689 VARIANT destination
)
1691 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1698 TRACE("(%p)->(var(vt %x, %s))\n", This
, V_VT(&destination
),
1699 V_VT(&destination
) == VT_BSTR
? debugstr_w(V_BSTR(&destination
)) : NULL
);
1701 if(V_VT(&destination
) != VT_BSTR
&& V_VT(&destination
) != VT_UNKNOWN
)
1703 FIXME("Unhandled vt %d\n", V_VT(&destination
));
1707 if(V_VT(&destination
) == VT_UNKNOWN
)
1709 IUnknown
*pUnk
= V_UNKNOWN(&destination
);
1710 IXMLDOMDocument
*pDocument
;
1712 ret
= IXMLDOMDocument_QueryInterface(pUnk
, &IID_IXMLDOMDocument2
, (void**)&pDocument
);
1716 VARIANT_BOOL bSuccessful
;
1718 ret
= IXMLDOMDocument_get_xml(iface
, &bXML
);
1721 ret
= IXMLDOMDocument_loadXML(pDocument
, bXML
, &bSuccessful
);
1723 SysFreeString(bXML
);
1726 IXMLDOMDocument_Release(pDocument
);
1732 handle
= CreateFileW( V_BSTR(&destination
), GENERIC_WRITE
, 0,
1733 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1734 if( handle
== INVALID_HANDLE_VALUE
)
1736 WARN("failed to create file\n");
1740 xmlDocDumpMemory(get_doc(This
), &mem
, &size
);
1741 if(!WriteFile(handle
, mem
, (DWORD
)size
, &written
, NULL
) || written
!= (DWORD
)size
)
1743 WARN("write error\n");
1748 CloseHandle(handle
);
1752 static HRESULT WINAPI
domdoc_get_validateOnParse(
1753 IXMLDOMDocument2
*iface
,
1754 VARIANT_BOOL
* isValidating
)
1756 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1758 TRACE("%p <- %d\n", isValidating
, This
->validating
);
1759 *isValidating
= This
->validating
;
1764 static HRESULT WINAPI
domdoc_put_validateOnParse(
1765 IXMLDOMDocument2
*iface
,
1766 VARIANT_BOOL isValidating
)
1768 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1770 TRACE("%d\n", isValidating
);
1771 This
->validating
= isValidating
;
1776 static HRESULT WINAPI
domdoc_get_resolveExternals(
1777 IXMLDOMDocument2
*iface
,
1778 VARIANT_BOOL
* isResolving
)
1780 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1782 TRACE("%p <- %d\n", isResolving
, This
->resolving
);
1783 *isResolving
= This
->resolving
;
1788 static HRESULT WINAPI
domdoc_put_resolveExternals(
1789 IXMLDOMDocument2
*iface
,
1790 VARIANT_BOOL isResolving
)
1792 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1794 TRACE("%d\n", isResolving
);
1795 This
->resolving
= isResolving
;
1800 static HRESULT WINAPI
domdoc_get_preserveWhiteSpace(
1801 IXMLDOMDocument2
*iface
,
1802 VARIANT_BOOL
* isPreserving
)
1804 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1806 TRACE("%p <- %d\n", isPreserving
, This
->preserving
);
1807 *isPreserving
= This
->preserving
;
1812 static HRESULT WINAPI
domdoc_put_preserveWhiteSpace(
1813 IXMLDOMDocument2
*iface
,
1814 VARIANT_BOOL isPreserving
)
1816 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1818 TRACE("%d\n", isPreserving
);
1819 This
->preserving
= isPreserving
;
1824 static HRESULT WINAPI
domdoc_put_onReadyStateChange(
1825 IXMLDOMDocument2
*iface
,
1826 VARIANT readyStateChangeSink
)
1833 static HRESULT WINAPI
domdoc_put_onDataAvailable(
1834 IXMLDOMDocument2
*iface
,
1835 VARIANT onDataAvailableSink
)
1841 static HRESULT WINAPI
domdoc_put_onTransformNode(
1842 IXMLDOMDocument2
*iface
,
1843 VARIANT onTransformNodeSink
)
1849 static HRESULT WINAPI
domdoc_get_namespaces(
1850 IXMLDOMDocument2
* iface
,
1851 IXMLDOMSchemaCollection
** schemaCollection
)
1857 static HRESULT WINAPI
domdoc_get_schemas(
1858 IXMLDOMDocument2
* iface
,
1861 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1862 HRESULT hr
= S_FALSE
;
1863 IXMLDOMSchemaCollection
*cur_schema
= This
->schema
;
1865 TRACE("(%p)->(%p)\n", This
, var1
);
1867 VariantInit(var1
); /* Test shows we don't call VariantClear here */
1868 V_VT(var1
) = VT_NULL
;
1872 hr
= IXMLDOMSchemaCollection_QueryInterface(cur_schema
, &IID_IDispatch
, (void**)&V_DISPATCH(var1
));
1874 V_VT(var1
) = VT_DISPATCH
;
1879 static HRESULT WINAPI
domdoc_putref_schemas(
1880 IXMLDOMDocument2
* iface
,
1883 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1884 HRESULT hr
= E_FAIL
;
1885 IXMLDOMSchemaCollection
*new_schema
= NULL
;
1887 FIXME("(%p): semi-stub\n", This
);
1891 hr
= IUnknown_QueryInterface(V_UNKNOWN(&var1
), &IID_IXMLDOMSchemaCollection
, (void**)&new_schema
);
1895 hr
= IDispatch_QueryInterface(V_DISPATCH(&var1
), &IID_IXMLDOMSchemaCollection
, (void**)&new_schema
);
1904 WARN("Can't get schema from vt %x\n", V_VT(&var1
));
1909 IXMLDOMSchemaCollection
*old_schema
= InterlockedExchangePointer((void**)&This
->schema
, new_schema
);
1910 if(old_schema
) IXMLDOMSchemaCollection_Release(old_schema
);
1916 static HRESULT WINAPI
domdoc_validate(
1917 IXMLDOMDocument2
* iface
,
1918 IXMLDOMParseError
** err
)
1924 static HRESULT WINAPI
domdoc_setProperty(
1925 IXMLDOMDocument2
* iface
,
1929 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1931 if (lstrcmpiW(p
, SZ_PROPERTY_SELECTION_LANGUAGE
) == 0)
1937 V_VT(&varStr
) = VT_EMPTY
;
1938 if (V_VT(&var
) != VT_BSTR
)
1940 if (FAILED(hr
= VariantChangeType(&varStr
, &var
, 0, VT_BSTR
)))
1942 bstr
= V_BSTR(&varStr
);
1945 bstr
= V_BSTR(&var
);
1948 if (lstrcmpiW(bstr
, SZ_VALUE_XPATH
) == 0)
1949 This
->bUseXPath
= TRUE
;
1950 else if (lstrcmpiW(bstr
, SZ_VALUE_XSLPATTERN
) == 0)
1951 This
->bUseXPath
= FALSE
;
1955 VariantClear(&varStr
);
1959 FIXME("Unknown property %s\n", wine_dbgstr_w(p
));
1963 static HRESULT WINAPI
domdoc_getProperty(
1964 IXMLDOMDocument2
* iface
,
1968 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1971 return E_INVALIDARG
;
1972 if (lstrcmpiW(p
, SZ_PROPERTY_SELECTION_LANGUAGE
) == 0)
1974 V_VT(var
) = VT_BSTR
;
1975 if (This
->bUseXPath
)
1976 V_BSTR(var
) = SysAllocString(SZ_VALUE_XPATH
);
1978 V_BSTR(var
) = SysAllocString(SZ_VALUE_XSLPATTERN
);
1982 FIXME("Unknown property %s\n", wine_dbgstr_w(p
));
1986 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl
=
1988 domdoc_QueryInterface
,
1991 domdoc_GetTypeInfoCount
,
1993 domdoc_GetIDsOfNames
,
1995 domdoc_get_nodeName
,
1996 domdoc_get_nodeValue
,
1997 domdoc_put_nodeValue
,
1998 domdoc_get_nodeType
,
1999 domdoc_get_parentNode
,
2000 domdoc_get_childNodes
,
2001 domdoc_get_firstChild
,
2002 domdoc_get_lastChild
,
2003 domdoc_get_previousSibling
,
2004 domdoc_get_nextSibling
,
2005 domdoc_get_attributes
,
2006 domdoc_insertBefore
,
2007 domdoc_replaceChild
,
2010 domdoc_hasChildNodes
,
2011 domdoc_get_ownerDocument
,
2013 domdoc_get_nodeTypeString
,
2016 domdoc_get_specified
,
2017 domdoc_get_definition
,
2018 domdoc_get_nodeTypedValue
,
2019 domdoc_put_nodeTypedValue
,
2020 domdoc_get_dataType
,
2021 domdoc_put_dataType
,
2023 domdoc_transformNode
,
2025 domdoc_selectSingleNode
,
2027 domdoc_get_namespaceURI
,
2029 domdoc_get_baseName
,
2030 domdoc_transformNodeToObject
,
2032 domdoc_get_implementation
,
2033 domdoc_get_documentElement
,
2034 domdoc_put_documentElement
,
2035 domdoc_createElement
,
2036 domdoc_createDocumentFragment
,
2037 domdoc_createTextNode
,
2038 domdoc_createComment
,
2039 domdoc_createCDATASection
,
2040 domdoc_createProcessingInstruction
,
2041 domdoc_createAttribute
,
2042 domdoc_createEntityReference
,
2043 domdoc_getElementsByTagName
,
2047 domdoc_get_readyState
,
2048 domdoc_get_parseError
,
2055 domdoc_get_validateOnParse
,
2056 domdoc_put_validateOnParse
,
2057 domdoc_get_resolveExternals
,
2058 domdoc_put_resolveExternals
,
2059 domdoc_get_preserveWhiteSpace
,
2060 domdoc_put_preserveWhiteSpace
,
2061 domdoc_put_onReadyStateChange
,
2062 domdoc_put_onDataAvailable
,
2063 domdoc_put_onTransformNode
,
2064 domdoc_get_namespaces
,
2066 domdoc_putref_schemas
,
2072 /* xmldoc implementation of IObjectWithSite */
2073 static HRESULT WINAPI
2074 xmldoc_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2076 domdoc
*This
= impl_from_IObjectWithSite(iface
);
2077 return IXMLDocument_QueryInterface( (IXMLDocument
*)This
, riid
, ppvObject
);
2081 xmldoc_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2083 domdoc
*This
= impl_from_IObjectWithSite(iface
);
2084 return IXMLDocument_AddRef((IXMLDocument
*)This
);
2088 xmldoc_ObjectWithSite_Release( IObjectWithSite
* iface
)
2090 domdoc
*This
= impl_from_IObjectWithSite(iface
);
2091 return IXMLDocument_Release((IXMLDocument
*)This
);
2094 static HRESULT WINAPI
2095 xmldoc_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2097 domdoc
*This
= impl_from_IObjectWithSite(iface
);
2099 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2104 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2107 static HRESULT WINAPI
2108 xmldoc_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2110 domdoc
*This
= impl_from_IObjectWithSite(iface
);
2112 TRACE("%p %p\n", iface
, punk
);
2118 IUnknown_Release( This
->site
);
2126 IUnknown_AddRef( punk
);
2129 IUnknown_Release( This
->site
);
2136 static const IObjectWithSiteVtbl domdocObjectSite
=
2138 xmldoc_ObjectWithSite_QueryInterface
,
2139 xmldoc_ObjectWithSite_AddRef
,
2140 xmldoc_ObjectWithSite_Release
,
2145 static HRESULT WINAPI
xmldoc_Safety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
2147 domdoc
*This
= impl_from_IObjectSafety(iface
);
2148 return IXMLDocument_QueryInterface( (IXMLDocument
*)This
, riid
, ppv
);
2151 static ULONG WINAPI
xmldoc_Safety_AddRef(IObjectSafety
*iface
)
2153 domdoc
*This
= impl_from_IObjectSafety(iface
);
2154 return IXMLDocument_AddRef((IXMLDocument
*)This
);
2157 static ULONG WINAPI
xmldoc_Safety_Release(IObjectSafety
*iface
)
2159 domdoc
*This
= impl_from_IObjectSafety(iface
);
2160 return IXMLDocument_Release((IXMLDocument
*)This
);
2163 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER)
2165 static HRESULT WINAPI
xmldoc_Safety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
2166 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
2168 domdoc
*This
= impl_from_IObjectSafety(iface
);
2170 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
2172 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
2175 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
2176 *pdwEnabledOptions
= This
->safeopt
;
2181 static HRESULT WINAPI
xmldoc_Safety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
2182 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
2184 domdoc
*This
= impl_from_IObjectSafety(iface
);
2186 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
2188 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
2191 This
->safeopt
= dwEnabledOptions
& dwEnabledOptions
;
2195 static const IObjectSafetyVtbl domdocObjectSafetyVtbl
= {
2196 xmldoc_Safety_QueryInterface
,
2197 xmldoc_Safety_AddRef
,
2198 xmldoc_Safety_Release
,
2199 xmldoc_Safety_GetInterfaceSafetyOptions
,
2200 xmldoc_Safety_SetInterfaceSafetyOptions
2203 HRESULT
DOMDocument_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2209 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
2211 doc
= HeapAlloc( GetProcessHeap(), 0, sizeof (*doc
) );
2213 return E_OUTOFMEMORY
;
2215 doc
->lpVtbl
= &domdoc_vtbl
;
2216 doc
->lpvtblIPersistStream
= &xmldoc_IPersistStream_VTable
;
2217 doc
->lpvtblIObjectWithSite
= &domdocObjectSite
;
2218 doc
->lpvtblIObjectSafety
= &domdocObjectSafetyVtbl
;
2221 doc
->validating
= 0;
2223 doc
->preserving
= 0;
2224 doc
->bUseXPath
= FALSE
;
2232 xmldoc
= xmlNewDoc(NULL
);
2235 HeapFree(GetProcessHeap(), 0, doc
);
2236 return E_OUTOFMEMORY
;
2239 xmldoc
->_private
= 0;
2241 doc
->node_unk
= create_basic_node( (xmlNodePtr
)xmldoc
, (IUnknown
*)&doc
->lpVtbl
);
2245 HeapFree(GetProcessHeap(), 0, doc
);
2249 hr
= IUnknown_QueryInterface(doc
->node_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&doc
->node
);
2252 IUnknown_Release(doc
->node_unk
);
2253 HeapFree( GetProcessHeap(), 0, doc
);
2256 /* The ref on doc->node is actually looped back into this object, so release it */
2257 IXMLDOMNode_Release(doc
->node
);
2259 *ppObj
= &doc
->lpVtbl
;
2261 TRACE("returning iface %p\n", *ppObj
);
2267 HRESULT
DOMDocument_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2269 MESSAGE("This program tried to use a DOMDocument object, but\n"
2270 "libxml2 support was not present at compile time.\n");