Using MSXML from C++
-
Not sure if this is the right place to post, but... I am trying to read and write attributes from a DOM. The attributes are of type base64Binary, and I am using IXMLDOMElement::setAttribute(BSTR, VARIANT). How to I package/assign binary data (currently a CDWordArray, but I'm very flexible!!) into/from the variant? Thanks!!!
-
Not sure if this is the right place to post, but... I am trying to read and write attributes from a DOM. The attributes are of type base64Binary, and I am using IXMLDOMElement::setAttribute(BSTR, VARIANT). How to I package/assign binary data (currently a CDWordArray, but I'm very flexible!!) into/from the variant? Thanks!!!
Using BSTR, Variant should be fine but keep in mind that the memory block you are writting to the document must be compliant with allowed characters. This is espcially true with using the attribute data blocks vs a CData section. Just think of handling the transmission over a http connection. You would have to encode/decode the data. The same concept can apply here. Encode the binary into a string and set it to be the attribute value is one path I have used for smaller sets of information. "I will find a new sig someday."
-
Using BSTR, Variant should be fine but keep in mind that the memory block you are writting to the document must be compliant with allowed characters. This is espcially true with using the attribute data blocks vs a CData section. Just think of handling the transmission over a http connection. You would have to encode/decode the data. The same concept can apply here. Encode the binary into a string and set it to be the attribute value is one path I have used for smaller sets of information. "I will find a new sig someday."
Thanks, no one seems to know much about this..... I have no experiance with http connections/communictions. Is it possible for you to dumb it down a bit? Encoding/decoding to me means stripping out the " ", "<", ">" etc characters, and replacing them when reading. Is this true? Are you aware of any functions available that will do this for me? I've found http://www.codeproject.com/internet/mimesniffer.asp Is this the sort of thing I should be using? My data will typically go to 20 to 30 attributes, each of which will be less than 1 KByte.
-
Thanks, no one seems to know much about this..... I have no experiance with http connections/communictions. Is it possible for you to dumb it down a bit? Encoding/decoding to me means stripping out the " ", "<", ">" etc characters, and replacing them when reading. Is this true? Are you aware of any functions available that will do this for me? I've found http://www.codeproject.com/internet/mimesniffer.asp Is this the sort of thing I should be using? My data will typically go to 20 to 30 attributes, each of which will be less than 1 KByte.
Here is some code I did awhile back. You need to remove nondisplay as well as conflicting characters from the display. CString EnCodeStr(CString ToCode) { CString RetStr,AddStr; int i,max; unsigned short asc; unsigned char c; max = (unsigned int)ToCode.GetLength(); // For binary you need to send the length, The block could have zeros for(i=0;i47 && asc<58) { RetStr+=c; } else if(asc>64 && asc<91) { RetStr+=c; } else if(asc>96 && asc<123) { RetStr+=c; } else if(asc==32) { RetStr+="+"; } else { AddStr.Format("%%%02x",asc); RetStr+=AddStr; } } return RetStr; } CString DeCodeStr(CString ToCode) { CString RetStr,AddStr; int i,max; unsigned short asc; unsigned char c; max = (unsigned int)ToCode.GetLength(); for(i=0;i_"I will find a new sig someday."_
-
Here is some code I did awhile back. You need to remove nondisplay as well as conflicting characters from the display. CString EnCodeStr(CString ToCode) { CString RetStr,AddStr; int i,max; unsigned short asc; unsigned char c; max = (unsigned int)ToCode.GetLength(); // For binary you need to send the length, The block could have zeros for(i=0;i47 && asc<58) { RetStr+=c; } else if(asc>64 && asc<91) { RetStr+=c; } else if(asc>96 && asc<123) { RetStr+=c; } else if(asc==32) { RetStr+="+"; } else { AddStr.Format("%%%02x",asc); RetStr+=AddStr; } } return RetStr; } CString DeCodeStr(CString ToCode) { CString RetStr,AddStr; int i,max; unsigned short asc; unsigned char c; max = (unsigned int)ToCode.GetLength(); for(i=0;i_"I will find a new sig someday."_
-
That sample's great, thanks. My main concern was what you meant by coding and encoding. If that's good enough then fantastic!!!! thanks again.
Glad it helped. Take care. "I will find a new sig someday."
-
Not sure if this is the right place to post, but... I am trying to read and write attributes from a DOM. The attributes are of type base64Binary, and I am using IXMLDOMElement::setAttribute(BSTR, VARIANT). How to I package/assign binary data (currently a CDWordArray, but I'm very flexible!!) into/from the variant? Thanks!!!
Maybe I am missing what Michael is getting at but I don't think he is entirely correct. The base64Binary datatype by definition doesn't require any replacements to be legal in an xml document as when it is encoded it uses the characters 0-9 a-z A-Z '+' '/' ie no replacements required see section 6.8 of http://www.ietf.org/rfc/rfc2045.txt for details (this page is linked to by the Schema spec). Also be aware that most XML DOM do translations required ie you set strings containing '>' '&' etc and they will automatically be converted on output to < and &, however I'm not sure if this is the case for binary types. If possible I would be tempted to use the hexBinary datatype as I find that easier to understand, two characters (0-9 a-f) are used to represent each hex octet ie 0x7f10 would be "7f10" in your XML doc. Hope I haven't confused you...
-
Maybe I am missing what Michael is getting at but I don't think he is entirely correct. The base64Binary datatype by definition doesn't require any replacements to be legal in an xml document as when it is encoded it uses the characters 0-9 a-z A-Z '+' '/' ie no replacements required see section 6.8 of http://www.ietf.org/rfc/rfc2045.txt for details (this page is linked to by the Schema spec). Also be aware that most XML DOM do translations required ie you set strings containing '>' '&' etc and they will automatically be converted on output to < and &, however I'm not sure if this is the case for binary types. If possible I would be tempted to use the hexBinary datatype as I find that easier to understand, two characters (0-9 a-f) are used to represent each hex octet ie 0x7f10 would be "7f10" in your XML doc. Hope I haven't confused you...
No, that makes a bit more sense to me, and sounds easier to implement and check. Is there an easy way to convert the 0x7f10 to "7f10"? sprintf("%08h", intArray[0]) is OK for an int, but a bit tedious for arrays. Is there a "short cut" here, or am I stuck with a loop? Being able to calculate the length of the final string from the input string seems to me like a major advantage over Michael's code.
-
Maybe I am missing what Michael is getting at but I don't think he is entirely correct. The base64Binary datatype by definition doesn't require any replacements to be legal in an xml document as when it is encoded it uses the characters 0-9 a-z A-Z '+' '/' ie no replacements required see section 6.8 of http://www.ietf.org/rfc/rfc2045.txt for details (this page is linked to by the Schema spec). Also be aware that most XML DOM do translations required ie you set strings containing '>' '&' etc and they will automatically be converted on output to < and &, however I'm not sure if this is the case for binary types. If possible I would be tempted to use the hexBinary datatype as I find that easier to understand, two characters (0-9 a-f) are used to represent each hex octet ie 0x7f10 would be "7f10" in your XML doc. Hope I haven't confused you...
Thanks for correcting this. I guess I have been working to long. I totally over looked base64Binary was mentioned and just read a binary memory block in a BSTR field. Take Care. "I will find a new sig someday."