This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > May 2007 > Binary data from _variant_t to MSXML DOM node





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Binary data from _variant_t to MSXML DOM node
vessep@gmail.com

2007-04-11, 6:17 am

Hi,

I have a function that returns a _variant_t value. It's API
documentation says "this property returns file data as an array of
bytes", and the return value contains contents of a file (may be a
text or binary file). I'd like to place that data in bin.base64-
encoded format to a XML node, but I have not yet succeeded. I've
tried:

MSXML2::IXMLDOMNodePtr node = domDocument-
>createNode(MSXML2::NODE_ELEMENT, "datanode", "");

node->put_dataType(_bstr_t("bin.base64"));
_variant_t data = att->GetData();
node->node->put_nodeTypedValue(data);

And:

VARIANT var;
VariantInit(&var);
var.vt = (VT_ARRAY | VT_UI1);
var = data.Detach();
node->node->put_nodeTypedValue(var);

And:

_variant_t data = att->GetData();
_bstr_t foo = data;
SAFEARRAY* sa = SafeArrayCreateVector(VT_UI1, 0L, att->GetFileSize());
VectorFromBstr(foo, &sa);
VARIANT var;
VariantInit(&var);
var.parray = sa;
var.vt = (VT_ARRAY|VT_UI1);
node->put_nodeTypedValue(var);

None of these work. The last one works if the file is a text file, if
it's a binary, only a few bytes appear. It is the only way I've gotten
anything to appear on the resulting XML (excluding the examples that
read the data from a file).

How could I store the received data?

S. Huseyin Ulger

2007-04-11, 10:16 pm

Unfortunately, you need to convert your bytes into base64 format yourself.
MSXML does not provide such a funtionality. You can then store the result as
text in your XML file.

--
S. Huseyin Ulger [MSFT]
MSXML Dev


"vessep@XXXXXXXXXX" wrote:

> Hi,
>
> I have a function that returns a _variant_t value. It's API
> documentation says "this property returns file data as an array of
> bytes", and the return value contains contents of a file (may be a
> text or binary file). I'd like to place that data in bin.base64-
> encoded format to a XML node, but I have not yet succeeded. I've
> tried:
>
> MSXML2::IXMLDOMNodePtr node = domDocument-
> node->put_dataType(_bstr_t("bin.base64"));
> _variant_t data = att->GetData();
> node->node->put_nodeTypedValue(data);
>
> And:
>
> VARIANT var;
> VariantInit(&var);
> var.vt = (VT_ARRAY | VT_UI1);
> var = data.Detach();
> node->node->put_nodeTypedValue(var);
>
> And:
>
> _variant_t data = att->GetData();
> _bstr_t foo = data;
> SAFEARRAY* sa = SafeArrayCreateVector(VT_UI1, 0L, att->GetFileSize());
> VectorFromBstr(foo, &sa);
> VARIANT var;
> VariantInit(&var);
> var.parray = sa;
> var.vt = (VT_ARRAY|VT_UI1);
> node->put_nodeTypedValue(var);
>
> None of these work. The last one works if the file is a text file, if
> it's a binary, only a few bytes appear. It is the only way I've gotten
> anything to appear on the resulting XML (excluding the examples that
> read the data from a file).
>
> How could I store the received data?
>
>

vessep@gmail.com

2007-04-12, 3:17 am

On 12 huhti, 02:50, S. Huseyin Ulger <ulger@(dontspam).microsoft.com>
wrote:
> Unfortunately, you need to convert your bytes into base64 format yourself.
> MSXML does not provide such a funtionality. You can then store the result as
> text in your XML file.


Hi,

Is it really so? E.g. in this example a file is stored using MSXML:
http://www.perfectxml.com/msxmlAnswers.asp?Row_ID=117

Neil Smith [MVP Digital Media]

2007-04-12, 6:17 pm

On 11 Apr 2007 23:33:31 -0700, vessep@XXXXXXXXXX wrote:

