Link to home
Start Free TrialLog in
Avatar of david_johns
david_johns

asked on

Exclamation Marks Inserted into XML

Experts,

I have a routine that sends xml data to a server for processing.  I generate the xml using MSXML routines.  After generating it I convert the xml to a CString using the code below.  We have one customer that is having problems with "!"s randomly getting added to the xml at any point of the xml.  It has shown up in the node names, the node values,...it seems to be able to show up anywhere in the code.  Any ideas where this would come from?

CString XMLtoCString(MSXML2::IXMLDOMDocument *pDoc)
{
      CString text;
      IStream *pStream=NULL;
      IUnknown *pUnknown=NULL;
      VARIANT varSaveTo;
      ULARGE_INTEGER nSize;
      LARGE_INTEGER nBeg;

      bool bReturn=true;

      
      if(!pDoc) return false;

      try{
            if(CreateStreamOnHGlobal(NULL, true, &pStream)!=S_OK) throw false;
            if(pStream->QueryInterface(IID_IUnknown, (void**)&pUnknown)!=S_OK) throw false;

            varSaveTo.vt = VT_UNKNOWN;
            varSaveTo.punkVal = pUnknown;

            if(pDoc->save(varSaveTo)!=S_OK) throw false;

            LARGE_INTEGER pos;
            pos.QuadPart = 0;

            //the key is to reset the seek pointer

            nBeg.QuadPart = 0;
            pStream->Seek(nBeg, STREAM_SEEK_END, &nSize);
            pStream->Seek(nBeg, STREAM_SEEK_SET, NULL);

            pStream->Read(text.GetBufferSetLength((int) nSize.QuadPart), (unsigned long) nSize.QuadPart, NULL);
            text.ReleaseBuffer();
      }catch(bool bError){
            bReturn = bError;
      }

      if(pStream) pStream->Release();
      if(pUnknown) pUnknown->Release();

      return text;
}

Thanks,
David
ASKER CERTIFIED SOLUTION
Avatar of novitiate
novitiate

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of novitiate
novitiate

David,

Is there any specific reason for using the IStream and save method. Since xml in text format is available as a property of document.

For more refer.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/xmproxml.asp

it can be as simple as, some thing like this...
CString XMLtoCString(MSXML2::IXMLDOMDocument *pDoc)
{
     BSTR xml;
     pDoc->get_xml(&xml);
     return CString(xml);
}

_novi_
Avatar of david_johns

ASKER

Novitiate,

You kow, right after I pasted the code I changed it to doing that.  I am not sure why I did it this round about way in the first place, but I can't think that there was any good reason.

Thanks,
David