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
38 #include "wine/debug.h"
40 #include "msxml_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msxml);
46 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};
47 static const WCHAR SZ_VALUE_XPATH[] = {'X','P','a','t','h',0};
48 static const WCHAR SZ_VALUE_XSLPATTERN[] = {'X','S','L','P','a','t','t','e','r','n',0};
51 const struct IBindStatusCallbackVtbl *lpVtbl;
54 static HRESULT WINAPI bsc_QueryInterface(
55 IBindStatusCallback *iface,
59 if (IsEqualGUID(riid, &IID_IUnknown) ||
60 IsEqualGUID(riid, &IID_IBindStatusCallback))
62 IBindStatusCallback_AddRef( iface );
67 FIXME("interface %s not implemented\n", debugstr_guid(riid));
71 static ULONG WINAPI bsc_AddRef(
72 IBindStatusCallback *iface )
77 static ULONG WINAPI bsc_Release(
78 IBindStatusCallback *iface )
83 static HRESULT WINAPI bsc_OnStartBinding(
84 IBindStatusCallback* iface,
91 static HRESULT WINAPI bsc_GetPriority(
92 IBindStatusCallback* iface,
98 static HRESULT WINAPI bsc_OnLowResource(
99 IBindStatusCallback* iface,
105 static HRESULT WINAPI bsc_OnProgress(
106 IBindStatusCallback* iface,
110 LPCWSTR szStatusText)
115 static HRESULT WINAPI bsc_OnStopBinding(
116 IBindStatusCallback* iface,
123 static HRESULT WINAPI bsc_GetBindInfo(
124 IBindStatusCallback* iface,
128 *grfBINDF = BINDF_RESYNCHRONIZE;
133 static HRESULT WINAPI bsc_OnDataAvailable(
134 IBindStatusCallback* iface,
137 FORMATETC* pformatetc,
143 static HRESULT WINAPI bsc_OnObjectAvailable(
144 IBindStatusCallback* iface,
151 static const struct IBindStatusCallbackVtbl bsc_vtbl =
163 bsc_OnObjectAvailable
166 static bsc domdoc_bsc = { &bsc_vtbl };
168 typedef struct _domdoc
170 const struct IXMLDOMDocument2Vtbl *lpVtbl;
171 const struct IPersistStreamVtbl *lpvtblIPersistStream;
174 VARIANT_BOOL validating;
175 VARIANT_BOOL resolving;
176 VARIANT_BOOL preserving;
180 IXMLDOMSchemaCollection *schema;
187 LONG xmldoc_add_ref(xmlDocPtr doc)
189 LONG ref = InterlockedIncrement((LONG*)&doc->_private);
194 LONG xmldoc_release(xmlDocPtr doc)
196 LONG ref = InterlockedDecrement((LONG*)&doc->_private);
200 TRACE("freeing docptr %p\n", doc);
207 static inline domdoc *impl_from_IXMLDOMDocument2( IXMLDOMDocument2 *iface )
209 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpVtbl));
212 static inline xmlDocPtr get_doc( domdoc *This )
214 return (xmlDocPtr) xmlNodePtr_from_domnode( This->node, XML_DOCUMENT_NODE );
217 static inline domdoc *impl_from_IPersistStream(IPersistStream *iface)
219 return (domdoc *)((char*)iface - FIELD_OFFSET(domdoc, lpvtblIPersistStream));
222 /************************************************************************
223 * xmldoc implementation of IPersistStream.
225 static HRESULT WINAPI xmldoc_IPersistStream_QueryInterface(
226 IPersistStream *iface, REFIID riid, LPVOID *ppvObj)
228 domdoc *this = impl_from_IPersistStream(iface);
229 return IXMLDocument_QueryInterface((IXMLDocument *)this, riid, ppvObj);
232 static ULONG WINAPI xmldoc_IPersistStream_AddRef(
233 IPersistStream *iface)
235 domdoc *this = impl_from_IPersistStream(iface);
236 return IXMLDocument_AddRef((IXMLDocument *)this);
239 static ULONG WINAPI xmldoc_IPersistStream_Release(
240 IPersistStream *iface)
242 domdoc *this = impl_from_IPersistStream(iface);
243 return IXMLDocument_Release((IXMLDocument *)this);
246 static HRESULT WINAPI xmldoc_IPersistStream_GetClassID(
247 IPersistStream *iface, CLSID *classid)
249 TRACE("(%p,%p): stub!\n", iface, classid);
254 *classid = CLSID_DOMDocument2;
259 static HRESULT WINAPI xmldoc_IPersistStream_IsDirty(
260 IPersistStream *iface)
262 domdoc *This = impl_from_IPersistStream(iface);
264 FIXME("(%p->%p): stub!\n", iface, This);
269 static HRESULT WINAPI xmldoc_IPersistStream_Load(
270 IPersistStream *iface, LPSTREAM pStm)
272 domdoc *This = impl_from_IPersistStream(iface);
275 DWORD read, written, len;
278 xmlDocPtr xmldoc = NULL;
280 TRACE("(%p, %p)\n", iface, pStm);
285 hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
291 IStream_Read(pStm, buf, sizeof(buf), &read);
292 hr = IStream_Write(This->stream, buf, read, &written);
293 } while(SUCCEEDED(hr) && written != 0 && read != 0);
297 ERR("Failed to copy stream\n");
301 hr = GetHGlobalFromStream(This->stream, &hglobal);
305 len = GlobalSize(hglobal);
306 ptr = GlobalLock(hglobal);
308 xmldoc = parse_xml(ptr, len);
309 GlobalUnlock(hglobal);
313 ERR("Failed to parse xml\n");
317 attach_xmlnode( This->node, (xmlNodePtr)xmldoc );
322 static HRESULT WINAPI xmldoc_IPersistStream_Save(
323 IPersistStream *iface, LPSTREAM pStm, BOOL fClearDirty)
325 FIXME("(%p, %p, %d): stub!\n", iface, pStm, fClearDirty);
329 static HRESULT WINAPI xmldoc_IPersistStream_GetSizeMax(
330 IPersistStream *iface, ULARGE_INTEGER *pcbSize)
332 TRACE("(%p, %p): stub!\n", iface, pcbSize);
336 static const IPersistStreamVtbl xmldoc_IPersistStream_VTable =
338 xmldoc_IPersistStream_QueryInterface,
339 xmldoc_IPersistStream_AddRef,
340 xmldoc_IPersistStream_Release,
341 xmldoc_IPersistStream_GetClassID,
342 xmldoc_IPersistStream_IsDirty,
343 xmldoc_IPersistStream_Load,
344 xmldoc_IPersistStream_Save,
345 xmldoc_IPersistStream_GetSizeMax,
348 static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument2 *iface, REFIID riid, void** ppvObject )
350 domdoc *This = impl_from_IXMLDOMDocument2( iface );
352 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
356 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
357 IsEqualGUID( riid, &IID_IDispatch ) ||
358 IsEqualGUID( riid, &IID_IXMLDOMDocument ) ||
359 IsEqualGUID( riid, &IID_IXMLDOMDocument2 ) )
363 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) )
365 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
367 else if (IsEqualGUID(&IID_IPersistStream, riid))
369 *ppvObject = (IPersistStream*)&(This->lpvtblIPersistStream);
371 else if(IsEqualGUID(&IID_IRunnableObject, riid))
373 TRACE("IID_IRunnableObject not supported returning NULL\n");
374 return E_NOINTERFACE;
378 FIXME("interface %s not implemented\n", debugstr_guid(riid));
379 return E_NOINTERFACE;
382 IXMLDOMDocument_AddRef( iface );
388 static ULONG WINAPI domdoc_AddRef(
389 IXMLDOMDocument2 *iface )
391 domdoc *This = impl_from_IXMLDOMDocument2( iface );
392 TRACE("%p\n", This );
393 return InterlockedIncrement( &This->ref );
397 static ULONG WINAPI domdoc_Release(
398 IXMLDOMDocument2 *iface )
400 domdoc *This = impl_from_IXMLDOMDocument2( iface );
403 TRACE("%p\n", This );
405 ref = InterlockedDecrement( &This->ref );
408 IUnknown_Release( This->node_unk );
409 if(This->schema) IXMLDOMSchemaCollection_Release( This->schema );
410 if (This->stream) IStream_Release(This->stream);
411 HeapFree( GetProcessHeap(), 0, This );
417 static HRESULT WINAPI domdoc_GetTypeInfoCount( IXMLDOMDocument2 *iface, UINT* pctinfo )
423 static HRESULT WINAPI domdoc_GetTypeInfo(
424 IXMLDOMDocument2 *iface,
425 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
431 static HRESULT WINAPI domdoc_GetIDsOfNames(
432 IXMLDOMDocument2 *iface,
444 static HRESULT WINAPI domdoc_Invoke(
445 IXMLDOMDocument2 *iface,
450 DISPPARAMS* pDispParams,
452 EXCEPINFO* pExcepInfo,
460 static HRESULT WINAPI domdoc_get_nodeName(
461 IXMLDOMDocument2 *iface,
464 domdoc *This = impl_from_IXMLDOMDocument2( iface );
465 return IXMLDOMNode_get_nodeName( This->node, name );
469 static HRESULT WINAPI domdoc_get_nodeValue(
470 IXMLDOMDocument2 *iface,
473 domdoc *This = impl_from_IXMLDOMDocument2( iface );
474 return IXMLDOMNode_get_nodeValue( This->node, value );
478 static HRESULT WINAPI domdoc_put_nodeValue(
479 IXMLDOMDocument2 *iface,
482 domdoc *This = impl_from_IXMLDOMDocument2( iface );
483 return IXMLDOMNode_put_nodeValue( This->node, value );
487 static HRESULT WINAPI domdoc_get_nodeType(
488 IXMLDOMDocument2 *iface,
491 domdoc *This = impl_from_IXMLDOMDocument2( iface );
492 return IXMLDOMNode_get_nodeType( This->node, type );
496 static HRESULT WINAPI domdoc_get_parentNode(
497 IXMLDOMDocument2 *iface,
498 IXMLDOMNode** parent )
500 domdoc *This = impl_from_IXMLDOMDocument2( iface );
501 return IXMLDOMNode_get_parentNode( This->node, parent );
505 static HRESULT WINAPI domdoc_get_childNodes(
506 IXMLDOMDocument2 *iface,
507 IXMLDOMNodeList** childList )
509 domdoc *This = impl_from_IXMLDOMDocument2( iface );
510 return IXMLDOMNode_get_childNodes( This->node, childList );
514 static HRESULT WINAPI domdoc_get_firstChild(
515 IXMLDOMDocument2 *iface,
516 IXMLDOMNode** firstChild )
518 domdoc *This = impl_from_IXMLDOMDocument2( iface );
519 return IXMLDOMNode_get_firstChild( This->node, firstChild );
523 static HRESULT WINAPI domdoc_get_lastChild(
524 IXMLDOMDocument2 *iface,
525 IXMLDOMNode** lastChild )
527 domdoc *This = impl_from_IXMLDOMDocument2( iface );
528 return IXMLDOMNode_get_lastChild( This->node, lastChild );
532 static HRESULT WINAPI domdoc_get_previousSibling(
533 IXMLDOMDocument2 *iface,
534 IXMLDOMNode** previousSibling )
536 domdoc *This = impl_from_IXMLDOMDocument2( iface );
537 return IXMLDOMNode_get_previousSibling( This->node, previousSibling );
541 static HRESULT WINAPI domdoc_get_nextSibling(
542 IXMLDOMDocument2 *iface,
543 IXMLDOMNode** nextSibling )
545 domdoc *This = impl_from_IXMLDOMDocument2( iface );
546 return IXMLDOMNode_get_nextSibling( This->node, nextSibling );
550 static HRESULT WINAPI domdoc_get_attributes(
551 IXMLDOMDocument2 *iface,
552 IXMLDOMNamedNodeMap** attributeMap )
554 domdoc *This = impl_from_IXMLDOMDocument2( iface );
555 return IXMLDOMNode_get_attributes( This->node, attributeMap );
559 static HRESULT WINAPI domdoc_insertBefore(
560 IXMLDOMDocument2 *iface,
561 IXMLDOMNode* newChild,
563 IXMLDOMNode** outNewChild )
565 domdoc *This = impl_from_IXMLDOMDocument2( iface );
566 return IXMLDOMNode_insertBefore( This->node, newChild, refChild, outNewChild );
570 static HRESULT WINAPI domdoc_replaceChild(
571 IXMLDOMDocument2 *iface,
572 IXMLDOMNode* newChild,
573 IXMLDOMNode* oldChild,
574 IXMLDOMNode** outOldChild)
576 domdoc *This = impl_from_IXMLDOMDocument2( iface );
577 return IXMLDOMNode_replaceChild( This->node, newChild, oldChild, outOldChild );
581 static HRESULT WINAPI domdoc_removeChild(
582 IXMLDOMDocument2 *iface,
583 IXMLDOMNode* childNode,
584 IXMLDOMNode** oldChild)
586 domdoc *This = impl_from_IXMLDOMDocument2( iface );
587 return IXMLDOMNode_removeChild( This->node, childNode, oldChild );
591 static HRESULT WINAPI domdoc_appendChild(
592 IXMLDOMDocument2 *iface,
593 IXMLDOMNode* newChild,
594 IXMLDOMNode** outNewChild)
596 domdoc *This = impl_from_IXMLDOMDocument2( iface );
597 return IXMLDOMNode_appendChild( This->node, newChild, outNewChild );
601 static HRESULT WINAPI domdoc_hasChildNodes(
602 IXMLDOMDocument2 *iface,
603 VARIANT_BOOL* hasChild)
605 domdoc *This = impl_from_IXMLDOMDocument2( iface );
606 return IXMLDOMNode_hasChildNodes( This->node, hasChild );
610 static HRESULT WINAPI domdoc_get_ownerDocument(
611 IXMLDOMDocument2 *iface,
612 IXMLDOMDocument** DOMDocument)
614 domdoc *This = impl_from_IXMLDOMDocument2( iface );
615 return IXMLDOMNode_get_ownerDocument( This->node, DOMDocument );
619 static HRESULT WINAPI domdoc_cloneNode(
620 IXMLDOMDocument2 *iface,
622 IXMLDOMNode** cloneRoot)
624 domdoc *This = impl_from_IXMLDOMDocument2( iface );
625 return IXMLDOMNode_cloneNode( This->node, deep, cloneRoot );
629 static HRESULT WINAPI domdoc_get_nodeTypeString(
630 IXMLDOMDocument2 *iface,
633 domdoc *This = impl_from_IXMLDOMDocument2( iface );
634 return IXMLDOMNode_get_nodeTypeString( This->node, nodeType );
638 static HRESULT WINAPI domdoc_get_text(
639 IXMLDOMDocument2 *iface,
642 domdoc *This = impl_from_IXMLDOMDocument2( iface );
643 return IXMLDOMNode_get_text( This->node, text );
647 static HRESULT WINAPI domdoc_put_text(
648 IXMLDOMDocument2 *iface,
651 domdoc *This = impl_from_IXMLDOMDocument2( iface );
652 return IXMLDOMNode_put_text( This->node, text );
656 static HRESULT WINAPI domdoc_get_specified(
657 IXMLDOMDocument2 *iface,
658 VARIANT_BOOL* isSpecified )
660 domdoc *This = impl_from_IXMLDOMDocument2( iface );
661 return IXMLDOMNode_get_specified( This->node, isSpecified );
665 static HRESULT WINAPI domdoc_get_definition(
666 IXMLDOMDocument2 *iface,
667 IXMLDOMNode** definitionNode )
669 domdoc *This = impl_from_IXMLDOMDocument2( iface );
670 return IXMLDOMNode_get_definition( This->node, definitionNode );
674 static HRESULT WINAPI domdoc_get_nodeTypedValue(
675 IXMLDOMDocument2 *iface,
676 VARIANT* typedValue )
678 domdoc *This = impl_from_IXMLDOMDocument2( iface );
679 return IXMLDOMNode_get_nodeTypedValue( This->node, typedValue );
682 static HRESULT WINAPI domdoc_put_nodeTypedValue(
683 IXMLDOMDocument2 *iface,
686 domdoc *This = impl_from_IXMLDOMDocument2( iface );
687 return IXMLDOMNode_put_nodeTypedValue( This->node, typedValue );
691 static HRESULT WINAPI domdoc_get_dataType(
692 IXMLDOMDocument2 *iface,
693 VARIANT* dataTypeName )
695 domdoc *This = impl_from_IXMLDOMDocument2( iface );
696 return IXMLDOMNode_get_dataType( This->node, dataTypeName );
700 static HRESULT WINAPI domdoc_put_dataType(
701 IXMLDOMDocument2 *iface,
704 domdoc *This = impl_from_IXMLDOMDocument2( iface );
705 return IXMLDOMNode_put_dataType( This->node, dataTypeName );
709 static HRESULT WINAPI domdoc_get_xml(
710 IXMLDOMDocument2 *iface,
713 domdoc *This = impl_from_IXMLDOMDocument2( iface );
714 return IXMLDOMNode_get_xml( This->node, xmlString );
718 static HRESULT WINAPI domdoc_transformNode(
719 IXMLDOMDocument2 *iface,
720 IXMLDOMNode* styleSheet,
723 domdoc *This = impl_from_IXMLDOMDocument2( iface );
724 return IXMLDOMNode_transformNode( This->node, styleSheet, xmlString );
728 static HRESULT WINAPI domdoc_selectNodes(
729 IXMLDOMDocument2 *iface,
731 IXMLDOMNodeList** resultList )
733 domdoc *This = impl_from_IXMLDOMDocument2( iface );
734 return IXMLDOMNode_selectNodes( This->node, queryString, resultList );
738 static HRESULT WINAPI domdoc_selectSingleNode(
739 IXMLDOMDocument2 *iface,
741 IXMLDOMNode** resultNode )
743 domdoc *This = impl_from_IXMLDOMDocument2( iface );
744 return IXMLDOMNode_selectSingleNode( This->node, queryString, resultNode );
748 static HRESULT WINAPI domdoc_get_parsed(
749 IXMLDOMDocument2 *iface,
750 VARIANT_BOOL* isParsed )
752 domdoc *This = impl_from_IXMLDOMDocument2( iface );
753 return IXMLDOMNode_get_parsed( This->node, isParsed );
757 static HRESULT WINAPI domdoc_get_namespaceURI(
758 IXMLDOMDocument2 *iface,
761 domdoc *This = impl_from_IXMLDOMDocument2( iface );
762 return IXMLDOMNode_get_namespaceURI( This->node, namespaceURI );
766 static HRESULT WINAPI domdoc_get_prefix(
767 IXMLDOMDocument2 *iface,
770 domdoc *This = impl_from_IXMLDOMDocument2( iface );
771 return IXMLDOMNode_get_prefix( This->node, prefixString );
775 static HRESULT WINAPI domdoc_get_baseName(
776 IXMLDOMDocument2 *iface,
779 domdoc *This = impl_from_IXMLDOMDocument2( iface );
780 return IXMLDOMNode_get_baseName( This->node, nameString );
784 static HRESULT WINAPI domdoc_transformNodeToObject(
785 IXMLDOMDocument2 *iface,
786 IXMLDOMNode* stylesheet,
787 VARIANT outputObject)
789 domdoc *This = impl_from_IXMLDOMDocument2( iface );
790 return IXMLDOMNode_transformNodeToObject( This->node, stylesheet, outputObject );
794 static HRESULT WINAPI domdoc_get_doctype(
795 IXMLDOMDocument2 *iface,
796 IXMLDOMDocumentType** documentType )
803 static HRESULT WINAPI domdoc_get_implementation(
804 IXMLDOMDocument2 *iface,
805 IXMLDOMImplementation** impl )
810 *impl = (IXMLDOMImplementation*)create_doc_Implementation();
815 static HRESULT WINAPI domdoc_get_documentElement(
816 IXMLDOMDocument2 *iface,
817 IXMLDOMElement** DOMElement )
819 domdoc *This = impl_from_IXMLDOMDocument2( iface );
820 xmlDocPtr xmldoc = NULL;
821 xmlNodePtr root = NULL;
822 IXMLDOMNode *element_node;
825 TRACE("%p %p\n", This, This->node);
832 xmldoc = get_doc( This );
834 root = xmlDocGetRootElement( xmldoc );
838 element_node = create_node( root );
839 if(!element_node) return S_FALSE;
841 hr = IXMLDOMNode_QueryInterface(element_node, &IID_IXMLDOMElement, (LPVOID*)DOMElement);
842 IXMLDOMNode_Release(element_node);
848 static HRESULT WINAPI domdoc_documentElement(
849 IXMLDOMDocument2 *iface,
850 IXMLDOMElement* DOMElement )
857 static HRESULT WINAPI domdoc_createElement(
858 IXMLDOMDocument2 *iface,
860 IXMLDOMElement** element )
863 domdoc *This = impl_from_IXMLDOMDocument2( iface );
868 TRACE("%p->(%s,%p)\n", iface, debugstr_w(tagname), element);
870 xml_name = xmlChar_from_wchar((WCHAR*)tagname);
871 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
873 TRACE("created xmlptr %p\n", xmlnode);
874 elem_unk = create_element(xmlnode, NULL);
875 HeapFree(GetProcessHeap(), 0, xml_name);
877 hr = IUnknown_QueryInterface(elem_unk, &IID_IXMLDOMElement, (void **)element);
878 IUnknown_Release(elem_unk);
879 TRACE("returning %p\n", *element);
884 static HRESULT WINAPI domdoc_createDocumentFragment(
885 IXMLDOMDocument2 *iface,
886 IXMLDOMDocumentFragment** docFrag )
888 domdoc *This = impl_from_IXMLDOMDocument2( iface );
891 TRACE("%p\n", iface);
898 xmlnode = xmlNewDocFragment(get_doc( This ) );
903 xmlnode->doc = get_doc( This );
905 *docFrag = (IXMLDOMDocumentFragment*)create_doc_fragment(xmlnode);
911 static HRESULT WINAPI domdoc_createTextNode(
912 IXMLDOMDocument2 *iface,
916 domdoc *This = impl_from_IXMLDOMDocument2( iface );
918 xmlChar *xml_content;
920 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), text);
927 xml_content = xmlChar_from_wchar((WCHAR*)data);
928 xmlnode = xmlNewText(xml_content);
929 HeapFree(GetProcessHeap(), 0, xml_content);
934 xmlnode->doc = get_doc( This );
936 *text = (IXMLDOMText*)create_text(xmlnode);
942 static HRESULT WINAPI domdoc_createComment(
943 IXMLDOMDocument2 *iface,
945 IXMLDOMComment** comment )
947 domdoc *This = impl_from_IXMLDOMDocument2( iface );
949 xmlChar *xml_content;
951 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), comment);
958 xml_content = xmlChar_from_wchar((WCHAR*)data);
959 xmlnode = xmlNewComment(xml_content);
960 HeapFree(GetProcessHeap(), 0, xml_content);
965 xmlnode->doc = get_doc( This );
967 *comment = (IXMLDOMComment*)create_comment(xmlnode);
973 static HRESULT WINAPI domdoc_createCDATASection(
974 IXMLDOMDocument2 *iface,
976 IXMLDOMCDATASection** cdata )
978 domdoc *This = impl_from_IXMLDOMDocument2( iface );
980 xmlChar *xml_content;
982 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), comment);
989 xml_content = xmlChar_from_wchar((WCHAR*)data);
990 xmlnode = xmlNewCDataBlock(get_doc( This ), xml_content, strlen( (char*)xml_content) );
991 HeapFree(GetProcessHeap(), 0, xml_content);
996 xmlnode->doc = get_doc( This );
998 *cdata = (IXMLDOMCDATASection*)create_cdata(xmlnode);
1004 static HRESULT WINAPI domdoc_createProcessingInstruction(
1005 IXMLDOMDocument2 *iface,
1008 IXMLDOMProcessingInstruction** pi )
1010 #ifdef HAVE_XMLNEWDOCPI
1012 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1013 xmlChar *xml_target, *xml_content;
1015 TRACE("%p->(%s %s %p)\n", iface, debugstr_w(target), debugstr_w(data), pi);
1018 return E_INVALIDARG;
1020 if(!target || lstrlenW(target) == 0)
1023 xml_target = xmlChar_from_wchar((WCHAR*)target);
1024 xml_content = xmlChar_from_wchar((WCHAR*)data);
1026 xmlnode = xmlNewDocPI(get_doc(This), xml_target, xml_content);
1027 TRACE("created xmlptr %p\n", xmlnode);
1028 *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode);
1030 HeapFree(GetProcessHeap(), 0, xml_content);
1031 HeapFree(GetProcessHeap(), 0, xml_target);
1035 FIXME("Libxml 2.6.15 or greater required.\n");
1041 static HRESULT WINAPI domdoc_createAttribute(
1042 IXMLDOMDocument2 *iface,
1044 IXMLDOMAttribute** attribute )
1046 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1050 TRACE("%p->(%s %p)\n", iface, debugstr_w(name), attribute);
1053 return E_INVALIDARG;
1057 xml_name = xmlChar_from_wchar((WCHAR*)name);
1058 xmlnode = (xmlNode *)xmlNewProp(NULL, xml_name, NULL);
1059 HeapFree(GetProcessHeap(), 0, xml_name);
1064 xmlnode->doc = get_doc( This );
1066 *attribute = (IXMLDOMAttribute*)create_attribute(xmlnode);
1072 static HRESULT WINAPI domdoc_createEntityReference(
1073 IXMLDOMDocument2 *iface,
1075 IXMLDOMEntityReference** entityRef )
1077 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1081 TRACE("%p\n", iface);
1084 return E_INVALIDARG;
1088 xml_name = xmlChar_from_wchar((WCHAR*)name);
1089 xmlnode = xmlNewReference(get_doc( This ), xml_name );
1090 HeapFree(GetProcessHeap(), 0, xml_name);
1095 xmlnode->doc = get_doc( This );
1097 *entityRef = (IXMLDOMEntityReference*)create_doc_entity_ref(xmlnode);
1103 static HRESULT WINAPI domdoc_getElementsByTagName(
1104 IXMLDOMDocument2 *iface,
1106 IXMLDOMNodeList** resultList )
1108 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1111 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
1113 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(2+lstrlenW(tagName)+1));
1114 szPattern[0] = szPattern[1] = '/';
1115 lstrcpyW(szPattern + 2, tagName);
1117 hr = queryresult_create((xmlNodePtr)get_doc(This), szPattern, resultList);
1118 HeapFree(GetProcessHeap(), 0, szPattern);
1123 static DOMNodeType get_node_type(VARIANT Type)
1125 if(V_VT(&Type) == VT_I4)
1128 FIXME("Unsupported variant type %x\n", V_VT(&Type));
1132 static HRESULT WINAPI domdoc_createNode(
1133 IXMLDOMDocument2 *iface,
1137 IXMLDOMNode** node )
1139 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1140 DOMNodeType node_type;
1141 xmlNodePtr xmlnode = NULL;
1144 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
1146 node_type = get_node_type(Type);
1147 TRACE("node_type %d\n", node_type);
1149 xml_name = xmlChar_from_wchar((WCHAR*)name);
1154 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
1155 *node = create_node(xmlnode);
1156 TRACE("created %p\n", xmlnode);
1160 FIXME("unhandled node type %d\n", node_type);
1164 HeapFree(GetProcessHeap(), 0, xml_name);
1166 if(xmlnode && *node)
1172 static HRESULT WINAPI domdoc_nodeFromID(
1173 IXMLDOMDocument2 *iface,
1175 IXMLDOMNode** node )
1181 static xmlDocPtr doparse( char *ptr, int len )
1183 #ifdef HAVE_XMLREADMEMORY
1185 * use xmlReadMemory if possible so we can suppress
1186 * writing errors to stderr
1188 return xmlReadMemory( ptr, len, NULL, NULL,
1189 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
1191 return xmlParseMemory( ptr, len );
1195 static xmlDocPtr doread( LPWSTR filename )
1197 xmlDocPtr xmldoc = NULL;
1200 IStream *stream, *memstream;
1201 WCHAR url[INTERNET_MAX_URL_LENGTH];
1203 DWORD read, written;
1205 TRACE("%s\n", debugstr_w( filename ));
1207 if(!PathIsURLW(filename))
1209 WCHAR fullpath[MAX_PATH];
1210 DWORD needed = sizeof(url)/sizeof(WCHAR);
1212 if(!PathSearchAndQualifyW(filename, fullpath, sizeof(fullpath)/sizeof(WCHAR)))
1214 WARN("can't find path\n");
1218 if(FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0)))
1220 ERR("can't create url from path\n");
1226 hr = CreateBindCtx(0, &pbc);
1229 hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&domdoc_bsc.lpVtbl, NULL, 0);
1233 hr = CreateURLMoniker(NULL, filename, &moniker);
1236 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
1237 IMoniker_Release(moniker);
1240 IBindCtx_Release(pbc);
1245 hr = CreateStreamOnHGlobal(NULL, TRUE, &memstream);
1248 IStream_Release(stream);
1254 IStream_Read(stream, buf, sizeof(buf), &read);
1255 hr = IStream_Write(memstream, buf, read, &written);
1256 } while(SUCCEEDED(hr) && written != 0 && read != 0);
1261 hr = GetHGlobalFromStream(memstream, &hglobal);
1264 DWORD len = GlobalSize(hglobal);
1265 char *ptr = GlobalLock(hglobal);
1267 xmldoc = doparse( ptr, len );
1268 GlobalUnlock(hglobal);
1271 IStream_Release(memstream);
1272 IStream_Release(stream);
1276 static HRESULT WINAPI domdoc_load(
1277 IXMLDOMDocument2 *iface,
1279 VARIANT_BOOL* isSuccessful )
1281 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1282 LPWSTR filename = NULL;
1283 xmlDocPtr xmldoc = NULL;
1284 HRESULT hr = S_FALSE;
1285 IXMLDOMDocument2 *pNewDoc = NULL;
1286 IStream *pStream = NULL;
1288 TRACE("type %d\n", V_VT(&xmlSource) );
1290 *isSuccessful = VARIANT_FALSE;
1292 assert( This->node );
1294 attach_xmlnode(This->node, NULL);
1296 switch( V_VT(&xmlSource) )
1299 filename = V_BSTR(&xmlSource);
1302 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IXMLDOMDocument2, (void**)&pNewDoc);
1307 domdoc *newDoc = impl_from_IXMLDOMDocument2( pNewDoc );
1308 xmldoc = xmlCopyDoc(get_doc(newDoc), 1);
1309 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1311 *isSuccessful = VARIANT_TRUE;
1316 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IStream, (void**)&pStream);
1319 IPersistStream *pDocStream;
1320 hr = IUnknown_QueryInterface(iface, &IID_IPersistStream, (void**)&pDocStream);
1323 hr = xmldoc_IPersistStream_Load(pDocStream, pStream);
1324 IStream_Release(pStream);
1327 *isSuccessful = VARIANT_TRUE;
1329 TRACE("Using ID_IStream to load Document\n");
1334 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr);
1339 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr);
1344 /* ISequentialStream */
1345 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr, pNewDoc, V_UNKNOWN(&xmlSource)->lpVtbl);
1349 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource));
1352 TRACE("filename (%s)\n", debugstr_w(filename));
1356 xmldoc = doread( filename );
1359 This->error = E_FAIL;
1362 hr = This->error = S_OK;
1363 *isSuccessful = VARIANT_TRUE;
1368 xmldoc = xmlNewDoc(NULL);
1370 xmldoc->_private = 0;
1371 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1373 TRACE("ret (%d)\n", hr);
1379 static HRESULT WINAPI domdoc_get_readyState(
1380 IXMLDOMDocument2 *iface,
1388 static HRESULT WINAPI domdoc_get_parseError(
1389 IXMLDOMDocument2 *iface,
1390 IXMLDOMParseError** errorObj )
1392 BSTR error_string = NULL;
1393 static const WCHAR err[] = {'e','r','r','o','r',0};
1394 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1396 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1399 error_string = SysAllocString(err);
1401 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1402 if(!*errorObj) return E_OUTOFMEMORY;
1407 static HRESULT WINAPI domdoc_get_url(
1408 IXMLDOMDocument2 *iface,
1416 static HRESULT WINAPI domdoc_get_async(
1417 IXMLDOMDocument2 *iface,
1418 VARIANT_BOOL* isAsync )
1420 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1422 TRACE("%p <- %d\n", isAsync, This->async);
1423 *isAsync = This->async;
1428 static HRESULT WINAPI domdoc_put_async(
1429 IXMLDOMDocument2 *iface,
1430 VARIANT_BOOL isAsync )
1432 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1434 TRACE("%d\n", isAsync);
1435 This->async = isAsync;
1440 static HRESULT WINAPI domdoc_abort(
1441 IXMLDOMDocument2 *iface )
1448 static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1450 UINT len, blen = SysStringLen( bstr );
1453 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1454 str = HeapAlloc( GetProcessHeap(), 0, len );
1457 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1463 static HRESULT WINAPI domdoc_loadXML(
1464 IXMLDOMDocument2 *iface,
1466 VARIANT_BOOL* isSuccessful )
1468 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1469 xmlDocPtr xmldoc = NULL;
1472 HRESULT hr = S_FALSE;
1474 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1476 assert ( This->node );
1478 attach_xmlnode( This->node, NULL );
1482 *isSuccessful = VARIANT_FALSE;
1484 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1486 xmldoc = doparse( str, len );
1487 HeapFree( GetProcessHeap(), 0, str );
1489 This->error = E_FAIL;
1492 hr = This->error = S_OK;
1493 *isSuccessful = VARIANT_TRUE;
1498 xmldoc = xmlNewDoc(NULL);
1500 xmldoc->_private = 0;
1501 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1507 static HRESULT WINAPI domdoc_save(
1508 IXMLDOMDocument2 *iface,
1509 VARIANT destination )
1511 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1518 TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
1519 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1521 if(V_VT(&destination) != VT_BSTR)
1523 FIXME("Unhandled vt %x\n", V_VT(&destination));
1527 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1528 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1529 if( handle == INVALID_HANDLE_VALUE )
1531 WARN("failed to create file\n");
1535 xmlDocDumpMemory(get_doc(This), &mem, &size);
1536 if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size)
1538 WARN("write error\n");
1543 CloseHandle(handle);
1547 static HRESULT WINAPI domdoc_get_validateOnParse(
1548 IXMLDOMDocument2 *iface,
1549 VARIANT_BOOL* isValidating )
1551 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1553 TRACE("%p <- %d\n", isValidating, This->validating);
1554 *isValidating = This->validating;
1559 static HRESULT WINAPI domdoc_put_validateOnParse(
1560 IXMLDOMDocument2 *iface,
1561 VARIANT_BOOL isValidating )
1563 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1565 TRACE("%d\n", isValidating);
1566 This->validating = isValidating;
1571 static HRESULT WINAPI domdoc_get_resolveExternals(
1572 IXMLDOMDocument2 *iface,
1573 VARIANT_BOOL* isResolving )
1575 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1577 TRACE("%p <- %d\n", isResolving, This->resolving);
1578 *isResolving = This->resolving;
1583 static HRESULT WINAPI domdoc_put_resolveExternals(
1584 IXMLDOMDocument2 *iface,
1585 VARIANT_BOOL isResolving )
1587 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1589 TRACE("%d\n", isResolving);
1590 This->resolving = isResolving;
1595 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1596 IXMLDOMDocument2 *iface,
1597 VARIANT_BOOL* isPreserving )
1599 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1601 TRACE("%p <- %d\n", isPreserving, This->preserving);
1602 *isPreserving = This->preserving;
1607 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1608 IXMLDOMDocument2 *iface,
1609 VARIANT_BOOL isPreserving )
1611 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1613 TRACE("%d\n", isPreserving);
1614 This->preserving = isPreserving;
1619 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1620 IXMLDOMDocument2 *iface,
1621 VARIANT readyStateChangeSink )
1628 static HRESULT WINAPI domdoc_put_onDataAvailable(
1629 IXMLDOMDocument2 *iface,
1630 VARIANT onDataAvailableSink )
1636 static HRESULT WINAPI domdoc_put_onTransformNode(
1637 IXMLDOMDocument2 *iface,
1638 VARIANT onTransformNodeSink )
1644 static HRESULT WINAPI domdoc_get_namespaces(
1645 IXMLDOMDocument2* iface,
1646 IXMLDOMSchemaCollection** schemaCollection )
1652 static HRESULT WINAPI domdoc_get_schemas(
1653 IXMLDOMDocument2* iface,
1656 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1657 HRESULT hr = S_FALSE;
1658 IXMLDOMSchemaCollection *cur_schema = This->schema;
1660 TRACE("(%p)->(%p)\n", This, var1);
1662 VariantInit(var1); /* Test shows we don't call VariantClear here */
1663 V_VT(var1) = VT_NULL;
1667 hr = IXMLDOMSchemaCollection_QueryInterface(cur_schema, &IID_IDispatch, (void**)&V_DISPATCH(var1));
1669 V_VT(var1) = VT_DISPATCH;
1674 static HRESULT WINAPI domdoc_putref_schemas(
1675 IXMLDOMDocument2* iface,
1678 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1679 HRESULT hr = E_FAIL;
1680 IXMLDOMSchemaCollection *new_schema = NULL;
1682 FIXME("(%p): semi-stub\n", This);
1686 hr = IUnknown_QueryInterface(V_UNKNOWN(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1690 hr = IDispatch_QueryInterface(V_DISPATCH(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1699 WARN("Can't get schema from vt %x\n", V_VT(&var1));
1704 IXMLDOMSchemaCollection *old_schema = InterlockedExchangePointer((void**)&This->schema, new_schema);
1705 if(old_schema) IXMLDOMSchemaCollection_Release(old_schema);
1711 static HRESULT WINAPI domdoc_validate(
1712 IXMLDOMDocument2* iface,
1713 IXMLDOMParseError** err)
1719 static HRESULT WINAPI domdoc_setProperty(
1720 IXMLDOMDocument2* iface,
1724 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1726 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1732 V_VT(&varStr) = VT_EMPTY;
1733 if (V_VT(&var) != VT_BSTR)
1735 if (FAILED(hr = VariantChangeType(&varStr, &var, 0, VT_BSTR)))
1737 bstr = V_BSTR(&varStr);
1740 bstr = V_BSTR(&var);
1743 if (lstrcmpiW(bstr, SZ_VALUE_XPATH) == 0)
1744 This->bUseXPath = TRUE;
1745 else if (lstrcmpiW(bstr, SZ_VALUE_XSLPATTERN) == 0)
1746 This->bUseXPath = FALSE;
1750 VariantClear(&varStr);
1754 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1758 static HRESULT WINAPI domdoc_getProperty(
1759 IXMLDOMDocument2* iface,
1763 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1766 return E_INVALIDARG;
1767 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1769 V_VT(var) = VT_BSTR;
1770 if (This->bUseXPath)
1771 V_BSTR(var) = SysAllocString(SZ_VALUE_XPATH);
1773 V_BSTR(var) = SysAllocString(SZ_VALUE_XSLPATTERN);
1777 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1781 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl =
1783 domdoc_QueryInterface,
1786 domdoc_GetTypeInfoCount,
1788 domdoc_GetIDsOfNames,
1790 domdoc_get_nodeName,
1791 domdoc_get_nodeValue,
1792 domdoc_put_nodeValue,
1793 domdoc_get_nodeType,
1794 domdoc_get_parentNode,
1795 domdoc_get_childNodes,
1796 domdoc_get_firstChild,
1797 domdoc_get_lastChild,
1798 domdoc_get_previousSibling,
1799 domdoc_get_nextSibling,
1800 domdoc_get_attributes,
1801 domdoc_insertBefore,
1802 domdoc_replaceChild,
1805 domdoc_hasChildNodes,
1806 domdoc_get_ownerDocument,
1808 domdoc_get_nodeTypeString,
1811 domdoc_get_specified,
1812 domdoc_get_definition,
1813 domdoc_get_nodeTypedValue,
1814 domdoc_put_nodeTypedValue,
1815 domdoc_get_dataType,
1816 domdoc_put_dataType,
1818 domdoc_transformNode,
1820 domdoc_selectSingleNode,
1822 domdoc_get_namespaceURI,
1824 domdoc_get_baseName,
1825 domdoc_transformNodeToObject,
1827 domdoc_get_implementation,
1828 domdoc_get_documentElement,
1829 domdoc_documentElement,
1830 domdoc_createElement,
1831 domdoc_createDocumentFragment,
1832 domdoc_createTextNode,
1833 domdoc_createComment,
1834 domdoc_createCDATASection,
1835 domdoc_createProcessingInstruction,
1836 domdoc_createAttribute,
1837 domdoc_createEntityReference,
1838 domdoc_getElementsByTagName,
1842 domdoc_get_readyState,
1843 domdoc_get_parseError,
1850 domdoc_get_validateOnParse,
1851 domdoc_put_validateOnParse,
1852 domdoc_get_resolveExternals,
1853 domdoc_put_resolveExternals,
1854 domdoc_get_preserveWhiteSpace,
1855 domdoc_put_preserveWhiteSpace,
1856 domdoc_put_onReadyStateChange,
1857 domdoc_put_onDataAvailable,
1858 domdoc_put_onTransformNode,
1859 domdoc_get_namespaces,
1861 domdoc_putref_schemas,
1867 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1873 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1875 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
1877 return E_OUTOFMEMORY;
1879 doc->lpVtbl = &domdoc_vtbl;
1880 doc->lpvtblIPersistStream = &xmldoc_IPersistStream_VTable;
1883 doc->validating = 0;
1885 doc->preserving = 0;
1886 doc->bUseXPath = FALSE;
1891 xmldoc = xmlNewDoc(NULL);
1894 HeapFree(GetProcessHeap(), 0, doc);
1895 return E_OUTOFMEMORY;
1898 xmldoc->_private = 0;
1900 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
1904 HeapFree(GetProcessHeap(), 0, doc);
1908 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
1911 IUnknown_Release(doc->node_unk);
1912 HeapFree( GetProcessHeap(), 0, doc );
1915 /* The ref on doc->node is actually looped back into this object, so release it */
1916 IXMLDOMNode_Release(doc->node);
1918 *ppObj = &doc->lpVtbl;
1920 TRACE("returning iface %p\n", *ppObj);
1926 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1928 MESSAGE("This program tried to use a DOMDocument object, but\n"
1929 "libxml2 support was not present at compile time.\n");