2007-05-24 20:12:19 +02:00
|
|
|
/*
|
|
|
|
* XML Element implementation
|
|
|
|
*
|
|
|
|
* Copyright 2007 James Hawkins
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-02-24 13:11:53 +01:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
# include <libxml/parser.h>
|
|
|
|
# include <libxml/xmlerror.h>
|
|
|
|
#endif
|
|
|
|
|
2007-05-24 20:12:19 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2010-08-29 23:31:49 +02:00
|
|
|
#include "msxml6.h"
|
2007-05-24 20:12:19 +02:00
|
|
|
#include "ocidl.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "msxml_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
|
2008-12-18 20:58:39 +01:00
|
|
|
static HRESULT XMLElementCollection_create( IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj );
|
|
|
|
|
2007-05-24 20:12:19 +02:00
|
|
|
/**********************************************************************
|
|
|
|
* IXMLElement
|
|
|
|
*/
|
|
|
|
typedef struct _xmlelem
|
|
|
|
{
|
2010-12-23 02:03:06 +01:00
|
|
|
IXMLElement IXMLElement_iface;
|
2007-05-24 20:12:19 +02:00
|
|
|
LONG ref;
|
|
|
|
xmlNodePtr node;
|
2010-01-14 22:18:32 +01:00
|
|
|
BOOL own;
|
2007-05-24 20:12:19 +02:00
|
|
|
} xmlelem;
|
|
|
|
|
|
|
|
static inline xmlelem *impl_from_IXMLElement(IXMLElement *iface)
|
|
|
|
{
|
2010-12-23 02:03:06 +01:00
|
|
|
return CONTAINING_RECORD(iface, xmlelem, IXMLElement_iface);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_QueryInterface(IXMLElement *iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IXMLElement))
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
2011-02-28 20:28:53 +01:00
|
|
|
*ppvObject = NULL;
|
2007-05-24 20:12:19 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXMLElement_AddRef(iface);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlelem_AddRef(IXMLElement *iface)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlelem_Release(IXMLElement *iface)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2010-01-14 22:18:32 +01:00
|
|
|
if (This->own) xmlFreeNode(This->node);
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free(This);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_GetTypeInfoCount(IXMLElement *iface, UINT* pctinfo)
|
|
|
|
{
|
2008-02-19 02:40:29 +01:00
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pctinfo);
|
|
|
|
|
|
|
|
*pctinfo = 1;
|
|
|
|
|
|
|
|
return S_OK;
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_GetTypeInfo(IXMLElement *iface, UINT iTInfo,
|
|
|
|
LCID lcid, ITypeInfo** ppTInfo)
|
|
|
|
{
|
2008-02-19 02:40:29 +01:00
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%u %u %p)\n", This, iTInfo, lcid, ppTInfo);
|
|
|
|
|
|
|
|
hr = get_typeinfo(IXMLElement_tid, ppTInfo);
|
|
|
|
|
|
|
|
return hr;
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_GetIDsOfNames(IXMLElement *iface, REFIID riid,
|
|
|
|
LPOLESTR* rgszNames, UINT cNames,
|
|
|
|
LCID lcid, DISPID* rgDispId)
|
|
|
|
{
|
2008-02-19 02:40:29 +01:00
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %u %u %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
|
|
|
|
lcid, rgDispId);
|
|
|
|
|
|
|
|
if(!rgszNames || cNames == 0 || !rgDispId)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
hr = get_typeinfo(IXMLElement_tid, &typeinfo);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = ITypeInfo_GetIDsOfNames(typeinfo, rgszNames, cNames, rgDispId);
|
|
|
|
ITypeInfo_Release(typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_Invoke(IXMLElement *iface, DISPID dispIdMember,
|
|
|
|
REFIID riid, LCID lcid, WORD wFlags,
|
|
|
|
DISPPARAMS* pDispParams, VARIANT* pVarResult,
|
|
|
|
EXCEPINFO* pExcepInfo, UINT* puArgErr)
|
|
|
|
{
|
2008-02-19 02:40:29 +01:00
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
ITypeInfo *typeinfo;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d %s %d %d %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
|
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
|
|
|
|
|
|
|
hr = get_typeinfo(IXMLElement_tid, &typeinfo);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
2010-12-23 02:03:06 +01:00
|
|
|
hr = ITypeInfo_Invoke(typeinfo, &This->IXMLElement_iface, dispIdMember, wFlags, pDispParams,
|
2008-02-19 02:40:29 +01:00
|
|
|
pVarResult, pExcepInfo, puArgErr);
|
|
|
|
ITypeInfo_Release(typeinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_get_tagName(IXMLElement *iface, BSTR *p)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2010-01-10 20:42:46 +01:00
|
|
|
*p = bstr_from_xmlChar(This->node->name);
|
|
|
|
CharUpperBuffW(*p, SysStringLen(*p));
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
TRACE("returning %s\n", debugstr_w(*p));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_put_tagName(IXMLElement *iface, BSTR p)
|
|
|
|
{
|
2011-02-22 00:04:02 +01:00
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
|
|
|
|
FIXME("(%p)->(%s): stub\n", This, debugstr_w(p));
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_get_parent(IXMLElement *iface, IXMLElement **parent)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, parent);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*parent = NULL;
|
|
|
|
|
|
|
|
if (!This->node->parent)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2010-01-14 22:18:32 +01:00
|
|
|
return XMLElement_create((IUnknown *)iface, This->node->parent, (LPVOID *)parent, FALSE);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_setAttribute(IXMLElement *iface, BSTR strPropertyName,
|
|
|
|
VARIANT PropertyValue)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
xmlChar *name, *value;
|
|
|
|
xmlAttrPtr attr;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s %s)\n", This, debugstr_w(strPropertyName), debugstr_variant(&PropertyValue));
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!strPropertyName || V_VT(&PropertyValue) != VT_BSTR)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
name = xmlChar_from_wchar(strPropertyName);
|
|
|
|
value = xmlChar_from_wchar(V_BSTR(&PropertyValue));
|
|
|
|
attr = xmlSetProp(This->node, name, value);
|
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free(name);
|
|
|
|
heap_free(value);
|
2007-05-24 20:12:19 +02:00
|
|
|
return (attr) ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-20 23:51:20 +02:00
|
|
|
static HRESULT WINAPI xmlelem_getAttribute(IXMLElement *iface, BSTR name,
|
|
|
|
VARIANT *value)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
2010-06-20 23:51:20 +02:00
|
|
|
static const WCHAR xmllangW[] = { 'x','m','l',':','l','a','n','g',0 };
|
2007-05-24 20:12:19 +02:00
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
2010-06-20 23:51:20 +02:00
|
|
|
xmlChar *val = NULL;
|
2007-05-24 20:12:19 +02:00
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_w(name), value);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
2010-06-20 23:51:20 +02:00
|
|
|
if (!value)
|
2007-05-24 20:12:19 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2010-06-20 23:51:20 +02:00
|
|
|
VariantInit(value);
|
|
|
|
V_BSTR(value) = NULL;
|
2007-05-24 20:12:19 +02:00
|
|
|
|
2010-06-20 23:51:20 +02:00
|
|
|
if (!name)
|
2007-05-24 20:12:19 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2010-06-20 23:51:20 +02:00
|
|
|
/* case for xml:lang attribute */
|
|
|
|
if (!lstrcmpiW(name, xmllangW))
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
2010-06-20 23:51:20 +02:00
|
|
|
xmlNsPtr ns;
|
|
|
|
ns = xmlSearchNs(This->node->doc, This->node, (xmlChar*)"xml");
|
|
|
|
val = xmlGetNsProp(This->node, (xmlChar*)"lang", ns->href);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlAttrPtr attr;
|
|
|
|
xmlChar *xml_name;
|
|
|
|
|
|
|
|
xml_name = xmlChar_from_wchar(name);
|
|
|
|
attr = This->node->properties;
|
|
|
|
while (attr)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
2010-06-20 23:51:20 +02:00
|
|
|
BSTR attr_name;
|
|
|
|
|
|
|
|
attr_name = bstr_from_xmlChar(attr->name);
|
|
|
|
if (!lstrcmpiW(name, attr_name))
|
|
|
|
{
|
|
|
|
val = xmlNodeListGetString(attr->doc, attr->children, 1);
|
|
|
|
SysFreeString(attr_name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr = attr->next;
|
|
|
|
SysFreeString(attr_name);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
2010-06-20 23:51:20 +02:00
|
|
|
heap_free(xml_name);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (val)
|
|
|
|
{
|
2010-06-20 23:51:20 +02:00
|
|
|
V_VT(value) = VT_BSTR;
|
|
|
|
V_BSTR(value) = bstr_from_xmlChar(val);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
xmlFree(val);
|
2010-06-20 23:51:20 +02:00
|
|
|
TRACE("returning %s\n", debugstr_w(V_BSTR(value)));
|
2007-05-24 20:12:19 +02:00
|
|
|
return (val) ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_removeAttribute(IXMLElement *iface, BSTR strPropertyName)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
xmlChar *name;
|
|
|
|
xmlAttrPtr attr;
|
|
|
|
int res;
|
|
|
|
HRESULT hr = S_FALSE;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(strPropertyName));
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!strPropertyName)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
name = xmlChar_from_wchar(strPropertyName);
|
|
|
|
attr = xmlHasProp(This->node, name);
|
|
|
|
if (!attr)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
res = xmlRemoveProp(attr);
|
|
|
|
|
|
|
|
if (res == 0)
|
|
|
|
hr = S_OK;
|
|
|
|
|
|
|
|
done:
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free(name);
|
2007-05-24 20:12:19 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_get_children(IXMLElement *iface, IXMLElementCollection **p)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2010-01-14 22:16:03 +01:00
|
|
|
return XMLElementCollection_create((IUnknown *)iface, This->node, (LPVOID *)p);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
2009-03-09 23:28:53 +01:00
|
|
|
static LONG type_libxml_to_msxml(xmlElementType type)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case XML_ELEMENT_NODE:
|
|
|
|
return XMLELEMTYPE_ELEMENT;
|
|
|
|
case XML_TEXT_NODE:
|
|
|
|
return XMLELEMTYPE_TEXT;
|
|
|
|
case XML_COMMENT_NODE:
|
|
|
|
return XMLELEMTYPE_COMMENT;
|
|
|
|
case XML_DOCUMENT_NODE:
|
|
|
|
return XMLELEMTYPE_DOCUMENT;
|
|
|
|
case XML_DTD_NODE:
|
|
|
|
return XMLELEMTYPE_DTD;
|
|
|
|
case XML_PI_NODE:
|
|
|
|
return XMLELEMTYPE_PI;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return XMLELEMTYPE_OTHER;
|
|
|
|
}
|
|
|
|
|
2009-03-09 23:28:42 +01:00
|
|
|
static HRESULT WINAPI xmlelem_get_type(IXMLElement *iface, LONG *p)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*p = type_libxml_to_msxml(This->node->type);
|
2009-03-09 23:28:42 +01:00
|
|
|
TRACE("returning %d\n", *p);
|
2007-05-24 20:12:19 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_get_text(IXMLElement *iface, BSTR *p)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
xmlChar *content;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
content = xmlNodeGetContent(This->node);
|
|
|
|
*p = bstr_from_xmlChar(content);
|
|
|
|
TRACE("returning %s\n", debugstr_w(*p));
|
2007-11-07 02:39:11 +01:00
|
|
|
|
|
|
|
xmlFree(content);
|
2007-05-24 20:12:19 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_put_text(IXMLElement *iface, BSTR p)
|
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
xmlChar *content;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(p));
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
/* FIXME: test which types can be used */
|
|
|
|
if (This->node->type == XML_ELEMENT_NODE)
|
|
|
|
return E_NOTIMPL;
|
|
|
|
|
|
|
|
content = xmlChar_from_wchar(p);
|
|
|
|
xmlNodeSetContent(This->node, content);
|
2007-11-03 07:24:34 +01:00
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free(content);
|
2007-11-03 07:24:34 +01:00
|
|
|
|
2007-05-24 20:12:19 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_addChild(IXMLElement *iface, IXMLElement *pChildElem,
|
2009-03-09 23:28:42 +01:00
|
|
|
LONG lIndex, LONG lreserved)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
xmlelem *childElem = impl_from_IXMLElement(pChildElem);
|
|
|
|
xmlNodePtr child;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p %d %d)\n", This, pChildElem, lIndex, lreserved);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (lIndex == 0)
|
|
|
|
child = xmlAddChild(This->node, childElem->node);
|
|
|
|
else
|
|
|
|
child = xmlAddNextSibling(This->node, childElem->node->last);
|
|
|
|
|
2010-01-14 22:18:32 +01:00
|
|
|
/* parent is responsible for child data */
|
|
|
|
if (child) childElem->own = FALSE;
|
|
|
|
|
2007-05-24 20:12:19 +02:00
|
|
|
return (child) ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_removeChild(IXMLElement *iface, IXMLElement *pChildElem)
|
|
|
|
{
|
2010-01-14 22:13:50 +01:00
|
|
|
xmlelem *This = impl_from_IXMLElement(iface);
|
|
|
|
xmlelem *childElem = impl_from_IXMLElement(pChildElem);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, childElem);
|
2010-01-14 22:13:50 +01:00
|
|
|
|
|
|
|
if (!pChildElem)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* only supported for This is childElem parent case */
|
|
|
|
if (This->node != childElem->node->parent)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
xmlUnlinkNode(childElem->node);
|
2010-01-14 22:18:32 +01:00
|
|
|
/* standalone element now */
|
|
|
|
childElem->own = TRUE;
|
2010-01-14 22:13:50 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IXMLElementVtbl xmlelem_vtbl =
|
|
|
|
{
|
|
|
|
xmlelem_QueryInterface,
|
|
|
|
xmlelem_AddRef,
|
|
|
|
xmlelem_Release,
|
|
|
|
xmlelem_GetTypeInfoCount,
|
|
|
|
xmlelem_GetTypeInfo,
|
|
|
|
xmlelem_GetIDsOfNames,
|
|
|
|
xmlelem_Invoke,
|
|
|
|
xmlelem_get_tagName,
|
|
|
|
xmlelem_put_tagName,
|
|
|
|
xmlelem_get_parent,
|
|
|
|
xmlelem_setAttribute,
|
|
|
|
xmlelem_getAttribute,
|
|
|
|
xmlelem_removeAttribute,
|
|
|
|
xmlelem_get_children,
|
|
|
|
xmlelem_get_type,
|
|
|
|
xmlelem_get_text,
|
|
|
|
xmlelem_put_text,
|
|
|
|
xmlelem_addChild,
|
|
|
|
xmlelem_removeChild
|
|
|
|
};
|
|
|
|
|
2010-01-14 22:18:32 +01:00
|
|
|
HRESULT XMLElement_create(IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj, BOOL own)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
|
|
|
xmlelem *elem;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", pUnkOuter, ppObj);
|
|
|
|
|
|
|
|
if (!ppObj)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppObj = NULL;
|
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
elem = heap_alloc(sizeof (*elem));
|
2007-05-24 20:12:19 +02:00
|
|
|
if(!elem)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-23 02:03:06 +01:00
|
|
|
elem->IXMLElement_iface.lpVtbl = &xmlelem_vtbl;
|
2007-05-24 20:12:19 +02:00
|
|
|
elem->ref = 1;
|
|
|
|
elem->node = node;
|
2010-01-14 22:18:32 +01:00
|
|
|
elem->own = own;
|
2007-05-24 20:12:19 +02:00
|
|
|
|
2010-12-23 02:03:06 +01:00
|
|
|
*ppObj = &elem->IXMLElement_iface;
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
TRACE("returning iface %p\n", *ppObj);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* IXMLElementCollection
|
|
|
|
*/
|
|
|
|
typedef struct _xmlelem_collection
|
|
|
|
{
|
2010-12-23 02:03:06 +01:00
|
|
|
IXMLElementCollection IXMLElementCollection_iface;
|
|
|
|
IEnumVARIANT IEnumVARIANT_iface;
|
2007-05-24 20:12:19 +02:00
|
|
|
LONG ref;
|
|
|
|
LONG length;
|
|
|
|
xmlNodePtr node;
|
|
|
|
|
|
|
|
/* IEnumVARIANT members */
|
|
|
|
xmlNodePtr current;
|
|
|
|
} xmlelem_collection;
|
|
|
|
|
2010-01-14 22:16:03 +01:00
|
|
|
static inline LONG xmlelem_collection_updatelength(xmlelem_collection *collection)
|
|
|
|
{
|
|
|
|
xmlNodePtr ptr = collection->node->children;
|
|
|
|
|
|
|
|
collection->length = 0;
|
|
|
|
while (ptr)
|
|
|
|
{
|
|
|
|
collection->length++;
|
|
|
|
ptr = ptr->next;
|
|
|
|
}
|
|
|
|
return collection->length;
|
|
|
|
}
|
|
|
|
|
2007-05-24 20:12:19 +02:00
|
|
|
static inline xmlelem_collection *impl_from_IXMLElementCollection(IXMLElementCollection *iface)
|
|
|
|
{
|
2010-12-23 02:03:06 +01:00
|
|
|
return CONTAINING_RECORD(iface, xmlelem_collection, IXMLElementCollection_iface);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline xmlelem_collection *impl_from_IEnumVARIANT(IEnumVARIANT *iface)
|
|
|
|
{
|
2010-12-23 02:03:06 +01:00
|
|
|
return CONTAINING_RECORD(iface, xmlelem_collection, IEnumVARIANT_iface);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_QueryInterface(IXMLElementCollection *iface, REFIID riid, void** ppvObject)
|
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IXMLElementCollection(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IXMLElementCollection))
|
|
|
|
{
|
|
|
|
*ppvObject = iface;
|
|
|
|
}
|
|
|
|
else if (IsEqualGUID(riid, &IID_IEnumVARIANT))
|
|
|
|
{
|
2010-12-23 02:03:06 +01:00
|
|
|
*ppvObject = &This->IEnumVARIANT_iface;
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("interface %s not implemented\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IXMLElementCollection_AddRef(iface);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlelem_collection_AddRef(IXMLElementCollection *iface)
|
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IXMLElementCollection(iface);
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2007-05-24 20:12:19 +02:00
|
|
|
return InterlockedIncrement(&This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlelem_collection_Release(IXMLElementCollection *iface)
|
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IXMLElementCollection(iface);
|
|
|
|
LONG ref;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
ref = InterlockedDecrement(&This->ref);
|
|
|
|
if (ref == 0)
|
|
|
|
{
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free(This);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_GetTypeInfoCount(IXMLElementCollection *iface, UINT* pctinfo)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_GetTypeInfo(IXMLElementCollection *iface, UINT iTInfo,
|
|
|
|
LCID lcid, ITypeInfo** ppTInfo)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_GetIDsOfNames(IXMLElementCollection *iface, REFIID riid,
|
|
|
|
LPOLESTR* rgszNames, UINT cNames,
|
|
|
|
LCID lcid, DISPID* rgDispId)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_Invoke(IXMLElementCollection *iface, DISPID dispIdMember,
|
|
|
|
REFIID riid, LCID lcid, WORD wFlags,
|
|
|
|
DISPPARAMS* pDispParams, VARIANT* pVarResult,
|
|
|
|
EXCEPINFO* pExcepInfo, UINT* puArgErr)
|
|
|
|
{
|
|
|
|
FIXME("\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-03-09 23:28:42 +01:00
|
|
|
static HRESULT WINAPI xmlelem_collection_put_length(IXMLElementCollection *iface, LONG v)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
2011-02-22 00:04:02 +01:00
|
|
|
xmlelem_collection *This = impl_from_IXMLElementCollection(iface);
|
|
|
|
TRACE("(%p)->(%d)\n", This, v);
|
2007-05-24 20:12:19 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2009-03-09 23:28:42 +01:00
|
|
|
static HRESULT WINAPI xmlelem_collection_get_length(IXMLElementCollection *iface, LONG *p)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IXMLElementCollection(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!p)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2010-01-14 22:16:03 +01:00
|
|
|
*p = xmlelem_collection_updatelength(This);
|
2007-05-24 20:12:19 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_get__newEnum(IXMLElementCollection *iface, IUnknown **ppUnk)
|
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IXMLElementCollection(iface);
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, ppUnk);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!ppUnk)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppUnk = (IUnknown *)This;
|
|
|
|
IUnknown_AddRef(*ppUnk);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_item(IXMLElementCollection *iface, VARIANT var1,
|
|
|
|
VARIANT var2, IDispatch **ppDisp)
|
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IXMLElementCollection(iface);
|
2010-01-14 22:16:03 +01:00
|
|
|
xmlNodePtr ptr = This->node->children;
|
2007-05-24 20:12:19 +02:00
|
|
|
int index, i;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s %s %p)\n", This, debugstr_variant(&var1), debugstr_variant(&var2), ppDisp);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!ppDisp)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppDisp = NULL;
|
|
|
|
|
|
|
|
index = V_I4(&var1);
|
|
|
|
if (index < 0)
|
|
|
|
return E_INVALIDARG;
|
2010-01-14 22:16:03 +01:00
|
|
|
|
|
|
|
xmlelem_collection_updatelength(This);
|
2007-05-24 20:12:19 +02:00
|
|
|
if (index >= This->length)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
for (i = 0; i < index; i++)
|
|
|
|
ptr = ptr->next;
|
|
|
|
|
2010-01-14 22:18:32 +01:00
|
|
|
return XMLElement_create((IUnknown *)iface, ptr, (LPVOID *)ppDisp, FALSE);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IXMLElementCollectionVtbl xmlelem_collection_vtbl =
|
|
|
|
{
|
|
|
|
xmlelem_collection_QueryInterface,
|
|
|
|
xmlelem_collection_AddRef,
|
|
|
|
xmlelem_collection_Release,
|
|
|
|
xmlelem_collection_GetTypeInfoCount,
|
|
|
|
xmlelem_collection_GetTypeInfo,
|
|
|
|
xmlelem_collection_GetIDsOfNames,
|
|
|
|
xmlelem_collection_Invoke,
|
|
|
|
xmlelem_collection_put_length,
|
|
|
|
xmlelem_collection_get_length,
|
|
|
|
xmlelem_collection_get__newEnum,
|
|
|
|
xmlelem_collection_item
|
|
|
|
};
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* xmlelem_collection implementation of IEnumVARIANT.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_QueryInterface(
|
|
|
|
IEnumVARIANT *iface, REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
|
|
|
xmlelem_collection *this = impl_from_IEnumVARIANT(iface);
|
|
|
|
return IXMLDocument_QueryInterface((IXMLDocument *)this, riid, ppvObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlelem_collection_IEnumVARIANT_AddRef(
|
|
|
|
IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
xmlelem_collection *this = impl_from_IEnumVARIANT(iface);
|
|
|
|
return IXMLDocument_AddRef((IXMLDocument *)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI xmlelem_collection_IEnumVARIANT_Release(
|
|
|
|
IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
xmlelem_collection *this = impl_from_IEnumVARIANT(iface);
|
|
|
|
return IXMLDocument_Release((IXMLDocument *)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_Next(
|
2010-06-21 00:46:23 +02:00
|
|
|
IEnumVARIANT *iface, ULONG celt, VARIANT *rgVar, ULONG *fetched)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
xmlNodePtr ptr = This->current;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%d %p %p)\n", This, celt, rgVar, fetched);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
if (!rgVar)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
/* FIXME: handle celt */
|
2010-06-21 00:46:23 +02:00
|
|
|
if (fetched)
|
|
|
|
*fetched = 1;
|
2007-05-24 20:12:19 +02:00
|
|
|
|
2010-06-21 00:46:23 +02:00
|
|
|
if (This->current)
|
|
|
|
This->current = This->current->next;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
V_VT(rgVar) = VT_EMPTY;
|
|
|
|
if (fetched) *fetched = 0;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
V_VT(rgVar) = VT_DISPATCH;
|
2010-01-14 22:18:32 +01:00
|
|
|
return XMLElement_create((IUnknown *)iface, ptr, (LPVOID *)&V_DISPATCH(rgVar), FALSE);
|
2007-05-24 20:12:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_Skip(
|
|
|
|
IEnumVARIANT *iface, ULONG celt)
|
|
|
|
{
|
2011-02-22 00:04:02 +01:00
|
|
|
xmlelem_collection *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
FIXME("(%p)->(%d): stub\n", This, celt);
|
2007-05-24 20:12:19 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_Reset(
|
|
|
|
IEnumVARIANT *iface)
|
|
|
|
{
|
|
|
|
xmlelem_collection *This = impl_from_IEnumVARIANT(iface);
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)\n", This);
|
2010-01-14 22:16:03 +01:00
|
|
|
This->current = This->node->children;
|
2007-05-24 20:12:19 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI xmlelem_collection_IEnumVARIANT_Clone(
|
|
|
|
IEnumVARIANT *iface, IEnumVARIANT **ppEnum)
|
|
|
|
{
|
2011-02-22 00:04:02 +01:00
|
|
|
xmlelem_collection *This = impl_from_IEnumVARIANT(iface);
|
|
|
|
FIXME("(%p)->(%p): stub\n", This, ppEnum);
|
2007-05-24 20:12:19 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IEnumVARIANTVtbl xmlelem_collection_IEnumVARIANTvtbl =
|
|
|
|
{
|
|
|
|
xmlelem_collection_IEnumVARIANT_QueryInterface,
|
|
|
|
xmlelem_collection_IEnumVARIANT_AddRef,
|
|
|
|
xmlelem_collection_IEnumVARIANT_Release,
|
|
|
|
xmlelem_collection_IEnumVARIANT_Next,
|
|
|
|
xmlelem_collection_IEnumVARIANT_Skip,
|
|
|
|
xmlelem_collection_IEnumVARIANT_Reset,
|
|
|
|
xmlelem_collection_IEnumVARIANT_Clone
|
|
|
|
};
|
|
|
|
|
2008-12-18 20:58:39 +01:00
|
|
|
static HRESULT XMLElementCollection_create(IUnknown *pUnkOuter, xmlNodePtr node, LPVOID *ppObj)
|
2007-05-24 20:12:19 +02:00
|
|
|
{
|
|
|
|
xmlelem_collection *collection;
|
|
|
|
|
|
|
|
TRACE("(%p,%p)\n", pUnkOuter, ppObj);
|
|
|
|
|
|
|
|
*ppObj = NULL;
|
|
|
|
|
2010-01-14 22:16:03 +01:00
|
|
|
if (!node->children)
|
2007-05-24 20:12:19 +02:00
|
|
|
return S_FALSE;
|
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
collection = heap_alloc(sizeof (*collection));
|
2007-05-24 20:12:19 +02:00
|
|
|
if(!collection)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2010-12-23 02:03:06 +01:00
|
|
|
collection->IXMLElementCollection_iface.lpVtbl = &xmlelem_collection_vtbl;
|
|
|
|
collection->IEnumVARIANT_iface.lpVtbl = &xmlelem_collection_IEnumVARIANTvtbl;
|
2007-05-24 20:12:19 +02:00
|
|
|
collection->ref = 1;
|
|
|
|
collection->length = 0;
|
|
|
|
collection->node = node;
|
2010-01-14 22:16:03 +01:00
|
|
|
collection->current = node->children;
|
|
|
|
xmlelem_collection_updatelength(collection);
|
2007-05-24 20:12:19 +02:00
|
|
|
|
2010-12-23 02:03:06 +01:00
|
|
|
*ppObj = &collection->IXMLElementCollection_iface;
|
2007-05-24 20:12:19 +02:00
|
|
|
|
|
|
|
TRACE("returning iface %p\n", *ppObj);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|