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 DOMNodeType
get_node_type(VARIANT Type
)
1115 if(V_VT(&Type
) == VT_I4
)
1118 FIXME("Unsupported variant type %x\n", V_VT(&Type
));
1122 static HRESULT WINAPI
domdoc_createNode(
1123 IXMLDOMDocument2
*iface
,
1127 IXMLDOMNode
** node
)
1129 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1130 DOMNodeType node_type
;
1131 xmlNodePtr xmlnode
= NULL
;
1134 TRACE("(%p)->(type,%s,%s,%p)\n", This
, debugstr_w(name
), debugstr_w(namespaceURI
), node
);
1136 node_type
= get_node_type(Type
);
1137 TRACE("node_type %d\n", node_type
);
1139 xml_name
= xmlChar_from_wchar((WCHAR
*)name
);
1144 xmlnode
= xmlNewDocNode(get_doc(This
), NULL
, xml_name
, NULL
);
1145 *node
= create_node(xmlnode
);
1146 TRACE("created %p\n", xmlnode
);
1148 case NODE_ATTRIBUTE
:
1149 xmlnode
= (xmlNode
*)xmlNewProp(NULL
, xml_name
, NULL
);
1152 xmlnode
->doc
= get_doc( This
);
1154 *node
= (IXMLDOMNode
*)create_attribute(xmlnode
);
1157 TRACE("created %p\n", xmlnode
);
1161 FIXME("unhandled node type %d\n", node_type
);
1165 HeapFree(GetProcessHeap(), 0, xml_name
);
1167 if(xmlnode
&& *node
)
1173 static HRESULT WINAPI
domdoc_nodeFromID(
1174 IXMLDOMDocument2
*iface
,
1176 IXMLDOMNode
** node
)
1182 static HRESULT
domdoc_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
1187 xmldoc
= doparse( ptr
, len
);
1189 xmldoc
->_private
= 0;
1190 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1196 static HRESULT
doread( domdoc
*This
, LPWSTR filename
)
1201 hr
= bind_url(filename
, domdoc_onDataAvailable
, This
, &bsc
);
1206 detach_bsc(This
->bsc
);
1212 static HRESULT WINAPI
domdoc_load(
1213 IXMLDOMDocument2
*iface
,
1215 VARIANT_BOOL
* isSuccessful
)
1217 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1218 LPWSTR filename
= NULL
;
1219 HRESULT hr
= S_FALSE
;
1220 IXMLDOMDocument2
*pNewDoc
= NULL
;
1221 IStream
*pStream
= NULL
;
1224 TRACE("type %d\n", V_VT(&xmlSource
) );
1226 *isSuccessful
= VARIANT_FALSE
;
1228 assert( This
->node
);
1230 attach_xmlnode(This
->node
, NULL
);
1232 switch( V_VT(&xmlSource
) )
1235 filename
= V_BSTR(&xmlSource
);
1238 hr
= IUnknown_QueryInterface(V_UNKNOWN(&xmlSource
), &IID_IXMLDOMDocument2
, (void**)&pNewDoc
);
1243 domdoc
*newDoc
= impl_from_IXMLDOMDocument2( pNewDoc
);
1244 xmldoc
= xmlCopyDoc(get_doc(newDoc
), 1);
1245 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1247 *isSuccessful
= VARIANT_TRUE
;
1252 hr
= IUnknown_QueryInterface(V_UNKNOWN(&xmlSource
), &IID_IStream
, (void**)&pStream
);
1255 IPersistStream
*pDocStream
;
1256 hr
= IUnknown_QueryInterface(iface
, &IID_IPersistStream
, (void**)&pDocStream
);
1259 hr
= xmldoc_IPersistStream_Load(pDocStream
, pStream
);
1260 IStream_Release(pStream
);
1263 *isSuccessful
= VARIANT_TRUE
;
1265 TRACE("Using ID_IStream to load Document\n");
1270 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr
);
1275 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr
);
1280 /* ISequentialStream */
1281 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr
, pNewDoc
, V_UNKNOWN(&xmlSource
)->lpVtbl
);
1285 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource
));
1288 TRACE("filename (%s)\n", debugstr_w(filename
));
1292 hr
= doread( This
, filename
);
1295 This
->error
= E_FAIL
;
1298 hr
= This
->error
= S_OK
;
1299 *isSuccessful
= VARIANT_TRUE
;
1303 if(!filename
|| FAILED(hr
)) {
1304 xmldoc
= xmlNewDoc(NULL
);
1305 xmldoc
->_private
= 0;
1306 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1310 TRACE("ret (%d)\n", hr
);
1316 static HRESULT WINAPI
domdoc_get_readyState(
1317 IXMLDOMDocument2
*iface
,
1325 static HRESULT WINAPI
domdoc_get_parseError(
1326 IXMLDOMDocument2
*iface
,
1327 IXMLDOMParseError
** errorObj
)
1329 BSTR error_string
= NULL
;
1330 static const WCHAR err
[] = {'e','r','r','o','r',0};
1331 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1333 FIXME("(%p)->(%p): creating a dummy parseError\n", iface
, errorObj
);
1336 error_string
= SysAllocString(err
);
1338 *errorObj
= create_parseError(This
->error
, NULL
, error_string
, NULL
, 0, 0, 0);
1339 if(!*errorObj
) return E_OUTOFMEMORY
;
1344 static HRESULT WINAPI
domdoc_get_url(
1345 IXMLDOMDocument2
*iface
,
1353 static HRESULT WINAPI
domdoc_get_async(
1354 IXMLDOMDocument2
*iface
,
1355 VARIANT_BOOL
* isAsync
)
1357 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1359 TRACE("%p <- %d\n", isAsync
, This
->async
);
1360 *isAsync
= This
->async
;
1365 static HRESULT WINAPI
domdoc_put_async(
1366 IXMLDOMDocument2
*iface
,
1367 VARIANT_BOOL isAsync
)
1369 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1371 TRACE("%d\n", isAsync
);
1372 This
->async
= isAsync
;
1377 static HRESULT WINAPI
domdoc_abort(
1378 IXMLDOMDocument2
*iface
)
1385 static BOOL
bstr_to_utf8( BSTR bstr
, char **pstr
, int *plen
)
1387 UINT len
, blen
= SysStringLen( bstr
);
1390 len
= WideCharToMultiByte( CP_UTF8
, 0, bstr
, blen
, NULL
, 0, NULL
, NULL
);
1391 str
= HeapAlloc( GetProcessHeap(), 0, len
);
1394 WideCharToMultiByte( CP_UTF8
, 0, bstr
, blen
, str
, len
, NULL
, NULL
);
1400 static HRESULT WINAPI
domdoc_loadXML(
1401 IXMLDOMDocument2
*iface
,
1403 VARIANT_BOOL
* isSuccessful
)
1405 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1406 xmlDocPtr xmldoc
= NULL
;
1409 HRESULT hr
= S_FALSE
;
1411 TRACE("%p %s %p\n", This
, debugstr_w( bstrXML
), isSuccessful
);
1413 assert ( This
->node
);
1415 attach_xmlnode( This
->node
, NULL
);
1419 *isSuccessful
= VARIANT_FALSE
;
1421 if ( bstrXML
&& bstr_to_utf8( bstrXML
, &str
, &len
) )
1423 xmldoc
= doparse( str
, len
);
1424 HeapFree( GetProcessHeap(), 0, str
);
1426 This
->error
= E_FAIL
;
1429 hr
= This
->error
= S_OK
;
1430 *isSuccessful
= VARIANT_TRUE
;
1435 xmldoc
= xmlNewDoc(NULL
);
1437 xmldoc
->_private
= 0;
1438 attach_xmlnode( This
->node
, (xmlNodePtr
) xmldoc
);
1444 static HRESULT WINAPI
domdoc_save(
1445 IXMLDOMDocument2
*iface
,
1446 VARIANT destination
)
1448 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1455 TRACE("(%p)->(var(vt %d, %s))\n", This
, V_VT(&destination
),
1456 V_VT(&destination
) == VT_BSTR
? debugstr_w(V_BSTR(&destination
)) : NULL
);
1458 if(V_VT(&destination
) != VT_BSTR
&& V_VT(&destination
) != VT_UNKNOWN
)
1460 FIXME("Unhandled vt %d\n", V_VT(&destination
));
1464 if(V_VT(&destination
) == VT_UNKNOWN
)
1466 IUnknown
*pUnk
= V_UNKNOWN(&destination
);
1467 IXMLDOMDocument
*pDocument
;
1469 ret
= IXMLDOMDocument_QueryInterface(pUnk
, &IID_IXMLDOMDocument2
, (void**)&pDocument
);
1473 VARIANT_BOOL bSuccessful
;
1475 ret
= IXMLDOMDocument_get_xml(iface
, &bXML
);
1478 ret
= IXMLDOMDocument_loadXML(pDocument
, bXML
, &bSuccessful
);
1480 SysFreeString(bXML
);
1483 IXMLDOMDocument_Release(pDocument
);
1486 TRACE("ret %d\n", ret
);
1491 handle
= CreateFileW( V_BSTR(&destination
), GENERIC_WRITE
, 0,
1492 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1493 if( handle
== INVALID_HANDLE_VALUE
)
1495 WARN("failed to create file\n");
1499 xmlDocDumpMemory(get_doc(This
), &mem
, &size
);
1502 * libxml2 always adds XML declaration on top of the file and one for each processing instruction node in DOM tree.
1503 * MSXML adds XML declaration only for processing instruction nodes.
1504 * We skip the first XML declaration generated by libxml2 to get exactly what we need.
1507 if(size
> 2 && p
[0] == '<' && p
[1] == '?') {
1508 while(p
< mem
+size
&& (p
[0] != '?' || p
[1] != '>'))
1511 while(p
< mem
+size
&& isspace(*p
))
1516 if(!WriteFile(handle
, p
, (DWORD
)size
, &written
, NULL
) || written
!= (DWORD
)size
)
1518 WARN("write error\n");
1523 CloseHandle(handle
);
1527 static HRESULT WINAPI
domdoc_get_validateOnParse(
1528 IXMLDOMDocument2
*iface
,
1529 VARIANT_BOOL
* isValidating
)
1531 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1533 TRACE("%p <- %d\n", isValidating
, This
->validating
);
1534 *isValidating
= This
->validating
;
1539 static HRESULT WINAPI
domdoc_put_validateOnParse(
1540 IXMLDOMDocument2
*iface
,
1541 VARIANT_BOOL isValidating
)
1543 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1545 TRACE("%d\n", isValidating
);
1546 This
->validating
= isValidating
;
1551 static HRESULT WINAPI
domdoc_get_resolveExternals(
1552 IXMLDOMDocument2
*iface
,
1553 VARIANT_BOOL
* isResolving
)
1555 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1557 TRACE("%p <- %d\n", isResolving
, This
->resolving
);
1558 *isResolving
= This
->resolving
;
1563 static HRESULT WINAPI
domdoc_put_resolveExternals(
1564 IXMLDOMDocument2
*iface
,
1565 VARIANT_BOOL isResolving
)
1567 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1569 TRACE("%d\n", isResolving
);
1570 This
->resolving
= isResolving
;
1575 static HRESULT WINAPI
domdoc_get_preserveWhiteSpace(
1576 IXMLDOMDocument2
*iface
,
1577 VARIANT_BOOL
* isPreserving
)
1579 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1581 TRACE("%p <- %d\n", isPreserving
, This
->preserving
);
1582 *isPreserving
= This
->preserving
;
1587 static HRESULT WINAPI
domdoc_put_preserveWhiteSpace(
1588 IXMLDOMDocument2
*iface
,
1589 VARIANT_BOOL isPreserving
)
1591 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1593 TRACE("%d\n", isPreserving
);
1594 This
->preserving
= isPreserving
;
1599 static HRESULT WINAPI
domdoc_put_onReadyStateChange(
1600 IXMLDOMDocument2
*iface
,
1601 VARIANT readyStateChangeSink
)
1608 static HRESULT WINAPI
domdoc_put_onDataAvailable(
1609 IXMLDOMDocument2
*iface
,
1610 VARIANT onDataAvailableSink
)
1616 static HRESULT WINAPI
domdoc_put_onTransformNode(
1617 IXMLDOMDocument2
*iface
,
1618 VARIANT onTransformNodeSink
)
1624 static HRESULT WINAPI
domdoc_get_namespaces(
1625 IXMLDOMDocument2
* iface
,
1626 IXMLDOMSchemaCollection
** schemaCollection
)
1632 static HRESULT WINAPI
domdoc_get_schemas(
1633 IXMLDOMDocument2
* iface
,
1636 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1637 HRESULT hr
= S_FALSE
;
1638 IXMLDOMSchemaCollection
*cur_schema
= This
->schema
;
1640 TRACE("(%p)->(%p)\n", This
, var1
);
1642 VariantInit(var1
); /* Test shows we don't call VariantClear here */
1643 V_VT(var1
) = VT_NULL
;
1647 hr
= IXMLDOMSchemaCollection_QueryInterface(cur_schema
, &IID_IDispatch
, (void**)&V_DISPATCH(var1
));
1649 V_VT(var1
) = VT_DISPATCH
;
1654 static HRESULT WINAPI
domdoc_putref_schemas(
1655 IXMLDOMDocument2
* iface
,
1658 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1659 HRESULT hr
= E_FAIL
;
1660 IXMLDOMSchemaCollection
*new_schema
= NULL
;
1662 FIXME("(%p): semi-stub\n", This
);
1666 hr
= IUnknown_QueryInterface(V_UNKNOWN(&var1
), &IID_IXMLDOMSchemaCollection
, (void**)&new_schema
);
1670 hr
= IDispatch_QueryInterface(V_DISPATCH(&var1
), &IID_IXMLDOMSchemaCollection
, (void**)&new_schema
);
1679 WARN("Can't get schema from vt %x\n", V_VT(&var1
));
1684 IXMLDOMSchemaCollection
*old_schema
= InterlockedExchangePointer((void**)&This
->schema
, new_schema
);
1685 if(old_schema
) IXMLDOMSchemaCollection_Release(old_schema
);
1691 static HRESULT WINAPI
domdoc_validate(
1692 IXMLDOMDocument2
* iface
,
1693 IXMLDOMParseError
** err
)
1699 static HRESULT WINAPI
domdoc_setProperty(
1700 IXMLDOMDocument2
* iface
,
1704 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1706 if (lstrcmpiW(p
, SZ_PROPERTY_SELECTION_LANGUAGE
) == 0)
1712 V_VT(&varStr
) = VT_EMPTY
;
1713 if (V_VT(&var
) != VT_BSTR
)
1715 if (FAILED(hr
= VariantChangeType(&varStr
, &var
, 0, VT_BSTR
)))
1717 bstr
= V_BSTR(&varStr
);
1720 bstr
= V_BSTR(&var
);
1723 if (lstrcmpiW(bstr
, SZ_VALUE_XPATH
) == 0)
1724 This
->bUseXPath
= TRUE
;
1725 else if (lstrcmpiW(bstr
, SZ_VALUE_XSLPATTERN
) == 0)
1726 This
->bUseXPath
= FALSE
;
1730 VariantClear(&varStr
);
1734 FIXME("Unknown property %s\n", wine_dbgstr_w(p
));
1738 static HRESULT WINAPI
domdoc_getProperty(
1739 IXMLDOMDocument2
* iface
,
1743 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1746 return E_INVALIDARG
;
1747 if (lstrcmpiW(p
, SZ_PROPERTY_SELECTION_LANGUAGE
) == 0)
1749 V_VT(var
) = VT_BSTR
;
1750 if (This
->bUseXPath
)
1751 V_BSTR(var
) = SysAllocString(SZ_VALUE_XPATH
);
1753 V_BSTR(var
) = SysAllocString(SZ_VALUE_XSLPATTERN
);
1757 FIXME("Unknown property %s\n", wine_dbgstr_w(p
));
1761 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl
=
1763 domdoc_QueryInterface
,
1766 domdoc_GetTypeInfoCount
,
1768 domdoc_GetIDsOfNames
,
1770 domdoc_get_nodeName
,
1771 domdoc_get_nodeValue
,
1772 domdoc_put_nodeValue
,
1773 domdoc_get_nodeType
,
1774 domdoc_get_parentNode
,
1775 domdoc_get_childNodes
,
1776 domdoc_get_firstChild
,
1777 domdoc_get_lastChild
,
1778 domdoc_get_previousSibling
,
1779 domdoc_get_nextSibling
,
1780 domdoc_get_attributes
,
1781 domdoc_insertBefore
,
1782 domdoc_replaceChild
,
1785 domdoc_hasChildNodes
,
1786 domdoc_get_ownerDocument
,
1788 domdoc_get_nodeTypeString
,
1791 domdoc_get_specified
,
1792 domdoc_get_definition
,
1793 domdoc_get_nodeTypedValue
,
1794 domdoc_put_nodeTypedValue
,
1795 domdoc_get_dataType
,
1796 domdoc_put_dataType
,
1798 domdoc_transformNode
,
1800 domdoc_selectSingleNode
,
1802 domdoc_get_namespaceURI
,
1804 domdoc_get_baseName
,
1805 domdoc_transformNodeToObject
,
1807 domdoc_get_implementation
,
1808 domdoc_get_documentElement
,
1809 domdoc_put_documentElement
,
1810 domdoc_createElement
,
1811 domdoc_createDocumentFragment
,
1812 domdoc_createTextNode
,
1813 domdoc_createComment
,
1814 domdoc_createCDATASection
,
1815 domdoc_createProcessingInstruction
,
1816 domdoc_createAttribute
,
1817 domdoc_createEntityReference
,
1818 domdoc_getElementsByTagName
,
1822 domdoc_get_readyState
,
1823 domdoc_get_parseError
,
1830 domdoc_get_validateOnParse
,
1831 domdoc_put_validateOnParse
,
1832 domdoc_get_resolveExternals
,
1833 domdoc_put_resolveExternals
,
1834 domdoc_get_preserveWhiteSpace
,
1835 domdoc_put_preserveWhiteSpace
,
1836 domdoc_put_onReadyStateChange
,
1837 domdoc_put_onDataAvailable
,
1838 domdoc_put_onTransformNode
,
1839 domdoc_get_namespaces
,
1841 domdoc_putref_schemas
,
1847 /* xmldoc implementation of IObjectWithSite */
1848 static HRESULT WINAPI
1849 xmldoc_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
1851 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1852 return IXMLDocument_QueryInterface( (IXMLDocument
*)This
, riid
, ppvObject
);
1856 xmldoc_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
1858 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1859 return IXMLDocument_AddRef((IXMLDocument
*)This
);
1863 xmldoc_ObjectWithSite_Release( IObjectWithSite
* iface
)
1865 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1866 return IXMLDocument_Release((IXMLDocument
*)This
);
1869 static HRESULT WINAPI
1870 xmldoc_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
1872 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1874 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
1879 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
1882 static HRESULT WINAPI
1883 xmldoc_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
1885 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1887 TRACE("%p %p\n", iface
, punk
);
1893 IUnknown_Release( This
->site
);
1901 IUnknown_AddRef( punk
);
1904 IUnknown_Release( This
->site
);
1911 static const IObjectWithSiteVtbl domdocObjectSite
=
1913 xmldoc_ObjectWithSite_QueryInterface
,
1914 xmldoc_ObjectWithSite_AddRef
,
1915 xmldoc_ObjectWithSite_Release
,
1920 static HRESULT WINAPI
xmldoc_Safety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
1922 domdoc
*This
= impl_from_IObjectSafety(iface
);
1923 return IXMLDocument_QueryInterface( (IXMLDocument
*)This
, riid
, ppv
);
1926 static ULONG WINAPI
xmldoc_Safety_AddRef(IObjectSafety
*iface
)
1928 domdoc
*This
= impl_from_IObjectSafety(iface
);
1929 return IXMLDocument_AddRef((IXMLDocument
*)This
);
1932 static ULONG WINAPI
xmldoc_Safety_Release(IObjectSafety
*iface
)
1934 domdoc
*This
= impl_from_IObjectSafety(iface
);
1935 return IXMLDocument_Release((IXMLDocument
*)This
);
1938 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER)
1940 static HRESULT WINAPI
xmldoc_Safety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1941 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
1943 domdoc
*This
= impl_from_IObjectSafety(iface
);
1945 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
1947 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
1950 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
1951 *pdwEnabledOptions
= This
->safeopt
;
1956 static HRESULT WINAPI
xmldoc_Safety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1957 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
1959 domdoc
*This
= impl_from_IObjectSafety(iface
);
1961 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
1963 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
1966 This
->safeopt
= dwEnabledOptions
& dwEnabledOptions
;
1970 static const IObjectSafetyVtbl domdocObjectSafetyVtbl
= {
1971 xmldoc_Safety_QueryInterface
,
1972 xmldoc_Safety_AddRef
,
1973 xmldoc_Safety_Release
,
1974 xmldoc_Safety_GetInterfaceSafetyOptions
,
1975 xmldoc_Safety_SetInterfaceSafetyOptions
1979 static const tid_t domdoc_iface_tids
[] = {
1981 IXMLDOMDocument_tid
,
1982 IXMLDOMDocument2_tid
,
1985 static dispex_static_data_t domdoc_dispex
= {
1987 IXMLDOMDocument2_tid
,
1992 HRESULT
DOMDocument_create_from_xmldoc(xmlDocPtr xmldoc
, IXMLDOMDocument2
**document
)
1997 doc
= HeapAlloc( GetProcessHeap(), 0, sizeof (*doc
) );
1999 return E_OUTOFMEMORY
;
2001 doc
->lpVtbl
= &domdoc_vtbl
;
2002 doc
->lpvtblIPersistStream
= &xmldoc_IPersistStream_VTable
;
2003 doc
->lpvtblIObjectWithSite
= &domdocObjectSite
;
2004 doc
->lpvtblIObjectSafety
= &domdocObjectSafetyVtbl
;
2007 doc
->validating
= 0;
2009 doc
->preserving
= 0;
2010 doc
->bUseXPath
= FALSE
;
2018 doc
->node_unk
= create_basic_node( (xmlNodePtr
)xmldoc
, (IUnknown
*)&doc
->lpVtbl
);
2021 HeapFree(GetProcessHeap(), 0, doc
);
2025 hr
= IUnknown_QueryInterface(doc
->node_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&doc
->node
);
2028 IUnknown_Release(doc
->node_unk
);
2029 HeapFree( GetProcessHeap(), 0, doc
);
2033 init_dispex(&doc
->dispex
, (IUnknown
*)&doc
->lpVtbl
, &domdoc_dispex
);
2035 /* The ref on doc->node is actually looped back into this object, so release it */
2036 IXMLDOMNode_Release(doc
->node
);
2038 *document
= (IXMLDOMDocument2
*)&doc
->lpVtbl
;
2040 TRACE("returning iface %p\n", *document
);
2044 HRESULT
DOMDocument_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2049 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
2051 xmldoc
= xmlNewDoc(NULL
);
2053 return E_OUTOFMEMORY
;
2055 xmldoc
->_private
= 0;
2057 hr
= DOMDocument_create_from_xmldoc(xmldoc
, (IXMLDOMDocument2
**)ppObj
);
2064 IUnknown
* create_domdoc( xmlNodePtr document
)
2069 TRACE("(%p)\n", document
);
2071 hr
= DOMDocument_create_from_xmldoc((xmlDocPtr
)document
, (IXMLDOMDocument2
**)&pObj
);
2075 return (IUnknown
*)pObj
;
2080 HRESULT
DOMDocument_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2082 MESSAGE("This program tried to use a DOMDocument object, but\n"
2083 "libxml2 support was not present at compile time.\n");