Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:43:32+00:00 2026-05-28T07:43:32+00:00

pugixml seems to be adding invalid characters when I set the value of a

  • 0

pugixml seems to be adding invalid characters when I set the value of a node_pcdata. The code is below. What I’m trying to do is base-64 encode a PNG and send it via XML. I wrote the base-64 encoded text to a file to check it separately from pugixml, and it looks good, ending with these valid characters 4AAAAASUVORK5CYII=. But the ndAvatarData.set_value(avatarEnc) call is adding invalid characters for the same run 4AAAAASUVORK5CYII=
cY
3XA+Рz
. Occasionally the result is valid, but I have not been able to repeat that, so I don’t know what the pugi output looks like in that case.

Is there something I need to do here? Is this a known problem with pugixml? I searched but could not find anything discussing this problem.

I’m getting this in Visual C++ 2010.

char* avatarEnc = NULL;
try {
    std::ifstream avatarIn("MyAvatar.png", std::ios_base::in | std::ios_base::binary);
    if (!avatarIn.is_open())
        cerr << "Could not open avatar file!";
    else {
        base64::encoder E;
        stringstream  avatarOut;
        E.encode(avatarIn, avatarOut);

        avatarOut.seekg(0, ios::end);
        int avatarEncSize = avatarOut.tellg();
        avatarOut.seekg(0, ios::beg);

        avatarEnc = new char[avatarEncSize];
        avatarOut.read(avatarEnc, avatarEncSize);

        std::ofstream tempOut("avatarEnc.txt", std::ios_base::out | std::ios_base::binary);
        tempOut.write(avatarEnc, avatarEncSize);

        xml_node ndAvatar = root.append_child("avatar");
        xml_node ndAvatarData = ndAvatar.append_child(pugi::node_pcdata);
        ndAvatarData.set_value(avatarEnc);
    }
}
catch (...) {
    cerr << "Error loading avatar.";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:43:32+00:00Added an answer on May 28, 2026 at 7:43 am

    Figured it out – set_value() wants a null-terminated string.

    avatarEnc = new char[avatarEncSize+1];
    
    avatarOut.read(avatarEnc, avatarEncSize);
    
    avatarEnc[avatarEncSize] = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to set the value of an element, regulary when the element looks
There are plenty of Libraries to parse XML, but it seems there aren't many
I am building a GUI for my final project. This project uses pugixml as
Hi I'm using pugixml to process xml documents. I iterate through nodes using this
I have this template set __Self &set(const char *name, lua_CFunction func) { return rawSet(name,
Is there an easy way in PugiXML to unescape and load an XML embedded
I want a lite-weight C++ XML parser/DOM that: Can take UTF-8 as input, and
I am looking for C++ lib for XML. I know there are some questions
I know of at least three light weight C++ XML parsers: RapidXML , TinyXML
I have already following bash script. It count lines in *.cpp only. How i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.