2005-08-03 12:58:47 +02:00
|
|
|
/*
|
|
|
|
* DOM Document implementation
|
|
|
|
*
|
|
|
|
* Copyright 2005 Mike McCormack
|
|
|
|
*
|
2005-11-08 13:46:43 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
2005-08-03 12:58:47 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2005-11-08 13:46:43 +01:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2005-08-03 12:58:47 +02:00
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-08-03 12:58:47 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2005-08-03 12:58:47 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
2006-06-12 02:34:28 +02:00
|
|
|
#include "winnls.h"
|
2005-08-03 12:58:47 +02:00
|
|
|
#include "ole2.h"
|
2010-08-29 23:31:49 +02:00
|
|
|
#include "msxml6.h"
|
2005-08-03 12:58:47 +02:00
|
|
|
|
|
|
|
#include "msxml_private.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2005-08-08 14:13:31 +02:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
|
2015-02-21 14:58:41 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
2010-11-23 03:57:29 +01:00
|
|
|
static const xmlChar DT_prefix[] = "dt";
|
2010-11-23 03:55:54 +01:00
|
|
|
static const xmlChar DT_nsURI[] = "urn:schemas-microsoft-com:datatypes";
|
|
|
|
|
2005-08-03 12:58:47 +02:00
|
|
|
typedef struct _domelem
|
|
|
|
{
|
2009-10-14 20:01:42 +02:00
|
|
|
xmlnode node;
|
2010-12-16 01:04:12 +01:00
|
|
|
IXMLDOMElement IXMLDOMElement_iface;
|
2005-08-03 12:58:47 +02:00
|
|
|
LONG ref;
|
|
|
|
} domelem;
|
|
|
|
|
2011-11-12 22:45:10 +01:00
|
|
|
static const struct nodemap_funcs domelem_attr_map;
|
|
|
|
|
2011-11-19 14:33:10 +01:00
|
|
|
static const tid_t domelem_se_tids[] = {
|
|
|
|
IXMLDOMNode_tid,
|
|
|
|
IXMLDOMElement_tid,
|
2013-05-07 13:07:28 +02:00
|
|
|
NULL_tid
|
2011-11-19 14:33:10 +01:00
|
|
|
};
|
|
|
|
|
2005-08-03 12:58:47 +02:00
|
|
|
static inline domelem *impl_from_IXMLDOMElement( IXMLDOMElement *iface )
|
|
|
|
{
|
2010-12-16 01:04:12 +01:00
|
|
|
return CONTAINING_RECORD(iface, domelem, IXMLDOMElement_iface);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
2010-10-21 00:07:20 +02:00
|
|
|
static inline xmlNodePtr get_element( const domelem *This )
|
2005-08-18 12:48:13 +02:00
|
|
|
{
|
2009-10-14 20:01:42 +02:00
|
|
|
return This->node.node;
|
2005-08-18 12:48:13 +02:00
|
|
|
}
|
|
|
|
|
2005-08-03 12:58:47 +02:00
|
|
|
static HRESULT WINAPI domelem_QueryInterface(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
REFIID riid,
|
|
|
|
void** ppvObject )
|
|
|
|
{
|
2005-12-01 18:46:42 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2009-08-22 19:51:45 +02:00
|
|
|
|
2010-02-17 07:40:40 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObject);
|
2005-08-03 12:58:47 +02:00
|
|
|
|
2009-08-22 19:51:45 +02:00
|
|
|
if ( IsEqualGUID( riid, &IID_IXMLDOMElement ) ||
|
2010-09-04 17:56:08 +02:00
|
|
|
IsEqualGUID( riid, &IID_IXMLDOMNode ) ||
|
2009-08-22 19:51:45 +02:00
|
|
|
IsEqualGUID( riid, &IID_IDispatch ) ||
|
|
|
|
IsEqualGUID( riid, &IID_IUnknown ) )
|
|
|
|
{
|
2010-12-16 01:04:12 +01:00
|
|
|
*ppvObject = &This->IXMLDOMElement_iface;
|
2009-08-22 19:51:45 +02:00
|
|
|
}
|
2010-09-04 17:54:46 +02:00
|
|
|
else if(node_query_interface(&This->node, riid, ppvObject))
|
2009-08-31 07:18:00 +02:00
|
|
|
{
|
|
|
|
return *ppvObject ? S_OK : E_NOINTERFACE;
|
|
|
|
}
|
2011-11-19 14:33:10 +01:00
|
|
|
else if(IsEqualGUID( riid, &IID_ISupportErrorInfo ))
|
|
|
|
{
|
|
|
|
return node_create_supporterrorinfo(domelem_se_tids, ppvObject);
|
|
|
|
}
|
2009-08-22 19:51:45 +02:00
|
|
|
else
|
|
|
|
{
|
2011-03-13 14:40:26 +01:00
|
|
|
TRACE("interface %s not implemented\n", debugstr_guid(riid));
|
2011-02-28 20:28:53 +01:00
|
|
|
*ppvObject = NULL;
|
2009-08-22 19:51:45 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown_AddRef( (IUnknown*)*ppvObject );
|
|
|
|
return S_OK;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI domelem_AddRef(
|
|
|
|
IXMLDOMElement *iface )
|
|
|
|
{
|
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2009-08-22 19:51:45 +02:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2011-03-05 19:32:31 +01:00
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
2009-08-22 19:51:45 +02:00
|
|
|
|
|
|
|
return ref;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI domelem_Release(
|
|
|
|
IXMLDOMElement *iface )
|
|
|
|
{
|
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2009-08-22 19:51:45 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2011-03-05 19:32:31 +01:00
|
|
|
TRACE("(%p)->(%d)\n", This, ref);
|
2009-08-22 19:51:45 +02:00
|
|
|
|
|
|
|
if(!ref) {
|
2009-10-14 20:01:42 +02:00
|
|
|
destroy_xmlnode(&This->node);
|
2009-08-22 19:51:45 +02:00
|
|
|
heap_free(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_GetTypeInfoCount(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
UINT* pctinfo )
|
|
|
|
{
|
2008-02-19 02:13:22 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-11-19 17:32:23 +01:00
|
|
|
return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_GetTypeInfo(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
UINT iTInfo, LCID lcid,
|
|
|
|
ITypeInfo** ppTInfo )
|
|
|
|
{
|
2008-02-19 02:13:22 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-11-19 17:32:23 +01:00
|
|
|
return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface,
|
|
|
|
iTInfo, lcid, ppTInfo);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_GetIDsOfNames(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
REFIID riid, LPOLESTR* rgszNames,
|
|
|
|
UINT cNames, LCID lcid, DISPID* rgDispId )
|
|
|
|
{
|
2008-02-19 02:13:22 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-11-19 17:32:23 +01:00
|
|
|
return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface,
|
|
|
|
riid, rgszNames, cNames, lcid, rgDispId);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_Invoke(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
DISPID dispIdMember, REFIID riid, LCID lcid,
|
|
|
|
WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult,
|
|
|
|
EXCEPINFO* pExcepInfo, UINT* puArgErr )
|
|
|
|
{
|
2008-02-19 02:13:22 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-11-19 17:32:23 +01:00
|
|
|
return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface,
|
|
|
|
dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_nodeName(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR* p )
|
|
|
|
{
|
2005-08-18 12:48:13 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-04 17:56:25 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
|
|
|
|
return node_get_nodeName(&This->node, p);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_nodeValue(
|
|
|
|
IXMLDOMElement *iface,
|
2010-09-04 17:56:45 +02:00
|
|
|
VARIANT* value)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-18 12:48:13 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-04 17:56:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, value);
|
|
|
|
|
|
|
|
if(!value)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
V_VT(value) = VT_NULL;
|
|
|
|
V_BSTR(value) = NULL; /* tests show that we should do this */
|
|
|
|
return S_FALSE;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_put_nodeValue(
|
|
|
|
IXMLDOMElement *iface,
|
2010-09-07 15:27:31 +02:00
|
|
|
VARIANT value)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
|
2010-09-07 15:27:31 +02:00
|
|
|
return E_FAIL;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_nodeType(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
DOMNodeType* domNodeType )
|
|
|
|
{
|
2005-08-18 12:48:13 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-07 15:28:21 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, domNodeType);
|
|
|
|
|
|
|
|
*domNodeType = NODE_ELEMENT;
|
|
|
|
return S_OK;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_parentNode(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNode** parent )
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-07 15:28:21 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, parent);
|
|
|
|
|
|
|
|
return node_get_parent(&This->node, parent);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_childNodes(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNodeList** outList)
|
|
|
|
{
|
2005-08-18 12:48:13 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-08 15:12:02 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, outList);
|
|
|
|
|
|
|
|
return node_get_child_nodes(&This->node, outList);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_firstChild(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNode** domNode)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-08 15:12:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, domNode);
|
|
|
|
|
|
|
|
return node_get_first_child(&This->node, domNode);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_lastChild(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNode** domNode)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-08 15:12:14 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, domNode);
|
|
|
|
|
2010-09-08 21:55:37 +02:00
|
|
|
return node_get_last_child(&This->node, domNode);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_previousSibling(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNode** domNode)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-10 16:53:48 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, domNode);
|
|
|
|
|
|
|
|
return node_get_previous_sibling(&This->node, domNode);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_nextSibling(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNode** domNode)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-10 16:53:48 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, domNode);
|
|
|
|
|
|
|
|
return node_get_next_sibling(&This->node, domNode);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_attributes(
|
|
|
|
IXMLDOMElement *iface,
|
2011-03-10 19:56:51 +01:00
|
|
|
IXMLDOMNamedNodeMap** map)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-18 12:48:13 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-09-10 16:54:06 +02:00
|
|
|
|
2011-03-10 19:56:51 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, map);
|
2010-09-10 16:54:06 +02:00
|
|
|
|
2011-11-12 22:45:10 +01:00
|
|
|
*map = create_nodemap(This->node.node, &domelem_attr_map);
|
2010-09-10 16:54:06 +02:00
|
|
|
return S_OK;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_insertBefore(
|
|
|
|
IXMLDOMElement *iface,
|
2010-09-10 16:55:14 +02:00
|
|
|
IXMLDOMNode* newNode, VARIANT refChild,
|
2013-03-03 18:20:13 +01:00
|
|
|
IXMLDOMNode** old_node)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2013-03-03 18:20:13 +01:00
|
|
|
DOMNodeType type;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %s %p)\n", This, newNode, debugstr_variant(&refChild), old_node);
|
2010-09-10 16:55:14 +02:00
|
|
|
|
2013-03-03 18:20:13 +01:00
|
|
|
hr = IXMLDOMNode_get_nodeType(newNode, &type);
|
|
|
|
if (hr != S_OK) return hr;
|
2010-09-10 16:55:14 +02:00
|
|
|
|
2013-03-03 18:20:13 +01:00
|
|
|
TRACE("new node type %d\n", type);
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case NODE_DOCUMENT:
|
|
|
|
case NODE_DOCUMENT_TYPE:
|
|
|
|
case NODE_ENTITY:
|
|
|
|
case NODE_NOTATION:
|
|
|
|
if (old_node) *old_node = NULL;
|
|
|
|
return E_FAIL;
|
|
|
|
default:
|
|
|
|
return node_insert_before(&This->node, newNode, &refChild, old_node);
|
|
|
|
}
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_replaceChild(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNode* newNode,
|
|
|
|
IXMLDOMNode* oldNode,
|
|
|
|
IXMLDOMNode** outOldNode)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-13 15:11:32 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p %p)\n", This, newNode, oldNode, outOldNode);
|
|
|
|
|
|
|
|
return node_replace_child(&This->node, newNode, oldNode, outOldNode);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_removeChild(
|
|
|
|
IXMLDOMElement *iface,
|
2011-02-23 12:28:44 +01:00
|
|
|
IXMLDOMNode *child, IXMLDOMNode **oldChild)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 12:28:44 +01:00
|
|
|
TRACE("(%p)->(%p %p)\n", This, child, oldChild);
|
|
|
|
return node_remove_child(&This->node, child, oldChild);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_appendChild(
|
|
|
|
IXMLDOMElement *iface,
|
2011-02-23 12:32:16 +01:00
|
|
|
IXMLDOMNode *child, IXMLDOMNode **outChild)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 12:32:16 +01:00
|
|
|
TRACE("(%p)->(%p %p)\n", This, child, outChild);
|
|
|
|
return node_append_child(&This->node, child, outChild);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_hasChildNodes(
|
|
|
|
IXMLDOMElement *iface,
|
2011-02-23 12:35:35 +01:00
|
|
|
VARIANT_BOOL *ret)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 12:35:35 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, ret);
|
|
|
|
return node_has_childnodes(&This->node, ret);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_ownerDocument(
|
2011-02-23 12:38:32 +01:00
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMDocument **doc)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 12:38:32 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, doc);
|
|
|
|
return node_get_owner_doc(&This->node, doc);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_cloneNode(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-31 09:50:58 +01:00
|
|
|
VARIANT_BOOL deep, IXMLDOMNode** outNode)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-31 09:50:58 +01:00
|
|
|
TRACE("(%p)->(%d %p)\n", This, deep, outNode);
|
|
|
|
return node_clone( &This->node, deep, outNode );
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_nodeTypeString(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR* p)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-11-07 20:28:36 +01:00
|
|
|
static const WCHAR elementW[] = {'e','l','e','m','e','n','t',0};
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
|
|
|
|
return return_bstr(elementW, p);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_text(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR* p)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 12:40:43 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
return node_get_text(&This->node, p);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_put_text(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR p)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-19 01:27:48 +02:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(p));
|
|
|
|
return node_put_text( &This->node, p );
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_specified(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-24 22:55:04 +02:00
|
|
|
VARIANT_BOOL* isSpecified)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-24 22:55:04 +02:00
|
|
|
FIXME("(%p)->(%p) stub!\n", This, isSpecified);
|
|
|
|
*isSpecified = VARIANT_TRUE;
|
|
|
|
return S_OK;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_definition(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-24 22:55:04 +02:00
|
|
|
IXMLDOMNode** definitionNode)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-24 22:55:04 +02:00
|
|
|
FIXME("(%p)->(%p)\n", This, definitionNode);
|
|
|
|
return E_NOTIMPL;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
2010-11-23 03:55:54 +01:00
|
|
|
static inline BYTE hex_to_byte(xmlChar c)
|
|
|
|
{
|
|
|
|
if(c <= '9') return c-'0';
|
|
|
|
if(c <= 'F') return c-'A'+10;
|
|
|
|
return c-'a'+10;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BYTE base64_to_byte(xmlChar c)
|
|
|
|
{
|
|
|
|
if(c == '+') return 62;
|
|
|
|
if(c == '/') return 63;
|
|
|
|
if(c <= '9') return c-'0'+52;
|
|
|
|
if(c <= 'Z') return c-'A';
|
|
|
|
return c-'a'+26;
|
|
|
|
}
|
|
|
|
|
2011-03-17 11:14:25 +01:00
|
|
|
static inline HRESULT variant_from_dt(XDR_DT dt, xmlChar* str, VARIANT* v)
|
2010-11-23 03:55:54 +01:00
|
|
|
{
|
|
|
|
VARIANT src;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
BOOL handled = FALSE;
|
|
|
|
|
|
|
|
VariantInit(&src);
|
|
|
|
|
|
|
|
switch (dt)
|
|
|
|
{
|
|
|
|
case DT_INVALID:
|
|
|
|
case DT_STRING:
|
|
|
|
case DT_NMTOKEN:
|
|
|
|
case DT_NMTOKENS:
|
|
|
|
case DT_NUMBER:
|
|
|
|
case DT_URI:
|
|
|
|
case DT_UUID:
|
|
|
|
{
|
|
|
|
V_VT(v) = VT_BSTR;
|
|
|
|
V_BSTR(v) = bstr_from_xmlChar(str);
|
|
|
|
|
|
|
|
if(!V_BSTR(v))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DT_DATE:
|
|
|
|
case DT_DATE_TZ:
|
|
|
|
case DT_DATETIME:
|
|
|
|
case DT_DATETIME_TZ:
|
|
|
|
case DT_TIME:
|
|
|
|
case DT_TIME_TZ:
|
|
|
|
{
|
|
|
|
WCHAR *p, *e;
|
|
|
|
SYSTEMTIME st;
|
|
|
|
DOUBLE date = 0.0;
|
|
|
|
|
|
|
|
st.wYear = 1899;
|
|
|
|
st.wMonth = 12;
|
|
|
|
st.wDay = 30;
|
|
|
|
st.wDayOfWeek = st.wHour = st.wMinute = st.wSecond = st.wMilliseconds = 0;
|
|
|
|
|
|
|
|
V_VT(&src) = VT_BSTR;
|
|
|
|
V_BSTR(&src) = bstr_from_xmlChar(str);
|
|
|
|
|
|
|
|
if(!V_BSTR(&src))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
p = V_BSTR(&src);
|
|
|
|
e = p + SysStringLen(V_BSTR(&src));
|
|
|
|
|
|
|
|
if(p+4<e && *(p+4)=='-') /* parse date (yyyy-mm-dd) */
|
|
|
|
{
|
|
|
|
st.wYear = atoiW(p);
|
|
|
|
st.wMonth = atoiW(p+5);
|
|
|
|
st.wDay = atoiW(p+8);
|
|
|
|
p += 10;
|
|
|
|
|
|
|
|
if(*p == 'T') p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(p+2<e && *(p+2)==':') /* parse time (hh:mm:ss.?) */
|
|
|
|
{
|
|
|
|
st.wHour = atoiW(p);
|
|
|
|
st.wMinute = atoiW(p+3);
|
|
|
|
st.wSecond = atoiW(p+6);
|
|
|
|
p += 8;
|
|
|
|
|
|
|
|
if(*p == '.')
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
while(isdigitW(*p)) p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemTimeToVariantTime(&st, &date);
|
|
|
|
V_VT(v) = VT_DATE;
|
|
|
|
V_DATE(v) = date;
|
|
|
|
|
|
|
|
if(*p == '+') /* parse timezone offset (+hh:mm) */
|
|
|
|
V_DATE(v) += (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
|
|
|
|
else if(*p == '-') /* parse timezone offset (-hh:mm) */
|
|
|
|
V_DATE(v) -= (DOUBLE)atoiW(p+1)/24 + (DOUBLE)atoiW(p+4)/1440;
|
|
|
|
|
|
|
|
VariantClear(&src);
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DT_BIN_HEX:
|
|
|
|
{
|
|
|
|
SAFEARRAYBOUND sab;
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
len = xmlStrlen(str)/2;
|
|
|
|
sab.lLbound = 0;
|
|
|
|
sab.cElements = len;
|
|
|
|
|
|
|
|
V_VT(v) = (VT_ARRAY|VT_UI1);
|
|
|
|
V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
|
|
|
|
|
|
|
|
if(!V_ARRAY(v))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
for(i=0; i<len; i++)
|
|
|
|
((BYTE*)V_ARRAY(v)->pvData)[i] = (hex_to_byte(str[2*i])<<4)
|
|
|
|
+ hex_to_byte(str[2*i+1]);
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DT_BIN_BASE64:
|
|
|
|
{
|
|
|
|
SAFEARRAYBOUND sab;
|
2011-03-17 11:14:25 +01:00
|
|
|
xmlChar *c1, *c2;
|
2010-11-23 03:55:54 +01:00
|
|
|
int i, len;
|
|
|
|
|
2011-03-17 11:14:25 +01:00
|
|
|
/* remove all formatting chars */
|
|
|
|
c1 = c2 = str;
|
|
|
|
len = 0;
|
|
|
|
while (*c2)
|
|
|
|
{
|
|
|
|
if ( *c2 == ' ' || *c2 == '\t' ||
|
|
|
|
*c2 == '\n' || *c2 == '\r' )
|
|
|
|
{
|
|
|
|
c2++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*c1++ = *c2++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip padding */
|
2010-11-23 03:55:54 +01:00
|
|
|
if(str[len-2] == '=') i = 2;
|
|
|
|
else if(str[len-1] == '=') i = 1;
|
|
|
|
else i = 0;
|
|
|
|
|
|
|
|
sab.lLbound = 0;
|
|
|
|
sab.cElements = len/4*3-i;
|
|
|
|
|
|
|
|
V_VT(v) = (VT_ARRAY|VT_UI1);
|
|
|
|
V_ARRAY(v) = SafeArrayCreate(VT_UI1, 1, &sab);
|
|
|
|
|
|
|
|
if(!V_ARRAY(v))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
for(i=0; i<len/4; i++)
|
|
|
|
{
|
|
|
|
((BYTE*)V_ARRAY(v)->pvData)[3*i] = (base64_to_byte(str[4*i])<<2)
|
|
|
|
+ (base64_to_byte(str[4*i+1])>>4);
|
|
|
|
if(3*i+1 < sab.cElements)
|
|
|
|
((BYTE*)V_ARRAY(v)->pvData)[3*i+1] = (base64_to_byte(str[4*i+1])<<4)
|
|
|
|
+ (base64_to_byte(str[4*i+2])>>2);
|
|
|
|
if(3*i+2 < sab.cElements)
|
|
|
|
((BYTE*)V_ARRAY(v)->pvData)[3*i+2] = (base64_to_byte(str[4*i+2])<<6)
|
|
|
|
+ base64_to_byte(str[4*i+3]);
|
|
|
|
}
|
|
|
|
handled = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DT_BOOLEAN:
|
|
|
|
V_VT(v) = VT_BOOL;
|
|
|
|
break;
|
|
|
|
case DT_FIXED_14_4:
|
|
|
|
V_VT(v) = VT_CY;
|
|
|
|
break;
|
|
|
|
case DT_I1:
|
|
|
|
V_VT(v) = VT_I1;
|
|
|
|
break;
|
|
|
|
case DT_I2:
|
|
|
|
V_VT(v) = VT_I2;
|
|
|
|
break;
|
|
|
|
case DT_I4:
|
|
|
|
case DT_INT:
|
|
|
|
V_VT(v) = VT_I4;
|
|
|
|
break;
|
|
|
|
case DT_I8:
|
|
|
|
V_VT(v) = VT_I8;
|
|
|
|
break;
|
|
|
|
case DT_R4:
|
|
|
|
V_VT(v) = VT_R4;
|
|
|
|
break;
|
|
|
|
case DT_FLOAT:
|
|
|
|
case DT_R8:
|
|
|
|
V_VT(v) = VT_R8;
|
|
|
|
break;
|
|
|
|
case DT_UI1:
|
|
|
|
V_VT(v) = VT_UI1;
|
|
|
|
break;
|
|
|
|
case DT_UI2:
|
|
|
|
V_VT(v) = VT_UI2;
|
|
|
|
break;
|
|
|
|
case DT_UI4:
|
|
|
|
V_VT(v) = VT_UI4;
|
|
|
|
break;
|
|
|
|
case DT_UI8:
|
|
|
|
V_VT(v) = VT_UI8;
|
|
|
|
break;
|
|
|
|
case DT_CHAR:
|
|
|
|
case DT_ENTITY:
|
|
|
|
case DT_ENTITIES:
|
|
|
|
case DT_ENUMERATION:
|
|
|
|
case DT_ID:
|
|
|
|
case DT_IDREF:
|
|
|
|
case DT_IDREFS:
|
|
|
|
case DT_NOTATION:
|
2011-09-21 16:45:11 +02:00
|
|
|
FIXME("need to handle dt:%s\n", debugstr_dt(dt));
|
2010-11-23 03:55:54 +01:00
|
|
|
V_VT(v) = VT_BSTR;
|
|
|
|
V_BSTR(v) = bstr_from_xmlChar(str);
|
|
|
|
if (!V_BSTR(v))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
handled = TRUE;
|
|
|
|
break;
|
2012-01-23 05:28:21 +01:00
|
|
|
default:
|
|
|
|
WARN("unknown type %d\n", dt);
|
2010-11-23 03:55:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!handled)
|
|
|
|
{
|
|
|
|
V_VT(&src) = VT_BSTR;
|
|
|
|
V_BSTR(&src) = bstr_from_xmlChar(str);
|
|
|
|
|
|
|
|
if(!V_BSTR(&src))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = VariantChangeTypeEx(v, &src,
|
|
|
|
MAKELCID(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),SORT_DEFAULT),0, V_VT(v));
|
|
|
|
VariantClear(&src);
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-03-16 08:30:26 +01:00
|
|
|
static XDR_DT element_get_dt(xmlNodePtr node)
|
|
|
|
{
|
|
|
|
XDR_DT dt = DT_INVALID;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", node);
|
|
|
|
if(node->type != XML_ELEMENT_NODE)
|
|
|
|
{
|
|
|
|
FIXME("invalid element node\n");
|
|
|
|
return dt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node->ns && xmlStrEqual(node->ns->href, DT_nsURI))
|
|
|
|
{
|
|
|
|
dt = str_to_dt(node->name, -1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlChar* pVal = xmlGetNsProp(node, BAD_CAST "dt", DT_nsURI);
|
|
|
|
if (pVal)
|
|
|
|
{
|
|
|
|
dt = str_to_dt(pVal, -1);
|
|
|
|
xmlFree(pVal);
|
|
|
|
}
|
|
|
|
else if (node->doc)
|
|
|
|
{
|
|
|
|
IXMLDOMDocument3* doc = (IXMLDOMDocument3*)create_domdoc((xmlNodePtr)node->doc);
|
|
|
|
if (doc)
|
|
|
|
{
|
|
|
|
VARIANT v;
|
|
|
|
VariantInit(&v);
|
|
|
|
|
|
|
|
if (IXMLDOMDocument3_get_schemas(doc, &v) == S_OK &&
|
|
|
|
V_VT(&v) == VT_DISPATCH)
|
|
|
|
{
|
|
|
|
dt = SchemaCache_get_node_dt((IXMLDOMSchemaCollection2*)V_DISPATCH(&v), node);
|
|
|
|
}
|
|
|
|
VariantClear(&v);
|
|
|
|
IXMLDOMDocument3_Release(doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-21 16:45:11 +02:00
|
|
|
TRACE("=> dt:%s\n", debugstr_dt(dt));
|
2011-03-16 08:30:26 +01:00
|
|
|
return dt;
|
|
|
|
}
|
|
|
|
|
2005-08-03 12:58:47 +02:00
|
|
|
static HRESULT WINAPI domelem_get_nodeTypedValue(
|
|
|
|
IXMLDOMElement *iface,
|
2011-03-17 11:14:25 +01:00
|
|
|
VARIANT* v)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-11-23 03:55:54 +01:00
|
|
|
XDR_DT dt;
|
|
|
|
xmlChar* content;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-03-17 11:14:25 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, v);
|
2010-11-23 03:55:54 +01:00
|
|
|
|
2011-03-17 11:14:25 +01:00
|
|
|
if(!v) return E_INVALIDARG;
|
2010-11-23 03:55:54 +01:00
|
|
|
|
2011-03-17 11:14:25 +01:00
|
|
|
V_VT(v) = VT_NULL;
|
2010-11-23 03:55:54 +01:00
|
|
|
|
|
|
|
dt = element_get_dt(get_element(This));
|
|
|
|
content = xmlNodeGetContent(get_element(This));
|
2011-03-17 11:14:25 +01:00
|
|
|
hr = variant_from_dt(dt, content, v);
|
2010-11-23 03:55:54 +01:00
|
|
|
xmlFree(content);
|
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
2012-06-29 09:10:55 +02:00
|
|
|
static HRESULT encode_base64(const BYTE *buf, int len, BSTR *ret)
|
|
|
|
{
|
|
|
|
static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
const BYTE *d = buf;
|
2012-11-21 22:16:55 +01:00
|
|
|
int bytes, pad_bytes, div;
|
2012-06-29 09:10:55 +02:00
|
|
|
DWORD needed;
|
|
|
|
WCHAR *ptr;
|
|
|
|
|
|
|
|
bytes = (len*8 + 5)/6;
|
|
|
|
pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0;
|
|
|
|
|
|
|
|
TRACE("%d, bytes is %d, pad bytes is %d\n", len, bytes, pad_bytes);
|
|
|
|
needed = bytes + pad_bytes + 1;
|
|
|
|
|
|
|
|
*ret = SysAllocStringLen(NULL, needed);
|
|
|
|
if (!*ret) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
/* Three bytes of input give 4 chars of output */
|
|
|
|
div = len / 3;
|
|
|
|
|
|
|
|
ptr = *ret;
|
|
|
|
while (div > 0)
|
|
|
|
{
|
|
|
|
/* first char is the first 6 bits of the first byte*/
|
|
|
|
*ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
|
|
|
|
/* second char is the last 2 bits of the first byte and the first 4
|
|
|
|
* bits of the second byte */
|
|
|
|
*ptr++ = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
|
|
|
|
/* third char is the last 4 bits of the second byte and the first 2
|
|
|
|
* bits of the third byte */
|
|
|
|
*ptr++ = b64[ ((d[1] << 2) & 0x3c) | (d[2] >> 6 & 0x03)];
|
|
|
|
/* fourth char is the remaining 6 bits of the third byte */
|
|
|
|
*ptr++ = b64[ d[2] & 0x3f];
|
|
|
|
d += 3;
|
|
|
|
div--;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pad_bytes)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
/* first char is the first 6 bits of the first byte*/
|
|
|
|
*ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
|
|
|
|
/* second char is the last 2 bits of the first byte and the first 4
|
|
|
|
* bits of the second byte */
|
|
|
|
*ptr++ = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
|
|
|
|
/* third char is the last 4 bits of the second byte padded with
|
|
|
|
* two zeroes */
|
|
|
|
*ptr++ = b64[ ((d[1] << 2) & 0x3c) ];
|
|
|
|
/* fourth char is a = to indicate one byte of padding */
|
|
|
|
*ptr++ = '=';
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* first char is the first 6 bits of the first byte*/
|
|
|
|
*ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
|
|
|
|
/* second char is the last 2 bits of the first byte padded with
|
|
|
|
* four zeroes*/
|
|
|
|
*ptr++ = b64[ ((d[0] << 4) & 0x30)];
|
|
|
|
/* third char is = to indicate padding */
|
|
|
|
*ptr++ = '=';
|
|
|
|
/* fourth char is = to indicate padding */
|
|
|
|
*ptr++ = '=';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-02 07:43:27 +02:00
|
|
|
static HRESULT encode_binhex(const BYTE *buf, int len, BSTR *ret)
|
|
|
|
{
|
|
|
|
static const char byte_to_hex[16] = "0123456789abcdef";
|
|
|
|
int i;
|
|
|
|
|
|
|
|
*ret = SysAllocStringLen(NULL, len*2);
|
|
|
|
if (!*ret) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
(*ret)[2*i] = byte_to_hex[buf[i] >> 4];
|
|
|
|
(*ret)[2*i+1] = byte_to_hex[0x0f & buf[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-03 12:58:47 +02:00
|
|
|
static HRESULT WINAPI domelem_put_nodeTypedValue(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-30 17:42:24 +02:00
|
|
|
VARIANT value)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-06-20 07:25:12 +02:00
|
|
|
XDR_DT dt;
|
2010-10-30 17:42:24 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_variant(&value));
|
2010-10-30 17:42:24 +02:00
|
|
|
|
2011-06-20 07:25:12 +02:00
|
|
|
dt = element_get_dt(get_element(This));
|
2012-06-29 09:10:55 +02:00
|
|
|
switch (dt)
|
2010-10-30 17:42:24 +02:00
|
|
|
{
|
2012-06-29 09:10:55 +02:00
|
|
|
/* for untyped node coerce to BSTR and set */
|
|
|
|
case DT_INVALID:
|
2010-10-30 17:42:24 +02:00
|
|
|
if (V_VT(&value) != VT_BSTR)
|
|
|
|
{
|
2011-06-20 07:25:12 +02:00
|
|
|
VARIANT content;
|
|
|
|
VariantInit(&content);
|
|
|
|
hr = VariantChangeType(&content, &value, 0, VT_BSTR);
|
2010-10-30 17:42:24 +02:00
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
2011-06-20 07:25:12 +02:00
|
|
|
hr = node_set_content(&This->node, V_BSTR(&content));
|
|
|
|
VariantClear(&content);
|
2010-10-30 17:42:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = node_set_content(&This->node, V_BSTR(&value));
|
2012-06-29 09:10:55 +02:00
|
|
|
break;
|
|
|
|
case DT_BIN_BASE64:
|
|
|
|
if (V_VT(&value) == VT_BSTR)
|
|
|
|
hr = node_set_content(&This->node, V_BSTR(&value));
|
|
|
|
else if (V_VT(&value) == (VT_UI1|VT_ARRAY))
|
|
|
|
{
|
|
|
|
UINT dim = SafeArrayGetDim(V_ARRAY(&value));
|
|
|
|
LONG lbound, ubound;
|
|
|
|
BSTR encoded;
|
|
|
|
BYTE *ptr;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (dim > 1)
|
|
|
|
FIXME("unexpected array dimension count %u\n", dim);
|
|
|
|
|
|
|
|
SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
|
|
|
|
SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
|
|
|
|
|
|
|
|
len = (ubound - lbound + 1)*SafeArrayGetElemsize(V_ARRAY(&value));
|
|
|
|
|
|
|
|
hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = encode_base64(ptr, len, &encoded);
|
|
|
|
SafeArrayUnaccessData(V_ARRAY(&value));
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = node_set_content(&This->node, encoded);
|
|
|
|
SysFreeString(encoded);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("unhandled variant type %d for dt:%s\n", V_VT(&value), debugstr_dt(dt));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
break;
|
2012-07-02 07:43:27 +02:00
|
|
|
case DT_BIN_HEX:
|
|
|
|
if (V_VT(&value) == (VT_UI1|VT_ARRAY))
|
|
|
|
{
|
|
|
|
UINT dim = SafeArrayGetDim(V_ARRAY(&value));
|
|
|
|
LONG lbound, ubound;
|
|
|
|
BSTR encoded;
|
|
|
|
BYTE *ptr;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (dim > 1)
|
|
|
|
FIXME("unexpected array dimension count %u\n", dim);
|
|
|
|
|
|
|
|
SafeArrayGetUBound(V_ARRAY(&value), 1, &ubound);
|
|
|
|
SafeArrayGetLBound(V_ARRAY(&value), 1, &lbound);
|
|
|
|
|
|
|
|
len = (ubound - lbound + 1)*SafeArrayGetElemsize(V_ARRAY(&value));
|
|
|
|
|
|
|
|
hr = SafeArrayAccessData(V_ARRAY(&value), (void*)&ptr);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = encode_binhex(ptr, len, &encoded);
|
|
|
|
SafeArrayUnaccessData(V_ARRAY(&value));
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = node_set_content(&This->node, encoded);
|
|
|
|
SysFreeString(encoded);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FIXME("unhandled variant type %d for dt:%s\n", V_VT(&value), debugstr_dt(dt));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
break;
|
2012-06-29 09:10:55 +02:00
|
|
|
default:
|
2011-09-21 16:45:11 +02:00
|
|
|
FIXME("not implemented for dt:%s\n", debugstr_dt(dt));
|
2010-10-30 17:42:24 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_dataType(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-19 01:13:30 +02:00
|
|
|
VARIANT* typename)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-11-23 03:55:54 +01:00
|
|
|
XDR_DT dt;
|
2010-10-19 01:13:30 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, typename);
|
|
|
|
|
2010-11-23 03:55:54 +01:00
|
|
|
if (!typename)
|
|
|
|
return E_INVALIDARG;
|
2010-10-19 01:13:30 +02:00
|
|
|
|
2010-11-23 03:55:54 +01:00
|
|
|
dt = element_get_dt(get_element(This));
|
|
|
|
switch (dt)
|
2010-10-19 01:13:30 +02:00
|
|
|
{
|
2010-11-23 03:55:54 +01:00
|
|
|
case DT_BIN_BASE64:
|
|
|
|
case DT_BIN_HEX:
|
|
|
|
case DT_BOOLEAN:
|
|
|
|
case DT_CHAR:
|
|
|
|
case DT_DATE:
|
|
|
|
case DT_DATE_TZ:
|
|
|
|
case DT_DATETIME:
|
|
|
|
case DT_DATETIME_TZ:
|
|
|
|
case DT_FIXED_14_4:
|
|
|
|
case DT_FLOAT:
|
|
|
|
case DT_I1:
|
|
|
|
case DT_I2:
|
|
|
|
case DT_I4:
|
|
|
|
case DT_I8:
|
|
|
|
case DT_INT:
|
|
|
|
case DT_NUMBER:
|
|
|
|
case DT_R4:
|
|
|
|
case DT_R8:
|
|
|
|
case DT_TIME:
|
|
|
|
case DT_TIME_TZ:
|
|
|
|
case DT_UI1:
|
|
|
|
case DT_UI2:
|
|
|
|
case DT_UI4:
|
|
|
|
case DT_UI8:
|
|
|
|
case DT_URI:
|
|
|
|
case DT_UUID:
|
|
|
|
V_VT(typename) = VT_BSTR;
|
2010-11-23 03:56:31 +01:00
|
|
|
V_BSTR(typename) = SysAllocString(dt_to_bstr(dt));
|
2010-11-23 03:55:54 +01:00
|
|
|
|
|
|
|
if (!V_BSTR(typename))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Other types (DTD equivalents) do not return anything here,
|
|
|
|
* but the pointer part of the VARIANT is set to NULL */
|
|
|
|
V_VT(typename) = VT_NULL;
|
|
|
|
V_BSTR(typename) = NULL;
|
|
|
|
break;
|
2010-10-19 01:13:30 +02:00
|
|
|
}
|
|
|
|
return (V_VT(typename) != VT_NULL) ? S_OK : S_FALSE;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_put_dataType(
|
|
|
|
IXMLDOMElement *iface,
|
2010-11-23 03:57:29 +01:00
|
|
|
BSTR dtName)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-11-23 03:57:29 +01:00
|
|
|
HRESULT hr = E_FAIL;
|
|
|
|
xmlChar *str;
|
|
|
|
XDR_DT dt;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(dtName));
|
|
|
|
|
|
|
|
if(dtName == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
dt = bstr_to_dt(dtName, -1);
|
|
|
|
|
|
|
|
/* An example of this is. The Text in the node needs to be a 0 or 1 for a boolean type.
|
|
|
|
This applies to changing types (string->bool) or setting a new one
|
|
|
|
*/
|
|
|
|
str = xmlNodeGetContent(get_element(This));
|
|
|
|
hr = dt_validate(dt, str);
|
|
|
|
xmlFree(str);
|
|
|
|
|
|
|
|
/* Check all supported types. */
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
switch (dt)
|
|
|
|
{
|
|
|
|
case DT_BIN_BASE64:
|
|
|
|
case DT_BIN_HEX:
|
|
|
|
case DT_BOOLEAN:
|
|
|
|
case DT_CHAR:
|
|
|
|
case DT_DATE:
|
|
|
|
case DT_DATE_TZ:
|
|
|
|
case DT_DATETIME:
|
|
|
|
case DT_DATETIME_TZ:
|
|
|
|
case DT_FIXED_14_4:
|
|
|
|
case DT_FLOAT:
|
|
|
|
case DT_I1:
|
|
|
|
case DT_I2:
|
|
|
|
case DT_I4:
|
|
|
|
case DT_I8:
|
|
|
|
case DT_INT:
|
|
|
|
case DT_NMTOKEN:
|
|
|
|
case DT_NMTOKENS:
|
|
|
|
case DT_NUMBER:
|
|
|
|
case DT_R4:
|
|
|
|
case DT_R8:
|
|
|
|
case DT_STRING:
|
|
|
|
case DT_TIME:
|
|
|
|
case DT_TIME_TZ:
|
|
|
|
case DT_UI1:
|
|
|
|
case DT_UI2:
|
|
|
|
case DT_UI4:
|
|
|
|
case DT_UI8:
|
|
|
|
case DT_URI:
|
|
|
|
case DT_UUID:
|
|
|
|
{
|
|
|
|
xmlAttrPtr attr = xmlHasNsProp(get_element(This), DT_prefix, DT_nsURI);
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
attr = xmlSetNsProp(get_element(This), attr->ns, DT_prefix, dt_to_str(dt));
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmlNsPtr ns = xmlNewNs(get_element(This), DT_nsURI, DT_prefix);
|
|
|
|
if (ns)
|
|
|
|
{
|
|
|
|
attr = xmlNewNsProp(get_element(This), ns, DT_prefix, dt_to_str(dt));
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
xmlAddChild(get_element(This), (xmlNodePtr)attr);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Failed to create Attribute\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ERR("Failed to create Namespace\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2011-09-21 16:45:11 +02:00
|
|
|
FIXME("need to handle dt:%s\n", debugstr_dt(dt));
|
2010-11-23 03:57:29 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_xml(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR* p)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-29 16:27:09 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
|
2012-05-15 09:49:58 +02:00
|
|
|
return node_get_xml(&This->node, TRUE, p);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_transformNode(
|
|
|
|
IXMLDOMElement *iface,
|
2011-02-23 13:03:42 +01:00
|
|
|
IXMLDOMNode *node, BSTR *p)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 13:03:42 +01:00
|
|
|
TRACE("(%p)->(%p %p)\n", This, node, p);
|
|
|
|
return node_transform_node(&This->node, node, p);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_selectNodes(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR p, IXMLDOMNodeList** outList)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 12:42:24 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outList);
|
|
|
|
return node_select_nodes(&This->node, p, outList);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_selectSingleNode(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR p, IXMLDOMNode** outNode)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-23 12:44:20 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), outNode);
|
|
|
|
return node_select_singlenode(&This->node, p, outNode);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_parsed(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-24 22:55:04 +02:00
|
|
|
VARIANT_BOOL* isParsed)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-24 22:55:04 +02:00
|
|
|
FIXME("(%p)->(%p) stub!\n", This, isParsed);
|
|
|
|
*isParsed = VARIANT_TRUE;
|
|
|
|
return S_OK;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_namespaceURI(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR* p)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-01-09 21:42:55 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
return node_get_namespaceURI(&This->node, p);
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_prefix(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-31 10:22:53 +01:00
|
|
|
BSTR* prefix)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-31 10:22:53 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, prefix);
|
|
|
|
return node_get_prefix( &This->node, prefix );
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_baseName(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-31 10:39:53 +01:00
|
|
|
BSTR* name)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-18 12:48:13 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-10-31 10:39:53 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, name);
|
|
|
|
return node_get_base_name( &This->node, name );
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_transformNodeToObject(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMNode* domNode, VARIANT var1)
|
|
|
|
{
|
2005-08-22 11:23:52 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-01-06 17:21:02 +01:00
|
|
|
FIXME("(%p)->(%p %s)\n", This, domNode, debugstr_variant(&var1));
|
|
|
|
return E_NOTIMPL;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_get_tagName(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR* p)
|
|
|
|
{
|
2005-08-11 12:57:58 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
|
|
|
xmlNodePtr element;
|
2010-02-19 16:06:17 +01:00
|
|
|
const xmlChar *prefix;
|
|
|
|
xmlChar *qname;
|
2005-08-11 12:57:58 +02:00
|
|
|
|
2010-02-17 07:40:40 +01:00
|
|
|
TRACE("(%p)->(%p)\n", This, p );
|
2005-08-11 12:57:58 +02:00
|
|
|
|
2010-02-19 16:06:17 +01:00
|
|
|
if (!p) return E_INVALIDARG;
|
|
|
|
|
2005-08-18 12:48:13 +02:00
|
|
|
element = get_element( This );
|
2005-08-11 12:57:58 +02:00
|
|
|
if ( !element )
|
|
|
|
return E_FAIL;
|
|
|
|
|
2010-02-19 16:06:17 +01:00
|
|
|
prefix = element->ns ? element->ns->prefix : NULL;
|
|
|
|
qname = xmlBuildQName(element->name, prefix, NULL, 0);
|
2005-08-11 12:57:58 +02:00
|
|
|
|
2010-02-19 16:06:17 +01:00
|
|
|
*p = bstr_from_xmlChar(qname);
|
|
|
|
if (qname != element->name) xmlFree(qname);
|
|
|
|
|
|
|
|
return *p ? S_OK : E_OUTOFMEMORY;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_getAttribute(
|
|
|
|
IXMLDOMElement *iface,
|
2006-01-14 17:05:32 +01:00
|
|
|
BSTR name, VARIANT* value)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2006-01-14 17:05:32 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
|
|
|
xmlNodePtr element;
|
2008-02-01 10:45:02 +01:00
|
|
|
xmlChar *xml_name, *xml_value = NULL;
|
2008-01-14 11:13:01 +01:00
|
|
|
HRESULT hr = S_FALSE;
|
2006-01-14 17:05:32 +01:00
|
|
|
|
2010-02-17 07:40:40 +01:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(name), value);
|
2006-01-14 17:05:32 +01:00
|
|
|
|
2008-01-14 11:13:01 +01:00
|
|
|
if(!value || !name)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2006-01-14 17:05:32 +01:00
|
|
|
element = get_element( This );
|
|
|
|
if ( !element )
|
|
|
|
return E_FAIL;
|
|
|
|
|
2008-01-14 11:13:01 +01:00
|
|
|
V_BSTR(value) = NULL;
|
|
|
|
V_VT(value) = VT_NULL;
|
|
|
|
|
2011-03-10 20:15:09 +01:00
|
|
|
xml_name = xmlchar_from_wchar( name );
|
2008-02-01 10:45:02 +01:00
|
|
|
|
|
|
|
if(!xmlValidateNameValue(xml_name))
|
|
|
|
hr = E_FAIL;
|
|
|
|
else
|
|
|
|
xml_value = xmlGetNsProp(element, xml_name, NULL);
|
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free(xml_name);
|
2006-01-14 17:05:32 +01:00
|
|
|
if(xml_value)
|
|
|
|
{
|
|
|
|
V_VT(value) = VT_BSTR;
|
|
|
|
V_BSTR(value) = bstr_from_xmlChar( xml_value );
|
|
|
|
xmlFree(xml_value);
|
|
|
|
hr = S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_setAttribute(
|
|
|
|
IXMLDOMElement *iface,
|
2006-01-16 20:42:39 +01:00
|
|
|
BSTR name, VARIANT value)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2006-01-16 20:42:39 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-10-27 18:30:45 +02:00
|
|
|
xmlChar *xml_name, *xml_value, *local, *prefix;
|
2006-01-16 20:42:39 +01:00
|
|
|
xmlNodePtr element;
|
2013-03-14 22:11:45 +01:00
|
|
|
HRESULT hr = S_OK;
|
2006-01-16 20:42:39 +01:00
|
|
|
|
2011-02-22 00:04:02 +01:00
|
|
|
TRACE("(%p)->(%s %s)\n", This, debugstr_w(name), debugstr_variant(&value));
|
2006-01-16 20:42:39 +01:00
|
|
|
|
|
|
|
element = get_element( This );
|
|
|
|
if ( !element )
|
|
|
|
return E_FAIL;
|
|
|
|
|
2013-03-01 06:08:33 +01:00
|
|
|
if (V_VT(&value) != VT_BSTR)
|
2006-01-16 20:42:39 +01:00
|
|
|
{
|
2013-03-01 06:08:33 +01:00
|
|
|
VARIANT var;
|
|
|
|
|
|
|
|
VariantInit(&var);
|
|
|
|
hr = VariantChangeType(&var, &value, 0, VT_BSTR);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
FIXME("VariantChangeType failed\n");
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
xml_value = xmlchar_from_wchar(V_BSTR(&var));
|
|
|
|
VariantClear(&var);
|
2006-01-16 20:42:39 +01:00
|
|
|
}
|
2013-03-01 06:08:33 +01:00
|
|
|
else
|
|
|
|
xml_value = xmlchar_from_wchar(V_BSTR(&value));
|
2006-01-16 20:42:39 +01:00
|
|
|
|
2011-03-10 20:15:09 +01:00
|
|
|
xml_name = xmlchar_from_wchar( name );
|
2006-01-16 20:42:39 +01:00
|
|
|
|
2011-10-27 18:30:45 +02:00
|
|
|
if ((local = xmlSplitQName2(xml_name, &prefix)))
|
|
|
|
{
|
|
|
|
static const xmlChar* xmlnsA = (const xmlChar*)"xmlns";
|
|
|
|
xmlNsPtr ns = NULL;
|
|
|
|
|
|
|
|
/* it's not allowed to modify existing namespace definition */
|
|
|
|
if (xmlStrEqual(prefix, xmlnsA))
|
|
|
|
ns = xmlSearchNs(element->doc, element, local);
|
|
|
|
|
|
|
|
xmlFree(prefix);
|
|
|
|
xmlFree(local);
|
|
|
|
|
|
|
|
if (ns)
|
2014-04-25 22:36:24 +02:00
|
|
|
{
|
|
|
|
int cmp = xmlStrEqual(ns->href, xml_value);
|
|
|
|
heap_free(xml_value);
|
2014-05-06 09:47:46 +02:00
|
|
|
heap_free(xml_name);
|
2014-04-25 22:36:24 +02:00
|
|
|
return cmp ? S_OK : E_INVALIDARG;
|
|
|
|
}
|
2011-10-27 18:30:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!xmlSetNsProp(element, NULL, xml_name, xml_value))
|
2006-01-16 20:42:39 +01:00
|
|
|
hr = E_FAIL;
|
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
heap_free(xml_value);
|
|
|
|
heap_free(xml_name);
|
2006-01-16 20:42:39 +01:00
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_removeAttribute(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR p)
|
|
|
|
{
|
2010-01-18 21:29:21 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
|
|
|
IXMLDOMNamedNodeMap *attr;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2010-03-20 15:24:04 +01:00
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(p));
|
2010-01-18 21:29:21 +01:00
|
|
|
|
|
|
|
hr = IXMLDOMElement_get_attributes(iface, &attr);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
|
|
|
hr = IXMLDOMNamedNodeMap_removeNamedItem(attr, p, NULL);
|
|
|
|
IXMLDOMNamedNodeMap_Release(attr);
|
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_getAttributeNode(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
BSTR p, IXMLDOMAttribute** attributeNode )
|
|
|
|
{
|
2008-07-01 19:47:08 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-11-14 11:48:36 +01:00
|
|
|
xmlChar *local, *prefix, *nameA;
|
|
|
|
HRESULT hr = S_FALSE;
|
2008-07-01 19:47:08 +02:00
|
|
|
xmlNodePtr element;
|
|
|
|
xmlAttrPtr attr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(p), attributeNode);
|
|
|
|
|
2011-11-14 11:48:36 +01:00
|
|
|
element = get_element( This );
|
|
|
|
if (!element) return E_FAIL;
|
|
|
|
|
|
|
|
if (attributeNode) *attributeNode = NULL;
|
|
|
|
|
|
|
|
nameA = xmlchar_from_wchar(p);
|
|
|
|
if (!xmlValidateNameValue(nameA))
|
|
|
|
{
|
|
|
|
heap_free(nameA);
|
2008-12-13 10:12:02 +01:00
|
|
|
return E_FAIL;
|
2011-11-14 11:48:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!attributeNode)
|
|
|
|
{
|
|
|
|
heap_free(nameA);
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2008-12-13 10:12:02 +01:00
|
|
|
|
|
|
|
*attributeNode = NULL;
|
|
|
|
|
2011-11-14 11:48:36 +01:00
|
|
|
local = xmlSplitQName2(nameA, &prefix);
|
2008-07-01 19:47:08 +02:00
|
|
|
|
2011-11-14 11:48:36 +01:00
|
|
|
if (local)
|
|
|
|
{
|
|
|
|
/* try to get namespace for supplied qualified name */
|
|
|
|
xmlNsPtr ns = xmlSearchNs(element->doc, element, prefix);
|
|
|
|
xmlFree(prefix);
|
2008-07-01 19:47:08 +02:00
|
|
|
|
2011-11-14 11:48:36 +01:00
|
|
|
attr = xmlHasNsProp(element, local, ns ? ns->href : NULL);
|
|
|
|
xmlFree(local);
|
|
|
|
}
|
|
|
|
else
|
2008-12-13 10:12:02 +01:00
|
|
|
{
|
2011-11-14 11:48:36 +01:00
|
|
|
attr = xmlHasProp(element, nameA);
|
|
|
|
/* attribute has attached namespace and we requested non-qualified
|
|
|
|
name - it's a failure case */
|
|
|
|
if (attr && attr->ns) attr = NULL;
|
2008-12-13 10:12:02 +01:00
|
|
|
}
|
|
|
|
|
2011-11-14 11:48:36 +01:00
|
|
|
heap_free(nameA);
|
|
|
|
|
|
|
|
if (attr)
|
|
|
|
{
|
|
|
|
IUnknown *unk = create_attribute((xmlNodePtr)attr);
|
2008-07-01 19:47:08 +02:00
|
|
|
hr = IUnknown_QueryInterface(unk, &IID_IXMLDOMAttribute, (void**)attributeNode);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_setAttributeNode(
|
|
|
|
IXMLDOMElement *iface,
|
2010-10-21 00:07:20 +02:00
|
|
|
IXMLDOMAttribute* attribute,
|
|
|
|
IXMLDOMAttribute** old)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2010-02-17 07:40:40 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2011-02-28 00:27:30 +01:00
|
|
|
static const WCHAR xmlnsW[] = {'x','m','l','n','s',0};
|
2010-10-21 00:07:20 +02:00
|
|
|
xmlChar *name, *value;
|
|
|
|
BSTR nameW, prefix;
|
2011-03-03 01:57:01 +01:00
|
|
|
xmlnode *attr_node;
|
2010-10-21 00:07:20 +02:00
|
|
|
xmlAttrPtr attr;
|
|
|
|
VARIANT valueW;
|
|
|
|
HRESULT hr;
|
2010-09-06 21:26:39 +02:00
|
|
|
|
2010-10-21 00:07:20 +02:00
|
|
|
FIXME("(%p)->(%p %p): semi-stub\n", This, attribute, old);
|
2010-09-06 21:26:39 +02:00
|
|
|
|
2010-10-21 00:07:20 +02:00
|
|
|
if (!attribute) return E_INVALIDARG;
|
2010-09-06 21:26:39 +02:00
|
|
|
|
2011-03-03 01:57:01 +01:00
|
|
|
attr_node = get_node_obj((IXMLDOMNode*)attribute);
|
2011-03-03 23:03:15 +01:00
|
|
|
if (!attr_node) return E_FAIL;
|
2011-03-03 01:57:01 +01:00
|
|
|
|
|
|
|
if (attr_node->parent)
|
|
|
|
{
|
|
|
|
WARN("attempt to add already used attribute\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-10-21 00:07:20 +02:00
|
|
|
hr = IXMLDOMAttribute_get_nodeName(attribute, &nameW);
|
|
|
|
if (hr != S_OK) return hr;
|
|
|
|
|
2011-02-28 00:27:30 +01:00
|
|
|
/* adding xmlns attribute doesn't change a tree or existing namespace definition */
|
|
|
|
if (!strcmpW(nameW, xmlnsW))
|
|
|
|
{
|
|
|
|
SysFreeString(nameW);
|
|
|
|
return DISP_E_UNKNOWNNAME;
|
|
|
|
}
|
|
|
|
|
2010-10-21 00:07:20 +02:00
|
|
|
hr = IXMLDOMAttribute_get_nodeValue(attribute, &valueW);
|
|
|
|
if (hr != S_OK)
|
|
|
|
{
|
|
|
|
SysFreeString(nameW);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-02-28 00:27:30 +01:00
|
|
|
if (old) *old = NULL;
|
|
|
|
|
2010-10-21 00:07:20 +02:00
|
|
|
TRACE("attribute: %s=%s\n", debugstr_w(nameW), debugstr_w(V_BSTR(&valueW)));
|
|
|
|
|
|
|
|
hr = IXMLDOMAttribute_get_prefix(attribute, &prefix);
|
|
|
|
if (hr == S_OK)
|
|
|
|
{
|
|
|
|
FIXME("namespaces not supported: %s\n", debugstr_w(prefix));
|
|
|
|
SysFreeString(prefix);
|
|
|
|
}
|
|
|
|
|
2011-03-10 20:15:09 +01:00
|
|
|
name = xmlchar_from_wchar(nameW);
|
|
|
|
value = xmlchar_from_wchar(V_BSTR(&valueW));
|
2010-10-21 00:07:20 +02:00
|
|
|
|
|
|
|
if (!name || !value)
|
|
|
|
{
|
|
|
|
SysFreeString(nameW);
|
|
|
|
VariantClear(&valueW);
|
|
|
|
heap_free(name);
|
|
|
|
heap_free(value);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr = xmlSetNsProp(get_element(This), NULL, name, value);
|
2011-03-03 01:57:01 +01:00
|
|
|
if (attr)
|
|
|
|
attr_node->parent = (IXMLDOMNode*)iface;
|
2010-10-21 00:07:20 +02:00
|
|
|
|
|
|
|
SysFreeString(nameW);
|
|
|
|
VariantClear(&valueW);
|
|
|
|
heap_free(name);
|
|
|
|
heap_free(value);
|
|
|
|
|
|
|
|
return attr ? S_OK : E_FAIL;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_removeAttributeNode(
|
|
|
|
IXMLDOMElement *iface,
|
|
|
|
IXMLDOMAttribute* domAttribute,
|
|
|
|
IXMLDOMAttribute** attributeNode)
|
|
|
|
{
|
2010-02-17 07:40:40 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
|
|
|
FIXME("(%p)->(%p %p)\n", This, domAttribute, attributeNode);
|
2005-08-03 12:58:47 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_getElementsByTagName(
|
|
|
|
IXMLDOMElement *iface,
|
2010-09-02 20:49:56 +02:00
|
|
|
BSTR tagName, IXMLDOMNodeList** resultList)
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2007-05-12 10:09:10 +02:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
2010-11-23 03:59:20 +01:00
|
|
|
xmlChar *query;
|
2007-05-12 10:09:10 +02:00
|
|
|
HRESULT hr;
|
2010-11-23 03:59:20 +01:00
|
|
|
BOOL XPath;
|
2007-05-12 10:09:10 +02:00
|
|
|
|
2010-11-23 03:59:20 +01:00
|
|
|
TRACE("(%p)->(%s, %p)\n", This, debugstr_w(tagName), resultList);
|
2007-05-12 10:09:10 +02:00
|
|
|
|
2010-09-02 20:49:56 +02:00
|
|
|
if (!tagName || !resultList) return E_INVALIDARG;
|
2007-05-12 10:09:10 +02:00
|
|
|
|
2010-11-23 03:59:20 +01:00
|
|
|
XPath = is_xpathmode(get_element(This)->doc);
|
|
|
|
set_xpathmode(get_element(This)->doc, TRUE);
|
|
|
|
query = tagName_to_XPath(tagName);
|
2011-03-13 00:54:47 +01:00
|
|
|
hr = create_selection(get_element(This), query, resultList);
|
2010-11-23 03:59:20 +01:00
|
|
|
xmlFree(query);
|
|
|
|
set_xpathmode(get_element(This)->doc, XPath);
|
2007-05-12 10:09:10 +02:00
|
|
|
|
|
|
|
return hr;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI domelem_normalize(
|
|
|
|
IXMLDOMElement *iface )
|
|
|
|
{
|
2010-02-17 07:40:40 +01:00
|
|
|
domelem *This = impl_from_IXMLDOMElement( iface );
|
|
|
|
FIXME("%p\n", This);
|
2005-08-03 12:58:47 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2005-08-08 17:04:00 +02:00
|
|
|
static const struct IXMLDOMElementVtbl domelem_vtbl =
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
|
|
|
domelem_QueryInterface,
|
|
|
|
domelem_AddRef,
|
|
|
|
domelem_Release,
|
|
|
|
domelem_GetTypeInfoCount,
|
|
|
|
domelem_GetTypeInfo,
|
|
|
|
domelem_GetIDsOfNames,
|
|
|
|
domelem_Invoke,
|
|
|
|
domelem_get_nodeName,
|
|
|
|
domelem_get_nodeValue,
|
|
|
|
domelem_put_nodeValue,
|
|
|
|
domelem_get_nodeType,
|
|
|
|
domelem_get_parentNode,
|
|
|
|
domelem_get_childNodes,
|
|
|
|
domelem_get_firstChild,
|
|
|
|
domelem_get_lastChild,
|
|
|
|
domelem_get_previousSibling,
|
|
|
|
domelem_get_nextSibling,
|
|
|
|
domelem_get_attributes,
|
|
|
|
domelem_insertBefore,
|
|
|
|
domelem_replaceChild,
|
|
|
|
domelem_removeChild,
|
|
|
|
domelem_appendChild,
|
|
|
|
domelem_hasChildNodes,
|
|
|
|
domelem_get_ownerDocument,
|
|
|
|
domelem_cloneNode,
|
|
|
|
domelem_get_nodeTypeString,
|
|
|
|
domelem_get_text,
|
|
|
|
domelem_put_text,
|
|
|
|
domelem_get_specified,
|
|
|
|
domelem_get_definition,
|
|
|
|
domelem_get_nodeTypedValue,
|
|
|
|
domelem_put_nodeTypedValue,
|
|
|
|
domelem_get_dataType,
|
|
|
|
domelem_put_dataType,
|
|
|
|
domelem_get_xml,
|
|
|
|
domelem_transformNode,
|
|
|
|
domelem_selectNodes,
|
|
|
|
domelem_selectSingleNode,
|
|
|
|
domelem_get_parsed,
|
|
|
|
domelem_get_namespaceURI,
|
|
|
|
domelem_get_prefix,
|
|
|
|
domelem_get_baseName,
|
|
|
|
domelem_transformNodeToObject,
|
|
|
|
domelem_get_tagName,
|
|
|
|
domelem_getAttribute,
|
|
|
|
domelem_setAttribute,
|
|
|
|
domelem_removeAttribute,
|
|
|
|
domelem_getAttributeNode,
|
|
|
|
domelem_setAttributeNode,
|
|
|
|
domelem_removeAttributeNode,
|
|
|
|
domelem_getElementsByTagName,
|
|
|
|
domelem_normalize,
|
|
|
|
};
|
|
|
|
|
2011-11-12 22:45:10 +01:00
|
|
|
static HRESULT domelem_get_qualified_item(const xmlNodePtr node, BSTR name, BSTR uri,
|
|
|
|
IXMLDOMNode **item)
|
|
|
|
{
|
|
|
|
xmlAttrPtr attr;
|
|
|
|
xmlChar *nameA;
|
|
|
|
xmlChar *href;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s %p)\n", node, debugstr_w(name), debugstr_w(uri), item);
|
|
|
|
|
|
|
|
if (!name || !item) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (uri && *uri)
|
|
|
|
{
|
|
|
|
href = xmlchar_from_wchar(uri);
|
|
|
|
if (!href) return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
href = NULL;
|
|
|
|
|
|
|
|
nameA = xmlchar_from_wchar(name);
|
|
|
|
if (!nameA)
|
|
|
|
{
|
|
|
|
heap_free(href);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr = xmlHasNsProp(node, nameA, href);
|
|
|
|
|
|
|
|
heap_free(nameA);
|
|
|
|
heap_free(href);
|
|
|
|
|
|
|
|
if (!attr)
|
|
|
|
{
|
|
|
|
*item = NULL;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*item = create_node((xmlNodePtr)attr);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT domelem_get_named_item(const xmlNodePtr node, BSTR name, IXMLDOMNode **item)
|
|
|
|
{
|
|
|
|
xmlChar *nameA, *local, *prefix;
|
|
|
|
BSTR uriW, localW;
|
|
|
|
xmlNsPtr ns;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", node, debugstr_w(name), item );
|
|
|
|
|
|
|
|
nameA = xmlchar_from_wchar(name);
|
|
|
|
local = xmlSplitQName2(nameA, &prefix);
|
|
|
|
heap_free(nameA);
|
|
|
|
|
|
|
|
if (!local)
|
|
|
|
return domelem_get_qualified_item(node, name, NULL, item);
|
|
|
|
|
|
|
|
/* try to get namespace uri for supplied qualified name */
|
|
|
|
ns = xmlSearchNs(node->doc, node, prefix);
|
|
|
|
|
|
|
|
xmlFree(prefix);
|
|
|
|
|
|
|
|
if (!ns)
|
|
|
|
{
|
|
|
|
xmlFree(local);
|
|
|
|
if (item) *item = NULL;
|
|
|
|
return item ? S_FALSE : E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
uriW = bstr_from_xmlChar(ns->href);
|
|
|
|
localW = bstr_from_xmlChar(local);
|
|
|
|
xmlFree(local);
|
|
|
|
|
|
|
|
TRACE("got qualified node %s, uri=%s\n", debugstr_w(localW), debugstr_w(uriW));
|
|
|
|
|
|
|
|
hr = domelem_get_qualified_item(node, localW, uriW, item);
|
|
|
|
|
|
|
|
SysFreeString(localW);
|
|
|
|
SysFreeString(uriW);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT domelem_set_named_item(xmlNodePtr node, IXMLDOMNode *newItem, IXMLDOMNode **namedItem)
|
|
|
|
{
|
|
|
|
xmlNodePtr nodeNew;
|
|
|
|
xmlnode *ThisNew;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", node, newItem, namedItem );
|
|
|
|
|
|
|
|
if(!newItem)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(namedItem) *namedItem = NULL;
|
|
|
|
|
|
|
|
/* Must be an Attribute */
|
|
|
|
ThisNew = get_node_obj( newItem );
|
|
|
|
if(!ThisNew) return E_FAIL;
|
|
|
|
|
|
|
|
if(ThisNew->node->type != XML_ATTRIBUTE_NODE)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if(!ThisNew->node->parent)
|
|
|
|
if(xmldoc_remove_orphan(ThisNew->node->doc, ThisNew->node) != S_OK)
|
|
|
|
WARN("%p is not an orphan of %p\n", ThisNew->node, ThisNew->node->doc);
|
|
|
|
|
|
|
|
nodeNew = xmlAddChild(node, ThisNew->node);
|
|
|
|
|
|
|
|
if(namedItem)
|
|
|
|
*namedItem = create_node( nodeNew );
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT domelem_remove_qualified_item(xmlNodePtr node, BSTR name, BSTR uri, IXMLDOMNode **item)
|
|
|
|
{
|
|
|
|
xmlChar *nameA, *href;
|
|
|
|
xmlAttrPtr attr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s %p)\n", node, debugstr_w(name), debugstr_w(uri), item);
|
|
|
|
|
|
|
|
if (!name) return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (uri && *uri)
|
|
|
|
{
|
|
|
|
href = xmlchar_from_wchar(uri);
|
|
|
|
if (!href) return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
href = NULL;
|
|
|
|
|
|
|
|
nameA = xmlchar_from_wchar(name);
|
|
|
|
if (!nameA)
|
|
|
|
{
|
|
|
|
heap_free(href);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr = xmlHasNsProp(node, nameA, href);
|
|
|
|
|
|
|
|
heap_free(nameA);
|
|
|
|
heap_free(href);
|
|
|
|
|
|
|
|
if (!attr)
|
|
|
|
{
|
|
|
|
if (item) *item = NULL;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
xmlUnlinkNode( (xmlNodePtr) attr );
|
|
|
|
xmldoc_add_orphan( attr->doc, (xmlNodePtr) attr );
|
|
|
|
*item = create_node( (xmlNodePtr) attr );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (xmlRemoveProp(attr) == -1)
|
|
|
|
ERR("xmlRemoveProp failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT domelem_remove_named_item(xmlNodePtr node, BSTR name, IXMLDOMNode **item)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%s %p)\n", node, debugstr_w(name), item);
|
|
|
|
return domelem_remove_qualified_item(node, name, NULL, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT domelem_get_item(const xmlNodePtr node, LONG index, IXMLDOMNode **item)
|
|
|
|
{
|
|
|
|
xmlAttrPtr curr;
|
|
|
|
LONG attrIndex;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d %p)\n", node, index, item);
|
|
|
|
|
|
|
|
*item = NULL;
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
curr = node->properties;
|
|
|
|
|
|
|
|
for (attrIndex = 0; attrIndex < index; attrIndex++) {
|
|
|
|
if (curr->next == NULL)
|
|
|
|
return S_FALSE;
|
|
|
|
else
|
|
|
|
curr = curr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
*item = create_node( (xmlNodePtr) curr );
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT domelem_get_length(const xmlNodePtr node, LONG *length)
|
|
|
|
{
|
|
|
|
xmlAttrPtr first;
|
|
|
|
xmlAttrPtr curr;
|
|
|
|
LONG attrCount;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", node, length);
|
|
|
|
|
|
|
|
if( !length )
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
first = node->properties;
|
|
|
|
if (first == NULL) {
|
|
|
|
*length = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr = first;
|
|
|
|
attrCount = 1;
|
|
|
|
while (curr->next) {
|
|
|
|
attrCount++;
|
|
|
|
curr = curr->next;
|
|
|
|
}
|
|
|
|
*length = attrCount;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT domelem_next_node(const xmlNodePtr node, LONG *iter, IXMLDOMNode **nextNode)
|
|
|
|
{
|
|
|
|
xmlAttrPtr curr;
|
|
|
|
LONG i;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%d: %p)\n", node, *iter, nextNode);
|
|
|
|
|
|
|
|
*nextNode = NULL;
|
|
|
|
|
|
|
|
curr = node->properties;
|
|
|
|
|
|
|
|
for (i = 0; i < *iter; i++) {
|
|
|
|
if (curr->next == NULL)
|
|
|
|
return S_FALSE;
|
|
|
|
else
|
|
|
|
curr = curr->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*iter)++;
|
|
|
|
*nextNode = create_node((xmlNodePtr)curr);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct nodemap_funcs domelem_attr_map = {
|
|
|
|
domelem_get_named_item,
|
|
|
|
domelem_set_named_item,
|
|
|
|
domelem_remove_named_item,
|
|
|
|
domelem_get_item,
|
|
|
|
domelem_get_length,
|
|
|
|
domelem_get_qualified_item,
|
|
|
|
domelem_remove_qualified_item,
|
|
|
|
domelem_next_node
|
|
|
|
};
|
|
|
|
|
2009-08-31 07:18:00 +02:00
|
|
|
static const tid_t domelem_iface_tids[] = {
|
|
|
|
IXMLDOMElement_tid,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static dispex_static_data_t domelem_dispex = {
|
|
|
|
NULL,
|
|
|
|
IXMLDOMElement_tid,
|
|
|
|
NULL,
|
|
|
|
domelem_iface_tids
|
|
|
|
};
|
|
|
|
|
2009-08-22 19:51:45 +02:00
|
|
|
IUnknown* create_element( xmlNodePtr element )
|
2005-08-03 12:58:47 +02:00
|
|
|
{
|
2005-08-10 11:54:22 +02:00
|
|
|
domelem *This;
|
2005-08-03 12:58:47 +02:00
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
This = heap_alloc( sizeof *This );
|
2005-08-10 11:54:22 +02:00
|
|
|
if ( !This )
|
|
|
|
return NULL;
|
2005-08-03 12:58:47 +02:00
|
|
|
|
2010-12-16 01:04:12 +01:00
|
|
|
This->IXMLDOMElement_iface.lpVtbl = &domelem_vtbl;
|
2005-08-10 11:54:22 +02:00
|
|
|
This->ref = 1;
|
2005-08-03 12:58:47 +02:00
|
|
|
|
2010-12-16 01:04:12 +01:00
|
|
|
init_xmlnode(&This->node, element, (IXMLDOMNode*)&This->IXMLDOMElement_iface, &domelem_dispex);
|
2005-12-01 18:46:42 +01:00
|
|
|
|
2010-12-16 01:04:12 +01:00
|
|
|
return (IUnknown*)&This->IXMLDOMElement_iface;
|
2005-08-03 12:58:47 +02:00
|
|
|
}
|
2005-08-08 14:13:31 +02:00
|
|
|
|
|
|
|
#endif
|