?
Solved

Exclamation Marks Inserted into XML

Posted on 2005-03-19
3
Medium Priority
?
703 Views
Last Modified: 2008-02-01
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
Comment
Question by:david_johns
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
novitiate earned 1200 total points
ID: 13581753
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
 
LVL 8

Expert Comment

by:novitiate
ID: 13581756
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
 

Author Comment

by:david_johns
ID: 13581765
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question