Title: Message
A few comments that probably have nothing to do with your problem:
 
- ParseDocument() allocates two objects (memBufIS and domParser) that it never releases. These objects are leaked. Not good.
- X(CString, CString) would be unnecessary if you changed X(char*, char*) to X(const char *, const char *). Since CString provides a conversion to const char *, the compiler can automatically provide the cast. This should be safe, since MemBufInputSource takes a const pointer. This approach is slightly more efficient, but more important, it is more direct and therefore easier to understand and maintain. Make the cast explicit if you're worried that it won't be obvious what function gets called because there's no X() that takes CStrings.
 
I don't see a call to XMLPlatformUtils::Initialize() in your excerpt. If you don't have one in your actual code, Xerces' behavior is undefined.
-----Original Message-----
From: Jimmy Yu [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 03, 2004 2:41 PM
To: [EMAIL PROTECTED]
Subject: MemBufInputSource with CString

Hello,
 
I have a question in regards to CString in usage with MemBufInputSource.
 
Here is an example of my code:
 
DOMDocument* ParseDocument(char *membuffer)
{
   MemBufInputSource *memBufIS = new MemBufInputSource((const XMLByte*)mem, strlen(mem), gMemBufId, false);
   XercesDOMParser *domParser  = new XercesDOMParser;
 
   domParser->parse(*memBufIS);
   return(domParser->getDocument());
}
 
and further down in my code I would have:
void X(CString setting, CString changeval)
{
   X(setting.GetBuffer(0), changeval.GetBuffer(0));
}
 
void X(char *setting, char *changeval)
{
   DOMDocument *foo = ParseDocument(setting);
   DOMDocument *goo = ParseDocument(changeval);
   // do something with the documents...
}
 
The above code becomes a lib file. in my main program, I would
include the lib in my project and have the hpp file included in my
main.cpp file. This becomes an exe.
 
Here is my problem during my testing phase....
void main(int argc, char *argv[]
{
   CString foo = "<valid xml here />\n\
                   <valid xml here/>\n\
                  ....
                 <valid xml here/>";
 
   CString goo = "<valid xml here />\n\
                   <valid xml here/>\n\
                  ....
                 <valid xml here/>";
 
   // this call crashes..
   // foo gets parsed ok, but goo would crash at
   // MemBufInputSource = new MemBufInputSource(...) call...
   X(foo, goo); 
 
   // this call does not crash...
   X(foo.GetBuffer(0), goo.GetBUffer(0)) <-- this would work perfectly...
}
 
Is this caused by my lack of understanding of CString? or is this actually a possible bug with Xerces?
 
Sincerely
-- Jimmy
________________________________________________
The meek shall inherit the earth, but not the mineral rights.
- J. Paul Getty

Reply via email to