Why is loadXML failing?
-
What could be wrong here??? I get the error "Invalid at the top level of the document"; however, loading the exact same text from a file using load() works!
CoInitialize(); CComPtr< IXMLDOMDocument2 > pDocument; pDocument.CoCreateInstance( CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER ); VARIANT_BOOL status; pDocument->loadXML( BSTR( "< ParticleSystem />" ), &status );
-
What could be wrong here??? I get the error "Invalid at the top level of the document"; however, loading the exact same text from a file using load() works!
CoInitialize(); CComPtr< IXMLDOMDocument2 > pDocument; pDocument.CoCreateInstance( CLSID_DOMDocument40, NULL, CLSCTX_INPROC_SERVER ); VARIANT_BOOL status; pDocument->loadXML( BSTR( "< ParticleSystem />" ), &status );
Without checking this out it may be because of the BSTR constructor you are using. BSTR's are unsigned short pointers, while you are passing in a const char* so a pointer cast is probably done (by the compiler) so two characters from your const char will be going into one character of the BSTR ie could be any character!! I suggest you try using CComBSTR, _bstr_t, or SysAllocString (and a matching free) to create your string to parse...
-
Without checking this out it may be because of the BSTR constructor you are using. BSTR's are unsigned short pointers, while you are passing in a const char* so a pointer cast is probably done (by the compiler) so two characters from your const char will be going into one character of the BSTR ie could be any character!! I suggest you try using CComBSTR, _bstr_t, or SysAllocString (and a matching free) to create your string to parse...
Thanks for your help. I finally found that my problem was a combination of two different problems. 1. Here was the real problem: I was loading (as binary) a Unicode file that has a BOM (byte-order mark) at the front of the file. Then I passed the text to loadXML. Apparently, loadXML can't handle Unicode special characters. I consider this a bug in loadXML. 2. In order to test loadXML, I was creating a BSTR like this:
BSTR( "< ParticleSystem />" );
Like you said, the constructor was not converting the string to a Unicode string as I expected it to do. loadXML was able to parse this:BSTR( L"< ParticleSystem />" );
-
Thanks for your help. I finally found that my problem was a combination of two different problems. 1. Here was the real problem: I was loading (as binary) a Unicode file that has a BOM (byte-order mark) at the front of the file. Then I passed the text to loadXML. Apparently, loadXML can't handle Unicode special characters. I consider this a bug in loadXML. 2. In order to test loadXML, I was creating a BSTR like this:
BSTR( "< ParticleSystem />" );
Like you said, the constructor was not converting the string to a Unicode string as I expected it to do. loadXML was able to parse this:BSTR( L"< ParticleSystem />" );
-
Thanks for your help. I finally found that my problem was a combination of two different problems. 1. Here was the real problem: I was loading (as binary) a Unicode file that has a BOM (byte-order mark) at the front of the file. Then I passed the text to loadXML. Apparently, loadXML can't handle Unicode special characters. I consider this a bug in loadXML. 2. In order to test loadXML, I was creating a BSTR like this:
BSTR( "< ParticleSystem />" );
Like you said, the constructor was not converting the string to a Unicode string as I expected it to do. loadXML was able to parse this:BSTR( L"< ParticleSystem />" );
Jambolo wrote: BSTR( L"< ParticleSystem />" ); That is still not correct, you need to make a real
BSTR
or use a wrapper class like_bstr_t
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 released -
Jambolo wrote: BSTR( L"< ParticleSystem />" ); That is still not correct, you need to make a real
BSTR
or use a wrapper class like_bstr_t
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber CP SearchBar v2.0.2 releasedMichael Dunn wrote: Jambolo wrote: BSTR( L"< ParticleSystem />" ); That is still not correct, you need to make a real BSTR or use a wrapper class like _bstr_t Well, it worked just fine, so I'm not convinced. Regardless, I am using
CComBSTR
for the real code, but I will keep that in mind for next time.