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
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 _domdoc
54 const struct IXMLDOMDocument2Vtbl
*lpVtbl
;
55 const struct IPersistStreamVtbl
*lpvtblIPersistStream
;
56 const struct IObjectWithSiteVtbl
*lpvtblIObjectWithSite
;
57 const struct IObjectSafetyVtbl
*lpvtblIObjectSafety
;
60 VARIANT_BOOL validating
;
61 VARIANT_BOOL resolving
;
62 VARIANT_BOOL preserving
;
66 IXMLDOMSchemaCollection
*schema
;
80 static xmlDocPtr
doparse( char *ptr
, int len
)
82 #ifdef HAVE_XMLREADMEMORY
84 * use xmlReadMemory if possible so we can suppress
85 * writing errors to stderr
87 return xmlReadMemory( ptr
, len
, NULL
, NULL
,
88 XML_PARSE_NOERROR
| XML_PARSE_NOWARNING
| XML_PARSE_NOBLANKS
);
90 return xmlParseMemory( ptr
, len
);
94 LONG
xmldoc_add_ref(xmlDocPtr doc
)
96 LONG ref
= InterlockedIncrement((LONG
*)&doc
->_private
);
101 LONG
xmldoc_release(xmlDocPtr doc
)
103 LONG ref
= InterlockedDecrement((LONG
*)&doc
->_private
);
107 TRACE("freeing docptr %p\n", doc
);
114 static inline domdoc
*impl_from_IXMLDOMDocument2( IXMLDOMDocument2
*iface
)
116 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpVtbl
));
119 static inline xmlDocPtr
get_doc( domdoc
*This
)
121 return (xmlDocPtr
) xmlNodePtr_from_domnode( This
->node
, XML_DOCUMENT_NODE
);
124 static inline domdoc
*impl_from_IPersistStream(IPersistStream
*iface
)
126 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpvtblIPersistStream
));
129 static inline domdoc
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
131 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpvtblIObjectWithSite
));
134 static inline domdoc
*impl_from_IObjectSafety(IObjectSafety
*iface
)
136 return (domdoc
*)((char*)iface
- FIELD_OFFSET(domdoc
, lpvtblIObjectSafety
));
140 /************************************************************************
141 * xmldoc implementation of IPersistStream.
143 static HRESULT WINAPI
xmldoc_IPersistStream_QueryInterface(
144 IPersistStream
*iface
, REFIID riid
, LPVOID
*ppvObj
)
146 domdoc
*this = impl_from_IPersistStream(iface
);
147 return IXMLDocument_QueryInterface((IXMLDocument
*)this, riid
, ppvObj
);
150 static ULONG WINAPI
xmldoc_IPersistStream_AddRef(
151 IPersistStream
*iface
)
153 domdoc
*this = impl_from_IPersistStream(iface
);
154 return IXMLDocument_AddRef((IXMLDocument
*)this);
157 static ULONG WINAPI
xmldoc_IPersistStream_Release(
158 IPersistStream
*iface
)
160 domdoc
*this = impl_from_IPersistStream(iface
);
161 return IXMLDocument_Release((IXMLDocument
*)this);
164 static HRESULT WINAPI
xmldoc_IPersistStream_GetClassID(
165 IPersistStream
*iface
, CLSID
*classid
)
167 TRACE("(%p,%p): stub!\n", iface
, classid
);
172 *classid
= CLSID_DOMDocument2
;
177 static HRESULT WINAPI
xmldoc_IPersistStream_IsDirty(
178 IPersistStream
*iface
)
180 domdoc
*This
= impl_from_IPersistStream(iface
);
182 FIXME("(%p->%p): stub!\n", iface
, This
);
187 static HRESULT WINAPI
xmldoc_IPersistStream_Load(
188 IPersistStream
*iface
, LPSTREAM pStm
)
190 domdoc
*This
= impl_from_IPersistStream(iface
);
193 DWORD read
, written
, len
;
196 xmlDocPtr xmldoc
= NULL
;
198 TRACE("(%p, %p)\n", iface
, pStm
);
203 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &This
->stream
);
209 IStream_Read(pStm
, buf
, sizeof(buf
), &read
);
210 hr
= IStream_Write(This
->stream
, buf
, read
, &written
);
211 } while(SUCCEEDED(hr
) && written
!= 0 && read
!= 0);
215 ERR("Failed to copy stream\n");
219 hr
= GetHGlobalFromStream(This
->stream
, &hglobal
);
223 len
= GlobalSize(hglobal
);
224 ptr
= GlobalLock(hglobal
);
226 xmldoc
= parse_xml(ptr
, len
);
227 GlobalUnlock(hglobal
);
231 ERR("Failed to parse xml\n");
235 attach_xmlnode( This
->node
, (xmlNodePtr
)xmldoc
);
240 static HRESULT WINAPI
xmldoc_IPersistStream_Save(
241 IPersistStream
*iface
, LPSTREAM pStm
, BOOL fClearDirty
)
243 FIXME("(%p, %p, %d): stub!\n", iface
, pStm
, fClearDirty
);
247 static HRESULT WINAPI
xmldoc_IPersistStream_GetSizeMax(
248 IPersistStream
*iface
, ULARGE_INTEGER
*pcbSize
)
250 TRACE("(%p, %p): stub!\n", iface
, pcbSize
);
254 static const IPersistStreamVtbl xmldoc_IPersistStream_VTable
=
256 xmldoc_IPersistStream_QueryInterface
,
257 xmldoc_IPersistStream_AddRef
,
258 xmldoc_IPersistStream_Release
,
259 xmldoc_IPersistStream_GetClassID
,
260 xmldoc_IPersistStream_IsDirty
,
261 xmldoc_IPersistStream_Load
,
262 xmldoc_IPersistStream_Save
,
263 xmldoc_IPersistStream_GetSizeMax
,
266 static HRESULT WINAPI
domdoc_QueryInterface( IXMLDOMDocument2
*iface
, REFIID riid
, void** ppvObject
)
268 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
270 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppvObject
);
274 if ( IsEqualGUID( riid
, &IID_IUnknown
) ||
275 IsEqualGUID( riid
, &IID_IDispatch
) ||
276 IsEqualGUID( riid
, &IID_IXMLDOMDocument
) ||
277 IsEqualGUID( riid
, &IID_IXMLDOMDocument2
) )
281 else if ( IsEqualGUID( riid
, &IID_IXMLDOMNode
) )
283 return IUnknown_QueryInterface(This
->node_unk
, riid
, ppvObject
);
285 else if (IsEqualGUID(&IID_IPersistStream
, riid
))
287 *ppvObject
= (IPersistStream
*)&(This
->lpvtblIPersistStream
);
289 else if (IsEqualGUID(&IID_IObjectWithSite
, riid
))
291 *ppvObject
= (IObjectWithSite
*)&(This
->lpvtblIObjectWithSite
);
293 else if(IsEqualGUID(&IID_IRunnableObject
, riid
))
295 TRACE("IID_IRunnableObject not supported returning NULL\n");
296 return E_NOINTERFACE
;
300 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
301 return E_NOINTERFACE
;
304 IXMLDOMDocument_AddRef( iface
);
310 static ULONG WINAPI
domdoc_AddRef(
311 IXMLDOMDocument2
*iface
)
313 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
314 TRACE("%p\n", This
);
315 return InterlockedIncrement( &This
->ref
);
319 static ULONG WINAPI
domdoc_Release(
320 IXMLDOMDocument2
*iface
)
322 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
325 TRACE("%p\n", This
);
327 ref
= InterlockedDecrement( &This
->ref
);
331 detach_bsc(This
->bsc
);
334 IUnknown_Release( This
->site
);
335 IUnknown_Release( This
->node_unk
);
336 if(This
->schema
) IXMLDOMSchemaCollection_Release( This
->schema
);
337 if (This
->stream
) IStream_Release(This
->stream
);
338 HeapFree( GetProcessHeap(), 0, This
);
344 static HRESULT WINAPI
domdoc_GetTypeInfoCount( IXMLDOMDocument2
*iface
, UINT
* pctinfo
)
346 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
348 TRACE("(%p)->(%p)\n", This
, pctinfo
);
355 static HRESULT WINAPI
domdoc_GetTypeInfo(
356 IXMLDOMDocument2
*iface
,
357 UINT iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
359 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
362 TRACE("(%p)->(%u %u %p)\n", This
, iTInfo
, lcid
, ppTInfo
);
364 hr
= get_typeinfo(IXMLDOMDocument2_tid
, ppTInfo
);
369 static HRESULT WINAPI
domdoc_GetIDsOfNames(
370 IXMLDOMDocument2
*iface
,
377 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
381 TRACE("(%p)->(%s %p %u %u %p)\n", This
, debugstr_guid(riid
), rgszNames
, cNames
,
384 if(!rgszNames
|| cNames
== 0 || !rgDispId
)
387 hr
= get_typeinfo(IXMLDOMDocument2_tid
, &typeinfo
);
390 hr
= ITypeInfo_GetIDsOfNames(typeinfo
, rgszNames
, cNames
, rgDispId
);
391 ITypeInfo_Release(typeinfo
);
398 static HRESULT WINAPI
domdoc_Invoke(
399 IXMLDOMDocument2
*iface
,
404 DISPPARAMS
* pDispParams
,
406 EXCEPINFO
* pExcepInfo
,
409 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
413 TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This
, dispIdMember
, debugstr_guid(riid
),
414 lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
416 hr
= get_typeinfo(IXMLDOMDocument2_tid
, &typeinfo
);
419 hr
= ITypeInfo_Invoke(typeinfo
, &(This
->lpVtbl
), dispIdMember
, wFlags
, pDispParams
,
420 pVarResult
, pExcepInfo
, puArgErr
);
421 ITypeInfo_Release(typeinfo
);
428 static HRESULT WINAPI
domdoc_get_nodeName(
429 IXMLDOMDocument2
*iface
,
432 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
433 return IXMLDOMNode_get_nodeName( This
->node
, name
);
437 static HRESULT WINAPI
domdoc_get_nodeValue(
438 IXMLDOMDocument2
*iface
,
441 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
442 return IXMLDOMNode_get_nodeValue( This
->node
, value
);
446 static HRESULT WINAPI
domdoc_put_nodeValue(
447 IXMLDOMDocument2
*iface
,
450 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
451 return IXMLDOMNode_put_nodeValue( This
->node
, value
);
455 static HRESULT WINAPI
domdoc_get_nodeType(
456 IXMLDOMDocument2
*iface
,
459 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
460 return IXMLDOMNode_get_nodeType( This
->node
, type
);
464 static HRESULT WINAPI
domdoc_get_parentNode(
465 IXMLDOMDocument2
*iface
,
466 IXMLDOMNode
** parent
)
468 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
469 return IXMLDOMNode_get_parentNode( This
->node
, parent
);
473 static HRESULT WINAPI
domdoc_get_childNodes(
474 IXMLDOMDocument2
*iface
,
475 IXMLDOMNodeList
** childList
)
477 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
478 return IXMLDOMNode_get_childNodes( This
->node
, childList
);
482 static HRESULT WINAPI
domdoc_get_firstChild(
483 IXMLDOMDocument2
*iface
,
484 IXMLDOMNode
** firstChild
)
486 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
487 return IXMLDOMNode_get_firstChild( This
->node
, firstChild
);
491 static HRESULT WINAPI
domdoc_get_lastChild(
492 IXMLDOMDocument2
*iface
,
493 IXMLDOMNode
** lastChild
)
495 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
496 return IXMLDOMNode_get_lastChild( This
->node
, lastChild
);
500 static HRESULT WINAPI
domdoc_get_previousSibling(
501 IXMLDOMDocument2
*iface
,
502 IXMLDOMNode
** previousSibling
)
504 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
505 return IXMLDOMNode_get_previousSibling( This
->node
, previousSibling
);
509 static HRESULT WINAPI
domdoc_get_nextSibling(
510 IXMLDOMDocument2
*iface
,
511 IXMLDOMNode
** nextSibling
)
513 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
514 return IXMLDOMNode_get_nextSibling( This
->node
, nextSibling
);
518 static HRESULT WINAPI
domdoc_get_attributes(
519 IXMLDOMDocument2
*iface
,
520 IXMLDOMNamedNodeMap
** attributeMap
)
522 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
523 return IXMLDOMNode_get_attributes( This
->node
, attributeMap
);
527 static HRESULT WINAPI
domdoc_insertBefore(
528 IXMLDOMDocument2
*iface
,
529 IXMLDOMNode
* newChild
,
531 IXMLDOMNode
** outNewChild
)
533 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
534 return IXMLDOMNode_insertBefore( This
->node
, newChild
, refChild
, outNewChild
);
538 static HRESULT WINAPI
domdoc_replaceChild(
539 IXMLDOMDocument2
*iface
,
540 IXMLDOMNode
* newChild
,
541 IXMLDOMNode
* oldChild
,
542 IXMLDOMNode
** outOldChild
)
544 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
545 return IXMLDOMNode_replaceChild( This
->node
, newChild
, oldChild
, outOldChild
);
549 static HRESULT WINAPI
domdoc_removeChild(
550 IXMLDOMDocument2
*iface
,
551 IXMLDOMNode
* childNode
,
552 IXMLDOMNode
** oldChild
)
554 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
555 return IXMLDOMNode_removeChild( This
->node
, childNode
, oldChild
);
559 static HRESULT WINAPI
domdoc_appendChild(
560 IXMLDOMDocument2
*iface
,
561 IXMLDOMNode
* newChild
,
562 IXMLDOMNode
** outNewChild
)
564 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
565 return IXMLDOMNode_appendChild( This
->node
, newChild
, outNewChild
);
569 static HRESULT WINAPI
domdoc_hasChildNodes(
570 IXMLDOMDocument2
*iface
,
571 VARIANT_BOOL
* hasChild
)
573 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
574 return IXMLDOMNode_hasChildNodes( This
->node
, hasChild
);
578 static HRESULT WINAPI
domdoc_get_ownerDocument(
579 IXMLDOMDocument2
*iface
,
580 IXMLDOMDocument
** DOMDocument
)
582 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
583 return IXMLDOMNode_get_ownerDocument( This
->node
, DOMDocument
);
587 static HRESULT WINAPI
domdoc_cloneNode(
588 IXMLDOMDocument2
*iface
,
590 IXMLDOMNode
** cloneRoot
)
592 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
593 return IXMLDOMNode_cloneNode( This
->node
, deep
, cloneRoot
);
597 static HRESULT WINAPI
domdoc_get_nodeTypeString(
598 IXMLDOMDocument2
*iface
,
601 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
602 return IXMLDOMNode_get_nodeTypeString( This
->node
, nodeType
);
606 static HRESULT WINAPI
domdoc_get_text(
607 IXMLDOMDocument2
*iface
,
610 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
611 return IXMLDOMNode_get_text( This
->node
, text
);
615 static HRESULT WINAPI
domdoc_put_text(
616 IXMLDOMDocument2
*iface
,
619 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
620 return IXMLDOMNode_put_text( This
->node
, text
);
624 static HRESULT WINAPI
domdoc_get_specified(
625 IXMLDOMDocument2
*iface
,
626 VARIANT_BOOL
* isSpecified
)
628 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
629 return IXMLDOMNode_get_specified( This
->node
, isSpecified
);
633 static HRESULT WINAPI
domdoc_get_definition(
634 IXMLDOMDocument2
*iface
,
635 IXMLDOMNode
** definitionNode
)
637 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
638 return IXMLDOMNode_get_definition( This
->node
, definitionNode
);
642 static HRESULT WINAPI
domdoc_get_nodeTypedValue(
643 IXMLDOMDocument2
*iface
,
644 VARIANT
* typedValue
)
646 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
647 return IXMLDOMNode_get_nodeTypedValue( This
->node
, typedValue
);
650 static HRESULT WINAPI
domdoc_put_nodeTypedValue(
651 IXMLDOMDocument2
*iface
,
654 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
655 return IXMLDOMNode_put_nodeTypedValue( This
->node
, typedValue
);
659 static HRESULT WINAPI
domdoc_get_dataType(
660 IXMLDOMDocument2
*iface
,
661 VARIANT
* dataTypeName
)
663 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
664 return IXMLDOMNode_get_dataType( This
->node
, dataTypeName
);
668 static HRESULT WINAPI
domdoc_put_dataType(
669 IXMLDOMDocument2
*iface
,
672 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
673 return IXMLDOMNode_put_dataType( This
->node
, dataTypeName
);
677 static HRESULT WINAPI
domdoc_get_xml(
678 IXMLDOMDocument2
*iface
,
681 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
682 return IXMLDOMNode_get_xml( This
->node
, xmlString
);
686 static HRESULT WINAPI
domdoc_transformNode(
687 IXMLDOMDocument2
*iface
,
688 IXMLDOMNode
* styleSheet
,
691 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
692 return IXMLDOMNode_transformNode( This
->node
, styleSheet
, xmlString
);
696 static HRESULT WINAPI
domdoc_selectNodes(
697 IXMLDOMDocument2
*iface
,
699 IXMLDOMNodeList
** resultList
)
701 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
702 return IXMLDOMNode_selectNodes( This
->node
, queryString
, resultList
);
706 static HRESULT WINAPI
domdoc_selectSingleNode(
707 IXMLDOMDocument2
*iface
,
709 IXMLDOMNode
** resultNode
)
711 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
712 return IXMLDOMNode_selectSingleNode( This
->node
, queryString
, resultNode
);
716 static HRESULT WINAPI
domdoc_get_parsed(
717 IXMLDOMDocument2
*iface
,
718 VARIANT_BOOL
* isParsed
)
720 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
721 return IXMLDOMNode_get_parsed( This
->node
, isParsed
);
725 static HRESULT WINAPI
domdoc_get_namespaceURI(
726 IXMLDOMDocument2
*iface
,
729 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
730 return IXMLDOMNode_get_namespaceURI( This
->node
, namespaceURI
);
734 static HRESULT WINAPI
domdoc_get_prefix(
735 IXMLDOMDocument2
*iface
,
738 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
739 return IXMLDOMNode_get_prefix( This
->node
, prefixString
);
743 static HRESULT WINAPI
domdoc_get_baseName(
744 IXMLDOMDocument2
*iface
,
747 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
748 return IXMLDOMNode_get_baseName( This
->node
, nameString
);
752 static HRESULT WINAPI
domdoc_transformNodeToObject(
753 IXMLDOMDocument2
*iface
,
754 IXMLDOMNode
* stylesheet
,
755 VARIANT outputObject
)
757 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
758 return IXMLDOMNode_transformNodeToObject( This
->node
, stylesheet
, outputObject
);
762 static HRESULT WINAPI
domdoc_get_doctype(
763 IXMLDOMDocument2
*iface
,
764 IXMLDOMDocumentType
** documentType
)
771 static HRESULT WINAPI
domdoc_get_implementation(
772 IXMLDOMDocument2
*iface
,
773 IXMLDOMImplementation
** impl
)
778 *impl
= (IXMLDOMImplementation
*)create_doc_Implementation();
783 static HRESULT WINAPI
domdoc_get_documentElement(
784 IXMLDOMDocument2
*iface
,
785 IXMLDOMElement
** DOMElement
)
787 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
788 xmlDocPtr xmldoc
= NULL
;
789 xmlNodePtr root
= NULL
;
790 IXMLDOMNode
*element_node
;
793 TRACE("%p %p\n", This
, This
->node
);
800 xmldoc
= get_doc( This
);
802 root
= xmlDocGetRootElement( xmldoc
);
806 element_node
= create_node( root
);
807 if(!element_node
) return S_FALSE
;
809 hr
= IXMLDOMNode_QueryInterface(element_node
, &IID_IXMLDOMElement
, (LPVOID
*)DOMElement
);
810 IXMLDOMNode_Release(element_node
);
816 static HRESULT WINAPI
domdoc_put_documentElement(
817 IXMLDOMDocument2
*iface
,
818 IXMLDOMElement
* DOMElement
)
820 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
821 IXMLDOMNode
*elementNode
;
825 TRACE("(%p)->(%p)\n", This
, DOMElement
);
827 hr
= IXMLDOMElement_QueryInterface( DOMElement
, &IID_IXMLDOMNode
, (void**)&elementNode
);
831 xmlNode
= impl_from_IXMLDOMNode( elementNode
);
832 xmlDocSetRootElement( get_doc(This
), xmlNode
->node
);
833 IXMLDOMNode_Release( elementNode
);
839 static HRESULT WINAPI
domdoc_createElement(
840 IXMLDOMDocument2
*iface
,
842 IXMLDOMElement
** element
)
845 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
850 TRACE("%p->(%s,%p)\n", iface
, debugstr_w(tagname
), element
);
852 xml_name
= xmlChar_from_wchar((WCHAR
*)tagname
);
853 xmlnode
= xmlNewDocNode(get_doc(This
), NULL
, xml_name
, NULL
);
855 TRACE("created xmlptr %p\n", xmlnode
);
856 elem_unk
= create_element(xmlnode
, NULL
);
857 HeapFree(GetProcessHeap(), 0, xml_name
);
859 hr
= IUnknown_QueryInterface(elem_unk
, &IID_IXMLDOMElement
, (void **)element
);
860 IUnknown_Release(elem_unk
);
861 TRACE("returning %p\n", *element
);
866 static HRESULT WINAPI
domdoc_createDocumentFragment(
867 IXMLDOMDocument2
*iface
,
868 IXMLDOMDocumentFragment
** docFrag
)
870 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
873 TRACE("%p\n", iface
);
880 xmlnode
= xmlNewDocFragment(get_doc( This
) );
885 xmlnode
->doc
= get_doc( This
);
887 *docFrag
= (IXMLDOMDocumentFragment
*)create_doc_fragment(xmlnode
);
893 static HRESULT WINAPI
domdoc_createTextNode(
894 IXMLDOMDocument2
*iface
,
898 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
900 xmlChar
*xml_content
;
902 TRACE("%p->(%s %p)\n", iface
, debugstr_w(data
), text
);
909 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
910 xmlnode
= xmlNewText(xml_content
);
911 HeapFree(GetProcessHeap(), 0, xml_content
);
916 xmlnode
->doc
= get_doc( This
);
918 *text
= (IXMLDOMText
*)create_text(xmlnode
);
924 static HRESULT WINAPI
domdoc_createComment(
925 IXMLDOMDocument2
*iface
,
927 IXMLDOMComment
** comment
)
929 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
931 xmlChar
*xml_content
;
933 TRACE("%p->(%s %p)\n", iface
, debugstr_w(data
), comment
);
940 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
941 xmlnode
= xmlNewComment(xml_content
);
942 HeapFree(GetProcessHeap(), 0, xml_content
);
947 xmlnode
->doc
= get_doc( This
);
949 *comment
= (IXMLDOMComment
*)create_comment(xmlnode
);
955 static HRESULT WINAPI
domdoc_createCDATASection(
956 IXMLDOMDocument2
*iface
,
958 IXMLDOMCDATASection
** cdata
)
960 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
962 xmlChar
*xml_content
;
964 TRACE("%p->(%s %p)\n", iface
, debugstr_w(data
), cdata
);
971 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
972 xmlnode
= xmlNewCDataBlock(get_doc( This
), xml_content
, strlen( (char*)xml_content
) );
973 HeapFree(GetProcessHeap(), 0, xml_content
);
978 xmlnode
->doc
= get_doc( This
);
980 *cdata
= (IXMLDOMCDATASection
*)create_cdata(xmlnode
);
986 static HRESULT WINAPI
domdoc_createProcessingInstruction(
987 IXMLDOMDocument2
*iface
,
990 IXMLDOMProcessingInstruction
** pi
)
992 #ifdef HAVE_XMLNEWDOCPI
994 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
995 xmlChar
*xml_target
, *xml_content
;
997 TRACE("%p->(%s %s %p)\n", iface
, debugstr_w(target
), debugstr_w(data
), pi
);
1000 return E_INVALIDARG
;
1002 if(!target
|| lstrlenW(target
) == 0)
1005 xml_target
= xmlChar_from_wchar((WCHAR
*)target
);
1006 xml_content
= xmlChar_from_wchar((WCHAR
*)data
);
1008 xmlnode
= xmlNewDocPI(get_doc(This
), xml_target
, xml_content
);
1009 TRACE("created xmlptr %p\n", xmlnode
);
1010 *pi
= (IXMLDOMProcessingInstruction
*)create_pi(xmlnode
);
1012 HeapFree(GetProcessHeap(), 0, xml_content
);
1013 HeapFree(GetProcessHeap(), 0, xml_target
);
1017 FIXME("Libxml 2.6.15 or greater required.\n");
1023 static HRESULT WINAPI
domdoc_createAttribute(
1024 IXMLDOMDocument2
*iface
,
1026 IXMLDOMAttribute
** attribute
)
1028 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1032 TRACE("%p->(%s %p)\n", iface
, debugstr_w(name
), attribute
);
1035 return E_INVALIDARG
;
1039 xml_name
= xmlChar_from_wchar((WCHAR
*)name
);
1040 xmlnode
= (xmlNode
*)xmlNewProp(NULL
, xml_name
, NULL
);
1041 HeapFree(GetProcessHeap(), 0, xml_name
);
1046 xmlnode
->doc
= get_doc( This
);
1048 *attribute
= (IXMLDOMAttribute
*)create_attribute(xmlnode
);
1054 static HRESULT WINAPI
domdoc_createEntityReference(
1055 IXMLDOMDocument2
*iface
,
1057 IXMLDOMEntityReference
** entityRef
)
1059 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1063 TRACE("%p\n", iface
);
1066 return E_INVALIDARG
;
1070 xml_name
= xmlChar_from_wchar((WCHAR
*)name
);
1071 xmlnode
= xmlNewReference(get_doc( This
), xml_name
);
1072 HeapFree(GetProcessHeap(), 0, xml_name
);
1077 xmlnode
->doc
= get_doc( This
);
1079 *entityRef
= (IXMLDOMEntityReference
*)create_doc_entity_ref(xmlnode
);
1085 static HRESULT WINAPI
domdoc_getElementsByTagName(
1086 IXMLDOMDocument2
*iface
,
1088 IXMLDOMNodeList
** resultList
)
1090 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1093 TRACE("(%p)->(%s, %p)\n", This
, debugstr_w(tagName
), resultList
);
1095 szPattern
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
)*(2+lstrlenW(tagName
)+1));
1096 szPattern
[0] = szPattern
[1] = '/';
1097 lstrcpyW(szPattern
+ 2, tagName
);
1099 hr
= queryresult_create((xmlNodePtr
)get_doc(This
), szPattern
, resultList
);
1100 HeapFree(GetProcessHeap(), 0, szPattern
);
1105 static DOMNodeType
get_node_type(VARIANT Type
)
1107 if(V_VT(&Type
) == VT_I4
)
1110 FIXME("Unsupported variant type %x\n", V_VT(&Type
));
1114 static HRESULT WINAPI
domdoc_createNode(
1115 IXMLDOMDocument2
*iface
,
1119 IXMLDOMNode
** node
)
1121 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1122 DOMNodeType node_type
;
1123 xmlNodePtr xmlnode
= NULL
;
1126 TRACE("(%p)->(type,%s,%s,%p)\n", This
, debugstr_w(name
), debugstr_w(namespaceURI
), node
);
1128 node_type
= get_node_type(Type
);
1129 TRACE("node_type %d\n", node_type
);
1131 xml_name
= xmlChar_from_wchar((WCHAR
*)name
);
1136 xmlnode
= xmlNewDocNode(get_doc(This
), NULL
, xml_name
, NULL
);
1137 *node
= create_node(xmlnode
);
1138 TRACE("created %p\n", xmlnode
);
1140 case NODE_ATTRIBUTE
:
1141 xmlnode
= (xmlNode
*)xmlNewProp(NULL
, xml_name
, NULL
);
1144 xmlnode
->doc
= get_doc( This
);
1146 *node
= (IXMLDOMNode
*)create_attribute(xmlnode
);
1149 TRACE("created %p\n", xmlnode
);
1153 FIXME("unhandled node type %d\n", node_type
);
1157 HeapFree(GetProcessHeap(), 0, xml_name
);
1159 if(xmlnode
&& *node
)
1165 static HRESULT WINAPI
domdoc_nodeFromID(
1166 IXMLDOMDocument2
*iface
,
1168 IXMLDOMNode
** node
)
1174 static HRESULT
domdoc_onDataAvailable(void *obj
, char *ptr
, DWORD len
)
1179 xmldoc
= doparse( ptr
, len
);
1181 xmldoc
->_private
= 0;
1182 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1188 static HRESULT
doread( domdoc
*This
, LPWSTR filename
)
1193 hr
= bind_url(filename
, domdoc_onDataAvailable
, This
, &bsc
);
1198 detach_bsc(This
->bsc
);
1204 static HRESULT WINAPI
domdoc_load(
1205 IXMLDOMDocument2
*iface
,
1207 VARIANT_BOOL
* isSuccessful
)
1209 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1210 LPWSTR filename
= NULL
;
1211 HRESULT hr
= S_FALSE
;
1212 IXMLDOMDocument2
*pNewDoc
= NULL
;
1213 IStream
*pStream
= NULL
;
1216 TRACE("type %d\n", V_VT(&xmlSource
) );
1218 *isSuccessful
= VARIANT_FALSE
;
1220 assert( This
->node
);
1222 attach_xmlnode(This
->node
, NULL
);
1224 switch( V_VT(&xmlSource
) )
1227 filename
= V_BSTR(&xmlSource
);
1230 hr
= IUnknown_QueryInterface(V_UNKNOWN(&xmlSource
), &IID_IXMLDOMDocument2
, (void**)&pNewDoc
);
1235 domdoc
*newDoc
= impl_from_IXMLDOMDocument2( pNewDoc
);
1236 xmldoc
= xmlCopyDoc(get_doc(newDoc
), 1);
1237 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1239 *isSuccessful
= VARIANT_TRUE
;
1244 hr
= IUnknown_QueryInterface(V_UNKNOWN(&xmlSource
), &IID_IStream
, (void**)&pStream
);
1247 IPersistStream
*pDocStream
;
1248 hr
= IUnknown_QueryInterface(iface
, &IID_IPersistStream
, (void**)&pDocStream
);
1251 hr
= xmldoc_IPersistStream_Load(pDocStream
, pStream
);
1252 IStream_Release(pStream
);
1255 *isSuccessful
= VARIANT_TRUE
;
1257 TRACE("Using ID_IStream to load Document\n");
1262 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr
);
1267 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr
);
1272 /* ISequentialStream */
1273 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr
, pNewDoc
, V_UNKNOWN(&xmlSource
)->lpVtbl
);
1277 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource
));
1280 TRACE("filename (%s)\n", debugstr_w(filename
));
1284 hr
= doread( This
, filename
);
1287 This
->error
= E_FAIL
;
1290 hr
= This
->error
= S_OK
;
1291 *isSuccessful
= VARIANT_TRUE
;
1295 if(!filename
|| FAILED(hr
)) {
1296 xmldoc
= xmlNewDoc(NULL
);
1297 xmldoc
->_private
= 0;
1298 attach_xmlnode(This
->node
, (xmlNodePtr
) xmldoc
);
1302 TRACE("ret (%d)\n", hr
);
1308 static HRESULT WINAPI
domdoc_get_readyState(
1309 IXMLDOMDocument2
*iface
,
1317 static HRESULT WINAPI
domdoc_get_parseError(
1318 IXMLDOMDocument2
*iface
,
1319 IXMLDOMParseError
** errorObj
)
1321 BSTR error_string
= NULL
;
1322 static const WCHAR err
[] = {'e','r','r','o','r',0};
1323 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1325 FIXME("(%p)->(%p): creating a dummy parseError\n", iface
, errorObj
);
1328 error_string
= SysAllocString(err
);
1330 *errorObj
= create_parseError(This
->error
, NULL
, error_string
, NULL
, 0, 0, 0);
1331 if(!*errorObj
) return E_OUTOFMEMORY
;
1336 static HRESULT WINAPI
domdoc_get_url(
1337 IXMLDOMDocument2
*iface
,
1345 static HRESULT WINAPI
domdoc_get_async(
1346 IXMLDOMDocument2
*iface
,
1347 VARIANT_BOOL
* isAsync
)
1349 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1351 TRACE("%p <- %d\n", isAsync
, This
->async
);
1352 *isAsync
= This
->async
;
1357 static HRESULT WINAPI
domdoc_put_async(
1358 IXMLDOMDocument2
*iface
,
1359 VARIANT_BOOL isAsync
)
1361 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1363 TRACE("%d\n", isAsync
);
1364 This
->async
= isAsync
;
1369 static HRESULT WINAPI
domdoc_abort(
1370 IXMLDOMDocument2
*iface
)
1377 static BOOL
bstr_to_utf8( BSTR bstr
, char **pstr
, int *plen
)
1379 UINT len
, blen
= SysStringLen( bstr
);
1382 len
= WideCharToMultiByte( CP_UTF8
, 0, bstr
, blen
, NULL
, 0, NULL
, NULL
);
1383 str
= HeapAlloc( GetProcessHeap(), 0, len
);
1386 WideCharToMultiByte( CP_UTF8
, 0, bstr
, blen
, str
, len
, NULL
, NULL
);
1392 static HRESULT WINAPI
domdoc_loadXML(
1393 IXMLDOMDocument2
*iface
,
1395 VARIANT_BOOL
* isSuccessful
)
1397 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1398 xmlDocPtr xmldoc
= NULL
;
1401 HRESULT hr
= S_FALSE
;
1403 TRACE("%p %s %p\n", This
, debugstr_w( bstrXML
), isSuccessful
);
1405 assert ( This
->node
);
1407 attach_xmlnode( This
->node
, NULL
);
1411 *isSuccessful
= VARIANT_FALSE
;
1413 if ( bstrXML
&& bstr_to_utf8( bstrXML
, &str
, &len
) )
1415 xmldoc
= doparse( str
, len
);
1416 HeapFree( GetProcessHeap(), 0, str
);
1418 This
->error
= E_FAIL
;
1421 hr
= This
->error
= S_OK
;
1422 *isSuccessful
= VARIANT_TRUE
;
1427 xmldoc
= xmlNewDoc(NULL
);
1429 xmldoc
->_private
= 0;
1430 attach_xmlnode( This
->node
, (xmlNodePtr
) xmldoc
);
1436 static HRESULT WINAPI
domdoc_save(
1437 IXMLDOMDocument2
*iface
,
1438 VARIANT destination
)
1440 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1447 TRACE("(%p)->(var(vt %x, %s))\n", This
, V_VT(&destination
),
1448 V_VT(&destination
) == VT_BSTR
? debugstr_w(V_BSTR(&destination
)) : NULL
);
1450 if(V_VT(&destination
) != VT_BSTR
&& V_VT(&destination
) != VT_UNKNOWN
)
1452 FIXME("Unhandled vt %d\n", V_VT(&destination
));
1456 if(V_VT(&destination
) == VT_UNKNOWN
)
1458 IUnknown
*pUnk
= V_UNKNOWN(&destination
);
1459 IXMLDOMDocument
*pDocument
;
1461 ret
= IXMLDOMDocument_QueryInterface(pUnk
, &IID_IXMLDOMDocument2
, (void**)&pDocument
);
1465 VARIANT_BOOL bSuccessful
;
1467 ret
= IXMLDOMDocument_get_xml(iface
, &bXML
);
1470 ret
= IXMLDOMDocument_loadXML(pDocument
, bXML
, &bSuccessful
);
1472 SysFreeString(bXML
);
1475 IXMLDOMDocument_Release(pDocument
);
1481 handle
= CreateFileW( V_BSTR(&destination
), GENERIC_WRITE
, 0,
1482 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1483 if( handle
== INVALID_HANDLE_VALUE
)
1485 WARN("failed to create file\n");
1489 xmlDocDumpMemory(get_doc(This
), &mem
, &size
);
1492 * libxml2 always adds XML declaration on top of the file and one for each processing instruction node in DOM tree.
1493 * MSXML adds XML declaration only for processing instruction nodes.
1494 * We skip the first XML declaration generated by libxml2 to get exactly what we need.
1497 if(size
> 2 && p
[0] == '<' && p
[1] == '?') {
1498 while(p
< mem
+size
&& (p
[0] != '?' || p
[1] != '>'))
1501 while(p
< mem
+size
&& isspace(*p
))
1506 if(!WriteFile(handle
, p
, (DWORD
)size
, &written
, NULL
) || written
!= (DWORD
)size
)
1508 WARN("write error\n");
1513 CloseHandle(handle
);
1517 static HRESULT WINAPI
domdoc_get_validateOnParse(
1518 IXMLDOMDocument2
*iface
,
1519 VARIANT_BOOL
* isValidating
)
1521 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1523 TRACE("%p <- %d\n", isValidating
, This
->validating
);
1524 *isValidating
= This
->validating
;
1529 static HRESULT WINAPI
domdoc_put_validateOnParse(
1530 IXMLDOMDocument2
*iface
,
1531 VARIANT_BOOL isValidating
)
1533 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1535 TRACE("%d\n", isValidating
);
1536 This
->validating
= isValidating
;
1541 static HRESULT WINAPI
domdoc_get_resolveExternals(
1542 IXMLDOMDocument2
*iface
,
1543 VARIANT_BOOL
* isResolving
)
1545 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1547 TRACE("%p <- %d\n", isResolving
, This
->resolving
);
1548 *isResolving
= This
->resolving
;
1553 static HRESULT WINAPI
domdoc_put_resolveExternals(
1554 IXMLDOMDocument2
*iface
,
1555 VARIANT_BOOL isResolving
)
1557 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1559 TRACE("%d\n", isResolving
);
1560 This
->resolving
= isResolving
;
1565 static HRESULT WINAPI
domdoc_get_preserveWhiteSpace(
1566 IXMLDOMDocument2
*iface
,
1567 VARIANT_BOOL
* isPreserving
)
1569 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1571 TRACE("%p <- %d\n", isPreserving
, This
->preserving
);
1572 *isPreserving
= This
->preserving
;
1577 static HRESULT WINAPI
domdoc_put_preserveWhiteSpace(
1578 IXMLDOMDocument2
*iface
,
1579 VARIANT_BOOL isPreserving
)
1581 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1583 TRACE("%d\n", isPreserving
);
1584 This
->preserving
= isPreserving
;
1589 static HRESULT WINAPI
domdoc_put_onReadyStateChange(
1590 IXMLDOMDocument2
*iface
,
1591 VARIANT readyStateChangeSink
)
1598 static HRESULT WINAPI
domdoc_put_onDataAvailable(
1599 IXMLDOMDocument2
*iface
,
1600 VARIANT onDataAvailableSink
)
1606 static HRESULT WINAPI
domdoc_put_onTransformNode(
1607 IXMLDOMDocument2
*iface
,
1608 VARIANT onTransformNodeSink
)
1614 static HRESULT WINAPI
domdoc_get_namespaces(
1615 IXMLDOMDocument2
* iface
,
1616 IXMLDOMSchemaCollection
** schemaCollection
)
1622 static HRESULT WINAPI
domdoc_get_schemas(
1623 IXMLDOMDocument2
* iface
,
1626 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1627 HRESULT hr
= S_FALSE
;
1628 IXMLDOMSchemaCollection
*cur_schema
= This
->schema
;
1630 TRACE("(%p)->(%p)\n", This
, var1
);
1632 VariantInit(var1
); /* Test shows we don't call VariantClear here */
1633 V_VT(var1
) = VT_NULL
;
1637 hr
= IXMLDOMSchemaCollection_QueryInterface(cur_schema
, &IID_IDispatch
, (void**)&V_DISPATCH(var1
));
1639 V_VT(var1
) = VT_DISPATCH
;
1644 static HRESULT WINAPI
domdoc_putref_schemas(
1645 IXMLDOMDocument2
* iface
,
1648 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1649 HRESULT hr
= E_FAIL
;
1650 IXMLDOMSchemaCollection
*new_schema
= NULL
;
1652 FIXME("(%p): semi-stub\n", This
);
1656 hr
= IUnknown_QueryInterface(V_UNKNOWN(&var1
), &IID_IXMLDOMSchemaCollection
, (void**)&new_schema
);
1660 hr
= IDispatch_QueryInterface(V_DISPATCH(&var1
), &IID_IXMLDOMSchemaCollection
, (void**)&new_schema
);
1669 WARN("Can't get schema from vt %x\n", V_VT(&var1
));
1674 IXMLDOMSchemaCollection
*old_schema
= InterlockedExchangePointer((void**)&This
->schema
, new_schema
);
1675 if(old_schema
) IXMLDOMSchemaCollection_Release(old_schema
);
1681 static HRESULT WINAPI
domdoc_validate(
1682 IXMLDOMDocument2
* iface
,
1683 IXMLDOMParseError
** err
)
1689 static HRESULT WINAPI
domdoc_setProperty(
1690 IXMLDOMDocument2
* iface
,
1694 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1696 if (lstrcmpiW(p
, SZ_PROPERTY_SELECTION_LANGUAGE
) == 0)
1702 V_VT(&varStr
) = VT_EMPTY
;
1703 if (V_VT(&var
) != VT_BSTR
)
1705 if (FAILED(hr
= VariantChangeType(&varStr
, &var
, 0, VT_BSTR
)))
1707 bstr
= V_BSTR(&varStr
);
1710 bstr
= V_BSTR(&var
);
1713 if (lstrcmpiW(bstr
, SZ_VALUE_XPATH
) == 0)
1714 This
->bUseXPath
= TRUE
;
1715 else if (lstrcmpiW(bstr
, SZ_VALUE_XSLPATTERN
) == 0)
1716 This
->bUseXPath
= FALSE
;
1720 VariantClear(&varStr
);
1724 FIXME("Unknown property %s\n", wine_dbgstr_w(p
));
1728 static HRESULT WINAPI
domdoc_getProperty(
1729 IXMLDOMDocument2
* iface
,
1733 domdoc
*This
= impl_from_IXMLDOMDocument2( iface
);
1736 return E_INVALIDARG
;
1737 if (lstrcmpiW(p
, SZ_PROPERTY_SELECTION_LANGUAGE
) == 0)
1739 V_VT(var
) = VT_BSTR
;
1740 if (This
->bUseXPath
)
1741 V_BSTR(var
) = SysAllocString(SZ_VALUE_XPATH
);
1743 V_BSTR(var
) = SysAllocString(SZ_VALUE_XSLPATTERN
);
1747 FIXME("Unknown property %s\n", wine_dbgstr_w(p
));
1751 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl
=
1753 domdoc_QueryInterface
,
1756 domdoc_GetTypeInfoCount
,
1758 domdoc_GetIDsOfNames
,
1760 domdoc_get_nodeName
,
1761 domdoc_get_nodeValue
,
1762 domdoc_put_nodeValue
,
1763 domdoc_get_nodeType
,
1764 domdoc_get_parentNode
,
1765 domdoc_get_childNodes
,
1766 domdoc_get_firstChild
,
1767 domdoc_get_lastChild
,
1768 domdoc_get_previousSibling
,
1769 domdoc_get_nextSibling
,
1770 domdoc_get_attributes
,
1771 domdoc_insertBefore
,
1772 domdoc_replaceChild
,
1775 domdoc_hasChildNodes
,
1776 domdoc_get_ownerDocument
,
1778 domdoc_get_nodeTypeString
,
1781 domdoc_get_specified
,
1782 domdoc_get_definition
,
1783 domdoc_get_nodeTypedValue
,
1784 domdoc_put_nodeTypedValue
,
1785 domdoc_get_dataType
,
1786 domdoc_put_dataType
,
1788 domdoc_transformNode
,
1790 domdoc_selectSingleNode
,
1792 domdoc_get_namespaceURI
,
1794 domdoc_get_baseName
,
1795 domdoc_transformNodeToObject
,
1797 domdoc_get_implementation
,
1798 domdoc_get_documentElement
,
1799 domdoc_put_documentElement
,
1800 domdoc_createElement
,
1801 domdoc_createDocumentFragment
,
1802 domdoc_createTextNode
,
1803 domdoc_createComment
,
1804 domdoc_createCDATASection
,
1805 domdoc_createProcessingInstruction
,
1806 domdoc_createAttribute
,
1807 domdoc_createEntityReference
,
1808 domdoc_getElementsByTagName
,
1812 domdoc_get_readyState
,
1813 domdoc_get_parseError
,
1820 domdoc_get_validateOnParse
,
1821 domdoc_put_validateOnParse
,
1822 domdoc_get_resolveExternals
,
1823 domdoc_put_resolveExternals
,
1824 domdoc_get_preserveWhiteSpace
,
1825 domdoc_put_preserveWhiteSpace
,
1826 domdoc_put_onReadyStateChange
,
1827 domdoc_put_onDataAvailable
,
1828 domdoc_put_onTransformNode
,
1829 domdoc_get_namespaces
,
1831 domdoc_putref_schemas
,
1837 /* xmldoc implementation of IObjectWithSite */
1838 static HRESULT WINAPI
1839 xmldoc_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
1841 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1842 return IXMLDocument_QueryInterface( (IXMLDocument
*)This
, riid
, ppvObject
);
1846 xmldoc_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
1848 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1849 return IXMLDocument_AddRef((IXMLDocument
*)This
);
1853 xmldoc_ObjectWithSite_Release( IObjectWithSite
* iface
)
1855 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1856 return IXMLDocument_Release((IXMLDocument
*)This
);
1859 static HRESULT WINAPI
1860 xmldoc_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
1862 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1864 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
1869 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
1872 static HRESULT WINAPI
1873 xmldoc_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
1875 domdoc
*This
= impl_from_IObjectWithSite(iface
);
1877 TRACE("%p %p\n", iface
, punk
);
1883 IUnknown_Release( This
->site
);
1891 IUnknown_AddRef( punk
);
1894 IUnknown_Release( This
->site
);
1901 static const IObjectWithSiteVtbl domdocObjectSite
=
1903 xmldoc_ObjectWithSite_QueryInterface
,
1904 xmldoc_ObjectWithSite_AddRef
,
1905 xmldoc_ObjectWithSite_Release
,
1910 static HRESULT WINAPI
xmldoc_Safety_QueryInterface(IObjectSafety
*iface
, REFIID riid
, void **ppv
)
1912 domdoc
*This
= impl_from_IObjectSafety(iface
);
1913 return IXMLDocument_QueryInterface( (IXMLDocument
*)This
, riid
, ppv
);
1916 static ULONG WINAPI
xmldoc_Safety_AddRef(IObjectSafety
*iface
)
1918 domdoc
*This
= impl_from_IObjectSafety(iface
);
1919 return IXMLDocument_AddRef((IXMLDocument
*)This
);
1922 static ULONG WINAPI
xmldoc_Safety_Release(IObjectSafety
*iface
)
1924 domdoc
*This
= impl_from_IObjectSafety(iface
);
1925 return IXMLDocument_Release((IXMLDocument
*)This
);
1928 #define SUPPORTED_OPTIONS (INTERFACESAFE_FOR_UNTRUSTED_CALLER|INTERFACESAFE_FOR_UNTRUSTED_DATA|INTERFACE_USES_SECURITY_MANAGER)
1930 static HRESULT WINAPI
xmldoc_Safety_GetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1931 DWORD
*pdwSupportedOptions
, DWORD
*pdwEnabledOptions
)
1933 domdoc
*This
= impl_from_IObjectSafety(iface
);
1935 TRACE("(%p)->(%s %p %p)\n", This
, debugstr_guid(riid
), pdwSupportedOptions
, pdwEnabledOptions
);
1937 if(!pdwSupportedOptions
|| !pdwEnabledOptions
)
1940 *pdwSupportedOptions
= SUPPORTED_OPTIONS
;
1941 *pdwEnabledOptions
= This
->safeopt
;
1946 static HRESULT WINAPI
xmldoc_Safety_SetInterfaceSafetyOptions(IObjectSafety
*iface
, REFIID riid
,
1947 DWORD dwOptionSetMask
, DWORD dwEnabledOptions
)
1949 domdoc
*This
= impl_from_IObjectSafety(iface
);
1951 TRACE("(%p)->(%s %x %x)\n", This
, debugstr_guid(riid
), dwOptionSetMask
, dwEnabledOptions
);
1953 if(dwOptionSetMask
& ~SUPPORTED_OPTIONS
)
1956 This
->safeopt
= dwEnabledOptions
& dwEnabledOptions
;
1960 static const IObjectSafetyVtbl domdocObjectSafetyVtbl
= {
1961 xmldoc_Safety_QueryInterface
,
1962 xmldoc_Safety_AddRef
,
1963 xmldoc_Safety_Release
,
1964 xmldoc_Safety_GetInterfaceSafetyOptions
,
1965 xmldoc_Safety_SetInterfaceSafetyOptions
1968 HRESULT
DOMDocument_create_from_xmldoc(xmlDocPtr xmldoc
, IXMLDOMDocument2
**document
)
1973 doc
= HeapAlloc( GetProcessHeap(), 0, sizeof (*doc
) );
1975 return E_OUTOFMEMORY
;
1977 doc
->lpVtbl
= &domdoc_vtbl
;
1978 doc
->lpvtblIPersistStream
= &xmldoc_IPersistStream_VTable
;
1979 doc
->lpvtblIObjectWithSite
= &domdocObjectSite
;
1980 doc
->lpvtblIObjectSafety
= &domdocObjectSafetyVtbl
;
1983 doc
->validating
= 0;
1985 doc
->preserving
= 0;
1986 doc
->bUseXPath
= FALSE
;
1994 doc
->node_unk
= create_basic_node( (xmlNodePtr
)xmldoc
, (IUnknown
*)&doc
->lpVtbl
);
1997 HeapFree(GetProcessHeap(), 0, doc
);
2001 hr
= IUnknown_QueryInterface(doc
->node_unk
, &IID_IXMLDOMNode
, (LPVOID
*)&doc
->node
);
2004 IUnknown_Release(doc
->node_unk
);
2005 HeapFree( GetProcessHeap(), 0, doc
);
2008 /* The ref on doc->node is actually looped back into this object, so release it */
2009 IXMLDOMNode_Release(doc
->node
);
2011 *document
= (IXMLDOMDocument2
*)&doc
->lpVtbl
;
2013 TRACE("returning iface %p\n", *document
);
2017 HRESULT
DOMDocument_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2022 TRACE("(%p,%p)\n", pUnkOuter
, ppObj
);
2024 xmldoc
= xmlNewDoc(NULL
);
2026 return E_OUTOFMEMORY
;
2028 xmldoc
->_private
= 0;
2030 hr
= DOMDocument_create_from_xmldoc(xmldoc
, (IXMLDOMDocument2
**)ppObj
);
2037 IUnknown
* create_domdoc( xmlNodePtr document
)
2042 TRACE("(%p)\n", document
);
2044 hr
= DOMDocument_create_from_xmldoc((xmlDocPtr
)document
, (IXMLDOMDocument2
**)&pObj
);
2048 return (IUnknown
*)pObj
;
2053 HRESULT
DOMDocument_create(IUnknown
*pUnkOuter
, LPVOID
*ppObj
)
2055 MESSAGE("This program tried to use a DOMDocument object, but\n"
2056 "libxml2 support was not present at compile time.\n");