Skip to main content
GameDev.net gamedev.net
🔒 Locked

Parsing XML as String

Started by fathom88 Jan 23, 2007 at 1:16 PM 2 replies 550+ views
Original Post
fathom88
fathom88
A client is sending me XML messages. I read the messages into a string buffer. I would like to parse the string directly. However, I'm running into problems. char Buffer[256]; ... ... Buffer is loaded w/ xml message ... VARIANT_BOOL result; _bstr_t *Temp = NULL; HRESULT hr; BSTR MyBSTR; Temp = new _bstr_t(Buffer); if(Temp != NULL) { MyBSTR = Temp->Detach(); hr = pXmlDoc->loadXML( MyBSTR,&result); } I get an access violation error when I run. I must be doing something wrong at the BSTRs. Could someone point me in the right direction. I've parsed files before, but I don't want to save my buffer to a file and reload as a document. Thanks.
TheTroll
TheTroll
Not sure exactly what you are doing, but I would suggest you look into the .net intity XmlTextReader class. Would save you a lot of headaches.

theTroll
IndyJones
IndyJones
Where do you get the access violation error (if you run in debug mode the debugger should break at the location causing the error).
Do you have to provide a BSTR to the loadXML method? What XML processing API do you use?
Also - you are leaking memory (you never free _bstr_t and if you Detach the BSTR from Temp you will also have to free that string using SysFreeString).
fathom88
fathom88
I use this to define my Xml Doc.

MSXML2::IXMLDOMDocument *pXmlDoc;


Yes, I need to send it a BSTR. It would be a lot easier, if I could load it as char string. I also noticed something strange. The BSTR does not contain my entire char string buffer. This seems like a real pain. I've used this technique before on XML files. Thanks anyways. I think I might be better off just parsing the messages w/ the CString.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.