Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

embed an image

2008-09-22
2013-05-20
  • Ignasi Mateos
    Ignasi Mateos
    2008-09-22

    Hi all,

    I would like to embed an image inside an xml. My idea is to use a CDATA node, but I'm not sure how to achieve this.

    Thanks in advance.

    Ignasi Mateos

     
    • Ignasi Mateos
      Ignasi Mateos
      2008-09-25

      Hi again,

      I'm trying to embed an image inside an XML, that's what I've done till now:

      ...

      ifstream imageFile;

      imageFile.open(imageFilename, ios::in | ios::binary);
      imageFile.seekg(0, ios::end);
      streamsize length = imageFile.tellg();

      if (length != 0)
      {
          imageFile.seekg(0, ios::beg);

          char *pRaw = new char[length];
          imageFile.read((char*)pRaw, length);

          TiXmlElement *imageElem = new TiXmlElement("IMG");
          imageElem->SetAttribute("Data", pRaw);
          rootElem->LinkEndChild(imageElem); 
      }
      imageFile.close();

      ...

      But it's only saved the fist four bits...Does anyone know what I'm doing wrong?

      Thanks in advance.