Writing binary data (CString) to file

Discussion in 'C++' started by Carl Forsman, Nov 19, 2008.

  1. Carl Forsman

    Carl Forsman Guest

    I have some binary data encoded as Base64 encoding in an XML element
    like this:

    <data>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx</data>

    how can I extract this data -
    TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx

    and save to a file say test2.xml

    ==================
    pug::xml_node_list CategoryEntries;
    PictureEntries.all_elements_by_name("category", CategoryEntries);

    // if found XML element
    if (CategoryEntries.size() > 0) {
    for (unsigned int i = 0; i < CategoryEntries.size(); i++) {

    //extract the Base64 string from XML element
    //this Base64 string has binary data after decode
    CString cat = CategoryEntries.child(0).value();

    //decode Base64 string into binary data
    CString decoded = decodeBase64(cat);

    //open file to write the binary data
    std::eek:fstream file1("c:/test2.xml");

    // write the decoded binary data to file
    file1.write(decoded);

    }
    }
    Carl Forsman, Nov 19, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sebastian Kemi
    Replies:
    6
    Views:
    550
    Kevin Goodsell
    Sep 21, 2003
  2. Replies:
    12
    Views:
    6,514
    Andy Flowers
    May 20, 2006
  3. Ron Eggler

    writing binary file (ios::binary)

    Ron Eggler, Apr 25, 2008, in forum: C++
    Replies:
    9
    Views:
    895
    James Kanze
    Apr 28, 2008
  4. Carl Forsman

    binary file to CString

    Carl Forsman, Nov 19, 2008, in forum: C++
    Replies:
    2
    Views:
    706
    Stefan Ram
    Nov 19, 2008
  5. Charblit
    Replies:
    0
    Views:
    470
    Charblit
    Jan 23, 2010
Loading...

Share This Page