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 FIXME("(%p,%p): stub!\n", iface, classid);
253 static HRESULT WINAPI xmldoc_IPersistStream_IsDirty(
254 IPersistStream *iface)
256 domdoc *This = impl_from_IPersistStream(iface);
258 FIXME("(%p->%p): stub!\n", iface, This);
263 static HRESULT WINAPI xmldoc_IPersistStream_Load(
264 IPersistStream *iface, LPSTREAM pStm)
266 domdoc *This = impl_from_IPersistStream(iface);
269 DWORD read, written, len;
272 xmlDocPtr xmldoc = NULL;
274 TRACE("(%p, %p)\n", iface, pStm);
279 hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
285 IStream_Read(pStm, buf, sizeof(buf), &read);
286 hr = IStream_Write(This->stream, buf, read, &written);
287 } while(SUCCEEDED(hr) && written != 0 && read != 0);
291 ERR("Failed to copy stream\n");
295 hr = GetHGlobalFromStream(This->stream, &hglobal);
299 len = GlobalSize(hglobal);
300 ptr = GlobalLock(hglobal);
302 xmldoc = parse_xml(ptr, len);
303 GlobalUnlock(hglobal);
307 ERR("Failed to parse xml\n");
311 attach_xmlnode( This->node, (xmlNodePtr)xmldoc );
316 static HRESULT WINAPI xmldoc_IPersistStream_Save(
317 IPersistStream *iface, LPSTREAM pStm, BOOL fClearDirty)
319 FIXME("(%p, %p, %d): stub!\n", iface, pStm, fClearDirty);
323 static HRESULT WINAPI xmldoc_IPersistStream_GetSizeMax(
324 IPersistStream *iface, ULARGE_INTEGER *pcbSize)
326 TRACE("(%p, %p): stub!\n", iface, pcbSize);
330 static const IPersistStreamVtbl xmldoc_IPersistStream_VTable =
332 xmldoc_IPersistStream_QueryInterface,
333 xmldoc_IPersistStream_AddRef,
334 xmldoc_IPersistStream_Release,
335 xmldoc_IPersistStream_GetClassID,
336 xmldoc_IPersistStream_IsDirty,
337 xmldoc_IPersistStream_Load,
338 xmldoc_IPersistStream_Save,
339 xmldoc_IPersistStream_GetSizeMax,
342 static HRESULT WINAPI domdoc_QueryInterface( IXMLDOMDocument2 *iface, REFIID riid, void** ppvObject )
344 domdoc *This = impl_from_IXMLDOMDocument2( iface );
346 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppvObject );
348 if ( IsEqualGUID( riid, &IID_IUnknown ) ||
349 IsEqualGUID( riid, &IID_IXMLDOMDocument ) ||
350 IsEqualGUID( riid, &IID_IXMLDOMDocument2 ) )
354 else if ( IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
355 IsEqualGUID( riid, &IID_IDispatch ) )
357 return IUnknown_QueryInterface(This->node_unk, riid, ppvObject);
359 else if (IsEqualGUID(&IID_IPersistStream, riid))
361 *ppvObject = (IPersistStream*)&(This->lpvtblIPersistStream);
365 FIXME("interface %s not implemented\n", debugstr_guid(riid));
366 return E_NOINTERFACE;
369 IXMLDOMDocument_AddRef( iface );
375 static ULONG WINAPI domdoc_AddRef(
376 IXMLDOMDocument2 *iface )
378 domdoc *This = impl_from_IXMLDOMDocument2( iface );
379 TRACE("%p\n", This );
380 return InterlockedIncrement( &This->ref );
384 static ULONG WINAPI domdoc_Release(
385 IXMLDOMDocument2 *iface )
387 domdoc *This = impl_from_IXMLDOMDocument2( iface );
390 TRACE("%p\n", This );
392 ref = InterlockedDecrement( &This->ref );
395 IUnknown_Release( This->node_unk );
396 if(This->schema) IXMLDOMSchemaCollection_Release( This->schema );
397 if (This->stream) IStream_Release(This->stream);
398 HeapFree( GetProcessHeap(), 0, This );
404 static HRESULT WINAPI domdoc_GetTypeInfoCount( IXMLDOMDocument2 *iface, UINT* pctinfo )
410 static HRESULT WINAPI domdoc_GetTypeInfo(
411 IXMLDOMDocument2 *iface,
412 UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo )
418 static HRESULT WINAPI domdoc_GetIDsOfNames(
419 IXMLDOMDocument2 *iface,
431 static HRESULT WINAPI domdoc_Invoke(
432 IXMLDOMDocument2 *iface,
437 DISPPARAMS* pDispParams,
439 EXCEPINFO* pExcepInfo,
447 static HRESULT WINAPI domdoc_get_nodeName(
448 IXMLDOMDocument2 *iface,
451 domdoc *This = impl_from_IXMLDOMDocument2( iface );
452 return IXMLDOMNode_get_nodeName( This->node, name );
456 static HRESULT WINAPI domdoc_get_nodeValue(
457 IXMLDOMDocument2 *iface,
460 domdoc *This = impl_from_IXMLDOMDocument2( iface );
461 return IXMLDOMNode_get_nodeValue( This->node, value );
465 static HRESULT WINAPI domdoc_put_nodeValue(
466 IXMLDOMDocument2 *iface,
469 domdoc *This = impl_from_IXMLDOMDocument2( iface );
470 return IXMLDOMNode_put_nodeValue( This->node, value );
474 static HRESULT WINAPI domdoc_get_nodeType(
475 IXMLDOMDocument2 *iface,
478 domdoc *This = impl_from_IXMLDOMDocument2( iface );
479 return IXMLDOMNode_get_nodeType( This->node, type );
483 static HRESULT WINAPI domdoc_get_parentNode(
484 IXMLDOMDocument2 *iface,
485 IXMLDOMNode** parent )
487 domdoc *This = impl_from_IXMLDOMDocument2( iface );
488 return IXMLDOMNode_get_parentNode( This->node, parent );
492 static HRESULT WINAPI domdoc_get_childNodes(
493 IXMLDOMDocument2 *iface,
494 IXMLDOMNodeList** childList )
496 domdoc *This = impl_from_IXMLDOMDocument2( iface );
497 return IXMLDOMNode_get_childNodes( This->node, childList );
501 static HRESULT WINAPI domdoc_get_firstChild(
502 IXMLDOMDocument2 *iface,
503 IXMLDOMNode** firstChild )
505 domdoc *This = impl_from_IXMLDOMDocument2( iface );
506 return IXMLDOMNode_get_firstChild( This->node, firstChild );
510 static HRESULT WINAPI domdoc_get_lastChild(
511 IXMLDOMDocument2 *iface,
512 IXMLDOMNode** lastChild )
514 domdoc *This = impl_from_IXMLDOMDocument2( iface );
515 return IXMLDOMNode_get_lastChild( This->node, lastChild );
519 static HRESULT WINAPI domdoc_get_previousSibling(
520 IXMLDOMDocument2 *iface,
521 IXMLDOMNode** previousSibling )
523 domdoc *This = impl_from_IXMLDOMDocument2( iface );
524 return IXMLDOMNode_get_previousSibling( This->node, previousSibling );
528 static HRESULT WINAPI domdoc_get_nextSibling(
529 IXMLDOMDocument2 *iface,
530 IXMLDOMNode** nextSibling )
532 domdoc *This = impl_from_IXMLDOMDocument2( iface );
533 return IXMLDOMNode_get_nextSibling( This->node, nextSibling );
537 static HRESULT WINAPI domdoc_get_attributes(
538 IXMLDOMDocument2 *iface,
539 IXMLDOMNamedNodeMap** attributeMap )
541 domdoc *This = impl_from_IXMLDOMDocument2( iface );
542 return IXMLDOMNode_get_attributes( This->node, attributeMap );
546 static HRESULT WINAPI domdoc_insertBefore(
547 IXMLDOMDocument2 *iface,
548 IXMLDOMNode* newChild,
550 IXMLDOMNode** outNewChild )
552 domdoc *This = impl_from_IXMLDOMDocument2( iface );
553 return IXMLDOMNode_insertBefore( This->node, newChild, refChild, outNewChild );
557 static HRESULT WINAPI domdoc_replaceChild(
558 IXMLDOMDocument2 *iface,
559 IXMLDOMNode* newChild,
560 IXMLDOMNode* oldChild,
561 IXMLDOMNode** outOldChild)
563 domdoc *This = impl_from_IXMLDOMDocument2( iface );
564 return IXMLDOMNode_replaceChild( This->node, newChild, oldChild, outOldChild );
568 static HRESULT WINAPI domdoc_removeChild(
569 IXMLDOMDocument2 *iface,
570 IXMLDOMNode* childNode,
571 IXMLDOMNode** oldChild)
573 domdoc *This = impl_from_IXMLDOMDocument2( iface );
574 return IXMLDOMNode_removeChild( This->node, childNode, oldChild );
578 static HRESULT WINAPI domdoc_appendChild(
579 IXMLDOMDocument2 *iface,
580 IXMLDOMNode* newChild,
581 IXMLDOMNode** outNewChild)
583 domdoc *This = impl_from_IXMLDOMDocument2( iface );
584 return IXMLDOMNode_appendChild( This->node, newChild, outNewChild );
588 static HRESULT WINAPI domdoc_hasChildNodes(
589 IXMLDOMDocument2 *iface,
590 VARIANT_BOOL* hasChild)
592 domdoc *This = impl_from_IXMLDOMDocument2( iface );
593 return IXMLDOMNode_hasChildNodes( This->node, hasChild );
597 static HRESULT WINAPI domdoc_get_ownerDocument(
598 IXMLDOMDocument2 *iface,
599 IXMLDOMDocument** DOMDocument)
601 domdoc *This = impl_from_IXMLDOMDocument2( iface );
602 return IXMLDOMNode_get_ownerDocument( This->node, DOMDocument );
606 static HRESULT WINAPI domdoc_cloneNode(
607 IXMLDOMDocument2 *iface,
609 IXMLDOMNode** cloneRoot)
611 domdoc *This = impl_from_IXMLDOMDocument2( iface );
612 return IXMLDOMNode_cloneNode( This->node, deep, cloneRoot );
616 static HRESULT WINAPI domdoc_get_nodeTypeString(
617 IXMLDOMDocument2 *iface,
620 domdoc *This = impl_from_IXMLDOMDocument2( iface );
621 return IXMLDOMNode_get_nodeTypeString( This->node, nodeType );
625 static HRESULT WINAPI domdoc_get_text(
626 IXMLDOMDocument2 *iface,
629 domdoc *This = impl_from_IXMLDOMDocument2( iface );
630 return IXMLDOMNode_get_text( This->node, text );
634 static HRESULT WINAPI domdoc_put_text(
635 IXMLDOMDocument2 *iface,
638 domdoc *This = impl_from_IXMLDOMDocument2( iface );
639 return IXMLDOMNode_put_text( This->node, text );
643 static HRESULT WINAPI domdoc_get_specified(
644 IXMLDOMDocument2 *iface,
645 VARIANT_BOOL* isSpecified )
647 domdoc *This = impl_from_IXMLDOMDocument2( iface );
648 return IXMLDOMNode_get_specified( This->node, isSpecified );
652 static HRESULT WINAPI domdoc_get_definition(
653 IXMLDOMDocument2 *iface,
654 IXMLDOMNode** definitionNode )
656 domdoc *This = impl_from_IXMLDOMDocument2( iface );
657 return IXMLDOMNode_get_definition( This->node, definitionNode );
661 static HRESULT WINAPI domdoc_get_nodeTypedValue(
662 IXMLDOMDocument2 *iface,
663 VARIANT* typedValue )
665 domdoc *This = impl_from_IXMLDOMDocument2( iface );
666 return IXMLDOMNode_get_nodeTypedValue( This->node, typedValue );
669 static HRESULT WINAPI domdoc_put_nodeTypedValue(
670 IXMLDOMDocument2 *iface,
673 domdoc *This = impl_from_IXMLDOMDocument2( iface );
674 return IXMLDOMNode_put_nodeTypedValue( This->node, typedValue );
678 static HRESULT WINAPI domdoc_get_dataType(
679 IXMLDOMDocument2 *iface,
680 VARIANT* dataTypeName )
682 domdoc *This = impl_from_IXMLDOMDocument2( iface );
683 return IXMLDOMNode_get_dataType( This->node, dataTypeName );
687 static HRESULT WINAPI domdoc_put_dataType(
688 IXMLDOMDocument2 *iface,
691 domdoc *This = impl_from_IXMLDOMDocument2( iface );
692 return IXMLDOMNode_put_dataType( This->node, dataTypeName );
696 static HRESULT WINAPI domdoc_get_xml(
697 IXMLDOMDocument2 *iface,
700 domdoc *This = impl_from_IXMLDOMDocument2( iface );
701 return IXMLDOMNode_get_xml( This->node, xmlString );
705 static HRESULT WINAPI domdoc_transformNode(
706 IXMLDOMDocument2 *iface,
707 IXMLDOMNode* styleSheet,
710 domdoc *This = impl_from_IXMLDOMDocument2( iface );
711 return IXMLDOMNode_transformNode( This->node, styleSheet, xmlString );
715 static HRESULT WINAPI domdoc_selectNodes(
716 IXMLDOMDocument2 *iface,
718 IXMLDOMNodeList** resultList )
720 domdoc *This = impl_from_IXMLDOMDocument2( iface );
721 return IXMLDOMNode_selectNodes( This->node, queryString, resultList );
725 static HRESULT WINAPI domdoc_selectSingleNode(
726 IXMLDOMDocument2 *iface,
728 IXMLDOMNode** resultNode )
730 domdoc *This = impl_from_IXMLDOMDocument2( iface );
731 return IXMLDOMNode_selectSingleNode( This->node, queryString, resultNode );
735 static HRESULT WINAPI domdoc_get_parsed(
736 IXMLDOMDocument2 *iface,
737 VARIANT_BOOL* isParsed )
739 domdoc *This = impl_from_IXMLDOMDocument2( iface );
740 return IXMLDOMNode_get_parsed( This->node, isParsed );
744 static HRESULT WINAPI domdoc_get_namespaceURI(
745 IXMLDOMDocument2 *iface,
748 domdoc *This = impl_from_IXMLDOMDocument2( iface );
749 return IXMLDOMNode_get_namespaceURI( This->node, namespaceURI );
753 static HRESULT WINAPI domdoc_get_prefix(
754 IXMLDOMDocument2 *iface,
757 domdoc *This = impl_from_IXMLDOMDocument2( iface );
758 return IXMLDOMNode_get_prefix( This->node, prefixString );
762 static HRESULT WINAPI domdoc_get_baseName(
763 IXMLDOMDocument2 *iface,
766 domdoc *This = impl_from_IXMLDOMDocument2( iface );
767 return IXMLDOMNode_get_baseName( This->node, nameString );
771 static HRESULT WINAPI domdoc_transformNodeToObject(
772 IXMLDOMDocument2 *iface,
773 IXMLDOMNode* stylesheet,
774 VARIANT outputObject)
776 domdoc *This = impl_from_IXMLDOMDocument2( iface );
777 return IXMLDOMNode_transformNodeToObject( This->node, stylesheet, outputObject );
781 static HRESULT WINAPI domdoc_get_doctype(
782 IXMLDOMDocument2 *iface,
783 IXMLDOMDocumentType** documentType )
790 static HRESULT WINAPI domdoc_get_implementation(
791 IXMLDOMDocument2 *iface,
792 IXMLDOMImplementation** impl )
798 static HRESULT WINAPI domdoc_get_documentElement(
799 IXMLDOMDocument2 *iface,
800 IXMLDOMElement** DOMElement )
802 domdoc *This = impl_from_IXMLDOMDocument2( iface );
803 xmlDocPtr xmldoc = NULL;
804 xmlNodePtr root = NULL;
805 IXMLDOMNode *element_node;
808 TRACE("%p %p\n", This, This->node);
815 xmldoc = get_doc( This );
817 root = xmlDocGetRootElement( xmldoc );
821 element_node = create_node( root );
822 if(!element_node) return S_FALSE;
824 hr = IXMLDOMNode_QueryInterface(element_node, &IID_IXMLDOMElement, (LPVOID*)DOMElement);
825 IXMLDOMNode_Release(element_node);
831 static HRESULT WINAPI domdoc_documentElement(
832 IXMLDOMDocument2 *iface,
833 IXMLDOMElement* DOMElement )
840 static HRESULT WINAPI domdoc_createElement(
841 IXMLDOMDocument2 *iface,
843 IXMLDOMElement** element )
846 domdoc *This = impl_from_IXMLDOMDocument2( iface );
851 TRACE("%p->(%s,%p)\n", iface, debugstr_w(tagname), element);
853 xml_name = xmlChar_from_wchar((WCHAR*)tagname);
854 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
856 TRACE("created xmlptr %p\n", xmlnode);
857 elem_unk = create_element(xmlnode, NULL);
858 HeapFree(GetProcessHeap(), 0, xml_name);
860 hr = IUnknown_QueryInterface(elem_unk, &IID_IXMLDOMElement, (void **)element);
861 IUnknown_Release(elem_unk);
862 TRACE("returning %p\n", *element);
867 static HRESULT WINAPI domdoc_createDocumentFragment(
868 IXMLDOMDocument2 *iface,
869 IXMLDOMDocumentFragment** docFrag )
876 static HRESULT WINAPI domdoc_createTextNode(
877 IXMLDOMDocument2 *iface,
881 domdoc *This = impl_from_IXMLDOMDocument2( iface );
883 xmlChar *xml_content;
885 TRACE("%p->(%s %p)\n", iface, debugstr_w(data), text);
892 xml_content = xmlChar_from_wchar((WCHAR*)data);
893 xmlnode = xmlNewText(xml_content);
894 HeapFree(GetProcessHeap(), 0, xml_content);
899 xmlnode->doc = get_doc( This );
901 *text = (IXMLDOMText*)create_text(xmlnode);
907 static HRESULT WINAPI domdoc_createComment(
908 IXMLDOMDocument2 *iface,
910 IXMLDOMComment** comment )
917 static HRESULT WINAPI domdoc_createCDATASection(
918 IXMLDOMDocument2 *iface,
920 IXMLDOMCDATASection** cdata )
927 static HRESULT WINAPI domdoc_createProcessingInstruction(
928 IXMLDOMDocument2 *iface,
931 IXMLDOMProcessingInstruction** pi )
933 #ifdef HAVE_XMLNEWDOCPI
935 domdoc *This = impl_from_IXMLDOMDocument2( iface );
936 xmlChar *xml_target, *xml_content;
938 TRACE("%p->(%s %s %p)\n", iface, debugstr_w(target), debugstr_w(data), pi);
940 xml_target = xmlChar_from_wchar((WCHAR*)target);
941 xml_content = xmlChar_from_wchar((WCHAR*)data);
943 xmlnode = xmlNewDocPI(get_doc(This), xml_target, xml_content);
944 TRACE("created xmlptr %p\n", xmlnode);
945 *pi = (IXMLDOMProcessingInstruction*)create_pi(xmlnode);
947 HeapFree(GetProcessHeap(), 0, xml_content);
948 HeapFree(GetProcessHeap(), 0, xml_target);
952 FIXME("Libxml 2.6.15 or greater required.\n");
958 static HRESULT WINAPI domdoc_createAttribute(
959 IXMLDOMDocument2 *iface,
961 IXMLDOMAttribute** attribute )
968 static HRESULT WINAPI domdoc_createEntityReference(
969 IXMLDOMDocument2 *iface,
971 IXMLDOMEntityReference** entityRef )
978 static HRESULT WINAPI domdoc_getElementsByTagName(
979 IXMLDOMDocument2 *iface,
981 IXMLDOMNodeList** resultList )
983 domdoc *This = impl_from_IXMLDOMDocument2( iface );
986 TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
988 szPattern = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*(2+lstrlenW(tagName)+1));
989 szPattern[0] = szPattern[1] = '/';
990 lstrcpyW(szPattern + 2, tagName);
992 hr = queryresult_create((xmlNodePtr)get_doc(This), szPattern, resultList);
993 HeapFree(GetProcessHeap(), 0, szPattern);
998 static DOMNodeType get_node_type(VARIANT Type)
1000 if(V_VT(&Type) == VT_I4)
1003 FIXME("Unsupported variant type %x\n", V_VT(&Type));
1007 static HRESULT WINAPI domdoc_createNode(
1008 IXMLDOMDocument2 *iface,
1012 IXMLDOMNode** node )
1014 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1015 DOMNodeType node_type;
1016 xmlNodePtr xmlnode = NULL;
1019 TRACE("(%p)->(type,%s,%s,%p)\n", This, debugstr_w(name), debugstr_w(namespaceURI), node);
1021 node_type = get_node_type(Type);
1022 TRACE("node_type %d\n", node_type);
1024 xml_name = xmlChar_from_wchar((WCHAR*)name);
1029 xmlnode = xmlNewDocNode(get_doc(This), NULL, xml_name, NULL);
1030 *node = create_node(xmlnode);
1031 TRACE("created %p\n", xmlnode);
1035 FIXME("unhandled node type %d\n", node_type);
1039 HeapFree(GetProcessHeap(), 0, xml_name);
1041 if(xmlnode && *node)
1047 static HRESULT WINAPI domdoc_nodeFromID(
1048 IXMLDOMDocument2 *iface,
1050 IXMLDOMNode** node )
1056 static xmlDocPtr doparse( char *ptr, int len )
1058 #ifdef HAVE_XMLREADMEMORY
1060 * use xmlReadMemory if possible so we can suppress
1061 * writing errors to stderr
1063 return xmlReadMemory( ptr, len, NULL, NULL,
1064 XML_PARSE_NOERROR | XML_PARSE_NOWARNING | XML_PARSE_NOBLANKS );
1066 return xmlParseMemory( ptr, len );
1070 static xmlDocPtr doread( LPWSTR filename )
1072 xmlDocPtr xmldoc = NULL;
1075 IStream *stream, *memstream;
1076 WCHAR url[INTERNET_MAX_URL_LENGTH];
1078 DWORD read, written;
1080 TRACE("%s\n", debugstr_w( filename ));
1082 if(!PathIsURLW(filename))
1084 WCHAR fullpath[MAX_PATH];
1085 DWORD needed = sizeof(url)/sizeof(WCHAR);
1087 if(!PathSearchAndQualifyW(filename, fullpath, sizeof(fullpath)/sizeof(WCHAR)))
1089 WARN("can't find path\n");
1093 if(FAILED(UrlCreateFromPathW(fullpath, url, &needed, 0)))
1095 ERR("can't create url from path\n");
1101 hr = CreateBindCtx(0, &pbc);
1104 hr = RegisterBindStatusCallback(pbc, (IBindStatusCallback*)&domdoc_bsc.lpVtbl, NULL, 0);
1108 hr = CreateURLMoniker(NULL, filename, &moniker);
1111 hr = IMoniker_BindToStorage(moniker, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
1112 IMoniker_Release(moniker);
1115 IBindCtx_Release(pbc);
1120 hr = CreateStreamOnHGlobal(NULL, TRUE, &memstream);
1123 IStream_Release(stream);
1129 IStream_Read(stream, buf, sizeof(buf), &read);
1130 hr = IStream_Write(memstream, buf, read, &written);
1131 } while(SUCCEEDED(hr) && written != 0 && read != 0);
1136 hr = GetHGlobalFromStream(memstream, &hglobal);
1139 DWORD len = GlobalSize(hglobal);
1140 char *ptr = GlobalLock(hglobal);
1142 xmldoc = doparse( ptr, len );
1143 GlobalUnlock(hglobal);
1146 IStream_Release(memstream);
1147 IStream_Release(stream);
1151 static HRESULT WINAPI domdoc_load(
1152 IXMLDOMDocument2 *iface,
1154 VARIANT_BOOL* isSuccessful )
1156 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1157 LPWSTR filename = NULL;
1158 xmlDocPtr xmldoc = NULL;
1159 HRESULT hr = S_FALSE;
1160 IXMLDOMDocument2 *pNewDoc = NULL;
1161 IStream *pStream = NULL;
1163 TRACE("type %d\n", V_VT(&xmlSource) );
1165 *isSuccessful = VARIANT_FALSE;
1167 assert( This->node );
1169 attach_xmlnode(This->node, NULL);
1171 switch( V_VT(&xmlSource) )
1174 filename = V_BSTR(&xmlSource);
1177 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IXMLDOMDocument2, (void**)&pNewDoc);
1182 domdoc *newDoc = impl_from_IXMLDOMDocument2( pNewDoc );
1183 xmldoc = xmlCopyDoc(get_doc(newDoc), 1);
1184 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1186 *isSuccessful = VARIANT_TRUE;
1191 hr = IUnknown_QueryInterface(V_UNKNOWN(&xmlSource), &IID_IStream, (void**)&pStream);
1194 IPersistStream *pDocStream;
1195 hr = IUnknown_QueryInterface(iface, &IID_IPersistStream, (void**)&pDocStream);
1198 hr = xmldoc_IPersistStream_Load(pDocStream, pStream);
1199 IStream_Release(pStream);
1202 *isSuccessful = VARIANT_TRUE;
1204 TRACE("Using ID_IStream to load Document\n");
1209 ERR("xmldoc_IPersistStream_Load failed (%d)\n", hr);
1214 ERR("QueryInterface IID_IPersistStream failed (%d)\n", hr);
1219 /* ISequentialStream */
1220 FIXME("Unknown type not supported (%d) (%p)(%p)\n", hr, pNewDoc, V_UNKNOWN(&xmlSource)->lpVtbl);
1224 FIXME("VT type not supported (%d)\n", V_VT(&xmlSource));
1227 TRACE("filename (%s)\n", debugstr_w(filename));
1231 xmldoc = doread( filename );
1234 This->error = E_FAIL;
1237 hr = This->error = S_OK;
1238 *isSuccessful = VARIANT_TRUE;
1243 xmldoc = xmlNewDoc(NULL);
1245 xmldoc->_private = 0;
1246 attach_xmlnode(This->node, (xmlNodePtr) xmldoc);
1248 TRACE("ret (%d)\n", hr);
1254 static HRESULT WINAPI domdoc_get_readyState(
1255 IXMLDOMDocument2 *iface,
1263 static HRESULT WINAPI domdoc_get_parseError(
1264 IXMLDOMDocument2 *iface,
1265 IXMLDOMParseError** errorObj )
1267 BSTR error_string = NULL;
1268 static const WCHAR err[] = {'e','r','r','o','r',0};
1269 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1271 FIXME("(%p)->(%p): creating a dummy parseError\n", iface, errorObj);
1274 error_string = SysAllocString(err);
1276 *errorObj = create_parseError(This->error, NULL, error_string, NULL, 0, 0, 0);
1277 if(!*errorObj) return E_OUTOFMEMORY;
1282 static HRESULT WINAPI domdoc_get_url(
1283 IXMLDOMDocument2 *iface,
1291 static HRESULT WINAPI domdoc_get_async(
1292 IXMLDOMDocument2 *iface,
1293 VARIANT_BOOL* isAsync )
1295 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1297 TRACE("%p <- %d\n", isAsync, This->async);
1298 *isAsync = This->async;
1303 static HRESULT WINAPI domdoc_put_async(
1304 IXMLDOMDocument2 *iface,
1305 VARIANT_BOOL isAsync )
1307 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1309 TRACE("%d\n", isAsync);
1310 This->async = isAsync;
1315 static HRESULT WINAPI domdoc_abort(
1316 IXMLDOMDocument2 *iface )
1323 static BOOL bstr_to_utf8( BSTR bstr, char **pstr, int *plen )
1325 UINT len, blen = SysStringLen( bstr );
1328 len = WideCharToMultiByte( CP_UTF8, 0, bstr, blen, NULL, 0, NULL, NULL );
1329 str = HeapAlloc( GetProcessHeap(), 0, len );
1332 WideCharToMultiByte( CP_UTF8, 0, bstr, blen, str, len, NULL, NULL );
1338 static HRESULT WINAPI domdoc_loadXML(
1339 IXMLDOMDocument2 *iface,
1341 VARIANT_BOOL* isSuccessful )
1343 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1344 xmlDocPtr xmldoc = NULL;
1347 HRESULT hr = S_FALSE;
1349 TRACE("%p %s %p\n", This, debugstr_w( bstrXML ), isSuccessful );
1351 assert ( This->node );
1353 attach_xmlnode( This->node, NULL );
1357 *isSuccessful = VARIANT_FALSE;
1359 if ( bstrXML && bstr_to_utf8( bstrXML, &str, &len ) )
1361 xmldoc = doparse( str, len );
1362 HeapFree( GetProcessHeap(), 0, str );
1364 This->error = E_FAIL;
1367 hr = This->error = S_OK;
1368 *isSuccessful = VARIANT_TRUE;
1373 xmldoc = xmlNewDoc(NULL);
1375 xmldoc->_private = 0;
1376 attach_xmlnode( This->node, (xmlNodePtr) xmldoc );
1382 static HRESULT WINAPI domdoc_save(
1383 IXMLDOMDocument2 *iface,
1384 VARIANT destination )
1386 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1393 TRACE("(%p)->(var(vt %x, %s))\n", This, V_VT(&destination),
1394 V_VT(&destination) == VT_BSTR ? debugstr_w(V_BSTR(&destination)) : NULL);
1396 if(V_VT(&destination) != VT_BSTR)
1398 FIXME("Unhandled vt %x\n", V_VT(&destination));
1402 handle = CreateFileW( V_BSTR(&destination), GENERIC_WRITE, 0,
1403 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1404 if( handle == INVALID_HANDLE_VALUE )
1406 WARN("failed to create file\n");
1410 xmlDocDumpMemory(get_doc(This), &mem, &size);
1411 if(!WriteFile(handle, mem, (DWORD)size, &written, NULL) || written != (DWORD)size)
1413 WARN("write error\n");
1418 CloseHandle(handle);
1422 static HRESULT WINAPI domdoc_get_validateOnParse(
1423 IXMLDOMDocument2 *iface,
1424 VARIANT_BOOL* isValidating )
1426 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1428 TRACE("%p <- %d\n", isValidating, This->validating);
1429 *isValidating = This->validating;
1434 static HRESULT WINAPI domdoc_put_validateOnParse(
1435 IXMLDOMDocument2 *iface,
1436 VARIANT_BOOL isValidating )
1438 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1440 TRACE("%d\n", isValidating);
1441 This->validating = isValidating;
1446 static HRESULT WINAPI domdoc_get_resolveExternals(
1447 IXMLDOMDocument2 *iface,
1448 VARIANT_BOOL* isResolving )
1450 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1452 TRACE("%p <- %d\n", isResolving, This->resolving);
1453 *isResolving = This->resolving;
1458 static HRESULT WINAPI domdoc_put_resolveExternals(
1459 IXMLDOMDocument2 *iface,
1460 VARIANT_BOOL isResolving )
1462 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1464 TRACE("%d\n", isResolving);
1465 This->resolving = isResolving;
1470 static HRESULT WINAPI domdoc_get_preserveWhiteSpace(
1471 IXMLDOMDocument2 *iface,
1472 VARIANT_BOOL* isPreserving )
1474 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1476 TRACE("%p <- %d\n", isPreserving, This->preserving);
1477 *isPreserving = This->preserving;
1482 static HRESULT WINAPI domdoc_put_preserveWhiteSpace(
1483 IXMLDOMDocument2 *iface,
1484 VARIANT_BOOL isPreserving )
1486 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1488 TRACE("%d\n", isPreserving);
1489 This->preserving = isPreserving;
1494 static HRESULT WINAPI domdoc_put_onReadyStateChange(
1495 IXMLDOMDocument2 *iface,
1496 VARIANT readyStateChangeSink )
1503 static HRESULT WINAPI domdoc_put_onDataAvailable(
1504 IXMLDOMDocument2 *iface,
1505 VARIANT onDataAvailableSink )
1511 static HRESULT WINAPI domdoc_put_onTransformNode(
1512 IXMLDOMDocument2 *iface,
1513 VARIANT onTransformNodeSink )
1519 static HRESULT WINAPI domdoc_get_namespaces(
1520 IXMLDOMDocument2* iface,
1521 IXMLDOMSchemaCollection** schemaCollection )
1527 static HRESULT WINAPI domdoc_get_schemas(
1528 IXMLDOMDocument2* iface,
1531 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1532 HRESULT hr = S_FALSE;
1533 IXMLDOMSchemaCollection *cur_schema = This->schema;
1535 TRACE("(%p)->(%p)\n", This, var1);
1537 VariantInit(var1); /* Test shows we don't call VariantClear here */
1538 V_VT(var1) = VT_NULL;
1542 hr = IXMLDOMSchemaCollection_QueryInterface(cur_schema, &IID_IDispatch, (void**)&V_DISPATCH(var1));
1544 V_VT(var1) = VT_DISPATCH;
1549 static HRESULT WINAPI domdoc_putref_schemas(
1550 IXMLDOMDocument2* iface,
1553 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1554 HRESULT hr = E_FAIL;
1555 IXMLDOMSchemaCollection *new_schema = NULL;
1557 FIXME("(%p): semi-stub\n", This);
1561 hr = IUnknown_QueryInterface(V_UNKNOWN(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1565 hr = IDispatch_QueryInterface(V_DISPATCH(&var1), &IID_IXMLDOMSchemaCollection, (void**)&new_schema);
1574 WARN("Can't get schema from vt %x\n", V_VT(&var1));
1579 IXMLDOMSchemaCollection *old_schema = InterlockedExchangePointer((void**)&This->schema, new_schema);
1580 if(old_schema) IXMLDOMSchemaCollection_Release(old_schema);
1586 static HRESULT WINAPI domdoc_validate(
1587 IXMLDOMDocument2* iface,
1588 IXMLDOMParseError** err)
1594 static HRESULT WINAPI domdoc_setProperty(
1595 IXMLDOMDocument2* iface,
1599 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1601 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1607 V_VT(&varStr) = VT_EMPTY;
1608 if (V_VT(&var) != VT_BSTR)
1610 if (FAILED(hr = VariantChangeType(&varStr, &var, 0, VT_BSTR)))
1612 bstr = V_BSTR(&varStr);
1615 bstr = V_BSTR(&var);
1618 if (lstrcmpiW(bstr, SZ_VALUE_XPATH) == 0)
1619 This->bUseXPath = TRUE;
1620 else if (lstrcmpiW(bstr, SZ_VALUE_XSLPATTERN) == 0)
1621 This->bUseXPath = FALSE;
1625 VariantClear(&varStr);
1629 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1633 static HRESULT WINAPI domdoc_getProperty(
1634 IXMLDOMDocument2* iface,
1638 domdoc *This = impl_from_IXMLDOMDocument2( iface );
1641 return E_INVALIDARG;
1642 if (lstrcmpiW(p, SZ_PROPERTY_SELECTION_LANGUAGE) == 0)
1644 V_VT(var) = VT_BSTR;
1645 if (This->bUseXPath)
1646 V_BSTR(var) = SysAllocString(SZ_VALUE_XPATH);
1648 V_BSTR(var) = SysAllocString(SZ_VALUE_XSLPATTERN);
1652 FIXME("Unknown property %s\n", wine_dbgstr_w(p));
1656 static const struct IXMLDOMDocument2Vtbl domdoc_vtbl =
1658 domdoc_QueryInterface,
1661 domdoc_GetTypeInfoCount,
1663 domdoc_GetIDsOfNames,
1665 domdoc_get_nodeName,
1666 domdoc_get_nodeValue,
1667 domdoc_put_nodeValue,
1668 domdoc_get_nodeType,
1669 domdoc_get_parentNode,
1670 domdoc_get_childNodes,
1671 domdoc_get_firstChild,
1672 domdoc_get_lastChild,
1673 domdoc_get_previousSibling,
1674 domdoc_get_nextSibling,
1675 domdoc_get_attributes,
1676 domdoc_insertBefore,
1677 domdoc_replaceChild,
1680 domdoc_hasChildNodes,
1681 domdoc_get_ownerDocument,
1683 domdoc_get_nodeTypeString,
1686 domdoc_get_specified,
1687 domdoc_get_definition,
1688 domdoc_get_nodeTypedValue,
1689 domdoc_put_nodeTypedValue,
1690 domdoc_get_dataType,
1691 domdoc_put_dataType,
1693 domdoc_transformNode,
1695 domdoc_selectSingleNode,
1697 domdoc_get_namespaceURI,
1699 domdoc_get_baseName,
1700 domdoc_transformNodeToObject,
1702 domdoc_get_implementation,
1703 domdoc_get_documentElement,
1704 domdoc_documentElement,
1705 domdoc_createElement,
1706 domdoc_createDocumentFragment,
1707 domdoc_createTextNode,
1708 domdoc_createComment,
1709 domdoc_createCDATASection,
1710 domdoc_createProcessingInstruction,
1711 domdoc_createAttribute,
1712 domdoc_createEntityReference,
1713 domdoc_getElementsByTagName,
1717 domdoc_get_readyState,
1718 domdoc_get_parseError,
1725 domdoc_get_validateOnParse,
1726 domdoc_put_validateOnParse,
1727 domdoc_get_resolveExternals,
1728 domdoc_put_resolveExternals,
1729 domdoc_get_preserveWhiteSpace,
1730 domdoc_put_preserveWhiteSpace,
1731 domdoc_put_onReadyStateChange,
1732 domdoc_put_onDataAvailable,
1733 domdoc_put_onTransformNode,
1734 domdoc_get_namespaces,
1736 domdoc_putref_schemas,
1742 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1748 TRACE("(%p,%p)\n", pUnkOuter, ppObj);
1750 doc = HeapAlloc( GetProcessHeap(), 0, sizeof (*doc) );
1752 return E_OUTOFMEMORY;
1754 doc->lpVtbl = &domdoc_vtbl;
1755 doc->lpvtblIPersistStream = &xmldoc_IPersistStream_VTable;
1758 doc->validating = 0;
1760 doc->preserving = 0;
1761 doc->bUseXPath = FALSE;
1766 xmldoc = xmlNewDoc(NULL);
1769 HeapFree(GetProcessHeap(), 0, doc);
1770 return E_OUTOFMEMORY;
1773 xmldoc->_private = 0;
1775 doc->node_unk = create_basic_node( (xmlNodePtr)xmldoc, (IUnknown*)&doc->lpVtbl );
1779 HeapFree(GetProcessHeap(), 0, doc);
1783 hr = IUnknown_QueryInterface(doc->node_unk, &IID_IXMLDOMNode, (LPVOID*)&doc->node);
1786 IUnknown_Release(doc->node_unk);
1787 HeapFree( GetProcessHeap(), 0, doc );
1790 /* The ref on doc->node is actually looped back into this object, so release it */
1791 IXMLDOMNode_Release(doc->node);
1793 *ppObj = &doc->lpVtbl;
1795 TRACE("returning iface %p\n", *ppObj);
1801 HRESULT DOMDocument_create(IUnknown *pUnkOuter, LPVOID *ppObj)
1803 MESSAGE("This program tried to use a DOMDocument object, but\n"
1804 "libxml2 support was not present at compile time.\n");