>On 12 huhti, 02:50, S. Huseyin Ulger <ulger@(dontspam).microsoft.com>
>wrote:
>
>Hi,
>
>Is it really so? E.g. in this example a file is stored using MSXML:
>http://www.perfectxml.com/msxmlAnswers.asp?Row_ID=117



Yes, and if you'd read past the first line you'd have seen "download a
sample C++ project that illustrates converting a disk file to base64
encoded XML"

Sheesh.
Cheers - Neil
------------------------------------------------
Digital Media MVP : 2004-2007
http://mvp.support.microsoft.com/mvpfaqs
vessep@gmail.com

2007-04-13, 3:24 am

On 12 huhti, 20:47, "Neil Smith [MVP Digital Media]" <n...@nospam.com>
wrote:

> Yes, and if you'd read past the first line you'd have seen "download a
> sample C++ project that illustrates converting a disk file to base64
> encoded XML"


I actually did read the whole example, and many others while trying to
solve this - unfortunately, many examples say something like "You can
also use the Microsoft Parser DLL (MSXML.DLL) to do base64 encoding
and decoding". I resolved the problem the same way eventully, that is
by downloading the file and then reading it as it was read in that
example. However, I still don't know that where did I manually convert
the file to base64, and don't even really care since it works now.

_bstr_t clientPath = "";
att->Load(-1, &clientPath.GetBSTR());
std::string filename = att->GetFileName();
std::ifstream fd;
fd.open(filename.c_str(), std::ios::binary);
fd.seekg(std::ios::beg);
SAFEARRAY* sa = SafeArrayCreateVector( VT_UI1, 0L, att-
>GetFileSize());

fd.read((char*)sa->pvData, att->GetFileSize());
fd.close();
VARIANT var;
VariantInit(&var);
var.parray = sa;
var.vt = (VT_ARRAY|VT_UI1);
node->put_nodeTypedValue(var);

vessep@gmail.com

2007-04-13, 3:24 am

On 12 huhti, 20:47, "Neil Smith [MVP Digital Media]" <n...@nospam.com>
wrote:

> Yes, and if you'd read past the first line you'd have seen "download a
> sample C++ project that illustrates converting a disk file to base64
> encoded XML"


And by the way, if you'd read my original post, you'd have noticed
that I had already tried to fit that solution to my problem. I just
couldn't figure out which part did what since MS has decided to invent
it's own datatypes but forgot to document those.

> Sheesh.


Indeed.


Neil Smith [MVP Digital Media]

2007-04-13, 6:16 pm

On 13 Apr 2007 00:17:23 -0700, vessep@XXXXXXXXXX wrote:

>On 12 huhti, 20:47, "Neil Smith [MVP Digital Media]" <n...@nospam.com>
>wrote:
>
>
>And by the way, if you'd read my original post, you'd have noticed
>that I had already tried to fit that solution to my problem. I just
>couldn't figure out which part did what since MS has decided to invent
>it's own datatypes but forgot to document those.



But MS hasn't "invented its own datatypes" here

Base64 encoding is well known and has been around almost as long as
email attachments, since it's one of a few schemes which can reliably
be transmitted even through very old (EBDIC) characterset based mail
systems.

It's equally prevalent as the encoding scheme for usenet attachments
on newsgroups, and in XML it contains no characters which would
require using CDATA sections to encode the content.

The downside is, it takes 25% more space than the equivalent 8-bit
binary data, that's because full range 8 bit data can't be used in
XML since it may contain characters in ranges not allowable in XML
content.

Cheers - Neil
------------------------------------------------
Digital Media MVP : 2004-2007
http://mvp.support.microsoft.com/mvpfaqs
Sam Hobbs

2007-05-14, 6:16 pm

"Neil Smith [MVP Digital Media]" <neil@nospam.com> wrote in message
news:r8iv13pe7651jb8rannaraue3f6cc9u26u@4ax.com...
>
> Base64 encoding is well known


http://rfc-ref.org/RFC-TEXTS/2045/chapter6.html#sub8


Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews