• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 707
  • Last Modified:

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
0
david_johns
Asked:
david_johns
  • 2
1 Solution
 
novitiateCommented:
David,

Is there any specific using the IStream and save method. Since you 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 this...
CString XMLtoCString(MSXML2::IXMLDOMDocument *pDoc)
{
     BSTR xml;
     pDoc->get_xml(&xml);
     return CString(xml);
}
0
 
novitiateCommented:
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_
0
 
david_johnsAuthor Commented:
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
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now