How do I extract a hexBinary attribute value?
XML / XSL
1
Posts
1
Posters
0
Views
1
Watching
-
I wrote a function that gets a attribute value that is in hex. Am I reinventing the wheel? The problem is that I can't get it to work. Here was my first attempt which failed because it didn't convert to hex (even though the the type is xsd:hexBinary):
HRESULT hr; CComVariant value; hr = pElement->getAttribute( CComBSTR( sName ), &value ); hr = value.ChangeType( VT\_UINT );
Here is my second attempt which works for values using digits '0'-'9' but fails for values using digits 'a'-'f' (and 'A'-'F') (VarParseNumFromStr returns DISP_E_TYPEMISMATCH):
HRESULT hr; CComVariant value; NUMPARSE np = { 10, NUMPRS\_HEX\_OCT|NUMPRS\_USE\_ALL, 0, 0, 4 }; unsigned char digits\[10\]; CComVariant vHex; hr = pElement->getAttribute( CComBSTR( sName ), &value ); hr = VarParseNumFromStr( value.bstrVal, GetUserDefaultLCID(), NUMPRS\_HEX\_OCT|NUMPRS\_USE\_ALL, &np, digits ); np.nBaseShift = 4; hr = VarNumFromParseNum( &np, digits, VTBIT\_UI4, &vHex ); hr = vHex.ChangeType( VT\_UINT );
Anyone know what is wrong or what the right way to do this is?