Beispiel #1
0
// returns true if clipboard turns out to be XML
bool IsClipboardXML (void)
  {
CString strContents; 

  if (!GetClipboardContents (strContents, false, false))
    return false;

// see if base64 encoded

  SeeIfBase64 (strContents);

  CMemFile f ((unsigned char *) (const char *) strContents, strContents.GetLength ());
  CArchive ar (&f, CArchive::load);
  
  if (IsArchiveXML (ar))
    return true;

  return false;
  } // end of IsClipboardXML
Beispiel #2
0
void CXMLparser::BuildStructure (CFile * file)
  {

  m_xmlLength = file->GetLength ();

  // can hardly be XML if empty file
  if (m_xmlLength == 0)
    ThrowErrorException ("Zero length XML file \"%s\"",
                          (LPCTSTR) file->GetFilePath ());

  // sanity check - don't read 20 Mb files into memory
  if (m_xmlLength > MAX_XML_DOCUMENT_SIZE)
    ThrowErrorException ("XML file \"%s\"too large - maximum permitted is %i bytes", 
                          (LPCTSTR) file->GetFilePath (),
                          MAX_XML_DOCUMENT_SIZE);

  char * p = m_strxmlBuffer.GetBuffer (m_xmlLength + 1);

  iLineLastItemFound = 0;

  if (file->Read (p, m_xmlLength) != m_xmlLength)
    {
    m_strxmlBuffer.ReleaseBuffer (0);
    ThrowErrorException ("Could not read XML file");
    }

  m_strxmlBuffer.ReleaseBuffer (m_xmlLength);

  // look for Unicode  (FF FE)
  if ((unsigned char) m_strxmlBuffer [0] == 0xFF &&
      (unsigned char) m_strxmlBuffer [1] == 0xFE)
    {
    CString buf2;
    const char * q =  m_strxmlBuffer;
    q += 2; // skip indicator bytes
    // find required buffer length
    int length = WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) q, (m_xmlLength - 2) / 2, 
                    NULL, 0, NULL, NULL);
    // make a new string with enough length to hold it
    char * p = buf2.GetBuffer (length);
    // convert it
    WideCharToMultiByte (CP_UTF8, 0, (LPCWSTR) q, (m_xmlLength - 2) / 2, 
              p, length, NULL, NULL);
    buf2.ReleaseBuffer (length);
    // copy to our buffer
    m_strxmlBuffer = buf2;
    }
  else 
    // look for UTF-8 indicator bytes  (EF BB BF)
    if ((unsigned char) m_strxmlBuffer [0] == 0xEF &&
        (unsigned char) m_strxmlBuffer [1] == 0xBB &&
        (unsigned char) m_strxmlBuffer [2] == 0xBF)
      m_strxmlBuffer = m_strxmlBuffer.Mid (3);  // skip them


  // convert tabs to spaces, we don't want tabs in our data
  m_strxmlBuffer.Replace ('\t', ' ');

  SeeIfBase64 (m_strxmlBuffer);

  m_xmlBuff = m_strxmlBuffer;    // get const char * pointer to buffer

  ProcessNode (m_xmlRoot);  // process root node

  }   // end of CXMLparser::BuildStructure