As Lei
pointed out, the XercesDOMParser destructor will destroy its DOMDocument by
default. You can prevent this by adopting the document - call adoptDocument()
instead of getDocument(). Once you do this, you're responsible for calling
release() to destroy the document once you're through with
it.
Lei
also raises a good point about character types. Technically, you're guaranteed
to be able to cast a CString to const char * only when using single-byte
characters. If you compile with Unicode support, a CString will be composed of
wide characters, and no cast to const char * will be available. In its place is
a cast to const wchar_t *. You can make your code work regardless of how it's
compiled by:
-
Using CStringA instead of CString. CStringA always uses single-byte characters,
so the const char * cast is always available.
-
Using TCHAR rather than char. A TCHAR is always the size of a CString
character, so a cast from CString to const TCHAR * is always available. If you
go this route, you'll want to use the generic-text routines (such as _tcslen)
rather than locking into the ANSI versions (such as strlen) and declare string
constants as _T("constant") rather than "constant". This approach takes slightly
more work but is more forward-looking (since it allows for the possibility of
processing non-ANSI text).
Of
course, this assumes that there is some reason you have to use CString (which
comes with some overhead). As Lei pointed out, a character pointer would suffice
in the example code you sent. It's still worth considering TCHAR instead of
char.
|
Title: Message
- MemBufInputSource with CString Jimmy Yu
- RE: MemBufInputSource with CString Jesse Pelton
- Re: MemBufInputSource with CString Jimmy Yu
- Re: MemBufInputSource with CString jiang lei
- Re: MemBufInputSource with CString Jesse Pelton
- Re: MemBufInputSource with CString Jimmy Yu
- RE: MemBufInputSource with CString Chaudhuri, Hiran
- RE: MemBufInputSource with CString Alberto Massari
- RE: MemBufInputSource with CString Chaudhuri, Hiran
- Re: MemBufInputSource with CString jiang lei
- RE: MemBufInputSource with CString Chaudhuri, Hiran