From d9fc6985fae076f1ee7952f010c81f8c8b11de87 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Sat, 14 Jan 2006 17:05:32 +0100 Subject: [PATCH] msxml: Implement getAttribute. --- dlls/msxml3/element.c | 28 +++++++++++++++++++++++++--- dlls/msxml3/tests/domdoc.c | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/dlls/msxml3/element.c b/dlls/msxml3/element.c index 194ea899d14..38c359107fa 100644 --- a/dlls/msxml3/element.c +++ b/dlls/msxml3/element.c @@ -454,10 +454,32 @@ static HRESULT WINAPI domelem_get_tagName( static HRESULT WINAPI domelem_getAttribute( IXMLDOMElement *iface, - BSTR p, VARIANT* var) + BSTR name, VARIANT* value) { - FIXME("\n"); - return E_NOTIMPL; + domelem *This = impl_from_IXMLDOMElement( iface ); + xmlNodePtr element; + xmlChar *xml_name, *xml_value; + HRESULT hr = E_FAIL; + + TRACE("(%p)->(%s,%p)\n", This, debugstr_w(name), value); + + element = get_element( This ); + if ( !element ) + return E_FAIL; + + VariantInit(value); + xml_name = xmlChar_from_wchar( name ); + xml_value = xmlGetNsProp(element, xml_name, NULL); + HeapFree(GetProcessHeap(), 0, xml_name); + if(xml_value) + { + V_VT(value) = VT_BSTR; + V_BSTR(value) = bstr_from_xmlChar( xml_value ); + xmlFree(xml_value); + hr = S_OK; + } + + return hr; } static HRESULT WINAPI domelem_setAttribute( diff --git a/dlls/msxml3/tests/domdoc.c b/dlls/msxml3/tests/domdoc.c index 74b96ec3d52..098b4283c28 100644 --- a/dlls/msxml3/tests/domdoc.c +++ b/dlls/msxml3/tests/domdoc.c @@ -71,6 +71,7 @@ static const WCHAR szOpen[] = { 'o','p','e','n',0 }; static const WCHAR szdl[] = { 'd','l',0 }; static const WCHAR szlc[] = { 'l','c',0 }; static const WCHAR szbs[] = { 'b','s',0 }; +static const WCHAR szstr1[] = { 's','t','r','1',0 }; void test_domdoc( void ) { @@ -312,6 +313,25 @@ void test_domnode( void ) ok( !lstrcmpW( str, szlc ), "incorrect nodeName\n"); SysFreeString( str ); + str = SysAllocString( szNonExistentFile ); + V_VT(&var) = VT_I4; + V_I4(&var) = 0x1234; + r = IXMLDOMElement_getAttribute( element, str, &var ); + ok( r == E_FAIL, "getAttribute ret %08lx\n", r ); + ok( V_VT(&var) == VT_EMPTY, "vt = %x\n", V_VT(&var)); + VariantClear(&var); + SysFreeString( str ); + + str = SysAllocString( szdl ); + V_VT(&var) = VT_I4; + V_I4(&var) = 0x1234; + r = IXMLDOMElement_getAttribute( element, str, &var ); + ok( r == S_OK, "getAttribute ret %08lx\n", r ); + ok( V_VT(&var) == VT_BSTR, "vt = %x\n", V_VT(&var)); + ok( !lstrcmpW(V_BSTR(&var), szstr1), "wrong attr value\n"); + VariantClear( &var ); + SysFreeString( str ); + r = IXMLDOMElement_get_attributes( element, &map ); ok( r == S_OK, "get_attributes returned wrong code\n"); ok( map != NULL, "should be attributes\n");