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 3281682
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:50:33+00:00 2026-05-17T19:50:33+00:00

I have a problem trying to get my head around using UTF8 with Poco::XML::XMLWriter

  • 0

I have a problem trying to get my head around using UTF8 with Poco::XML::XMLWriter. In the following code example, everything works fine when the input contains ASCII characters. However, occasionally the string in wordmapIt->first contains a non-ASCII value, such as a character -105 occurring in the middle of a string. When this happens the xml stream seems to terminate on the -105 char even though there are many other words after this one. I want to save whatever string was there so just stripping the char out isn’t the right answer – theres got to be some kind of encoding I can apply (I think) but what?

I’m clearly missing something conceptually but for the life of me I cant figure out the right way to do this.

Poco::XML::XMLString EDocument::makeXMLString()
{
    std::stringstream xmlstream;
    Poco::UTF8Encoding utf8encoding;
    Poco::XML::XMLWriter writer(xmlstream, 0, "UTF-8", &utf8encoding);

    writer.startDocument();
    std::map<std::string, std::string>::iterator wordmapIt;

    for ( wordmapIt = nodeinfo->wordmap.begin(); wordmapIt != nodeinfo->wordmap.end(); wordmapIt++ )
    {
        writer.startElement("", "", "word");
        writer.characters(Poco::XML::toXMLString(wordmapIt->first));
        writer.endElement("", "", "word");
        }
        writer.endDocument();
    return xmlstream.str();
    }

Edit:
Solution based on answer below.

Poco::XML::XMLString EDocument::makeXMLString()
{
    std::stringstream xmlstream;
    Poco::UTF8Encoding utf8encoding;
    Poco::XML::XMLWriter writer(xmlstream, 0, "UTF-8", &utf8encoding);

    Poco::Windows1252Encoding windows1252encoding;
    Poco::UTF8Encoding utf8encoding;
    Poco::TextConverter textconverter(windows1252encoding, utf8encoding);

    writer.startDocument();
    std::map<std::string, std::string>::iterator wordmapIt;

    for ( wordmapIt = nodeinfo->wordmap.begin(); wordmapIt != nodeinfo->wordmap.end(); wordmapIt++ )
        {
        std::string strword; 
        textconverter.convert(wordmapIt->first, strword);
        writer.startElement("", "", "word");
        writer.characters(strword);
        writer.endElement("", "", "word");
        }
    writer.endDocument();
    return xmlstream.str();
}
  • 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-17T19:50:34+00:00Added an answer on May 17, 2026 at 7:50 pm

    It sounds like you have a byte string in Windows code page 1252 encoding. “Character -105” presumably really means byte 0x97, which would map to Unicode character U+2014 Em Dash (—) in cp1252.

    I’m not familiar with Poco, but I would guess you’re expected to convert your cp1252 strings to UTF-8 output encoding using a TextConverter with Windows1252Encoding and UTF8Encoding.

    Although if what you really have is an “ANSI string” (a byte string in the default code page for the current machine’s locale), 1252 might not be the right answer and you might have to use a function from another library to do the conversion properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some problems trying to get my PHP running. When I
I have a problem I'm trying to solve involving interfaceing a C++ program with
I discovered to have some problem to fully understand callbacks scoping when trying to
I have a problem with my WPF program. I'm trying to create an object
I have a small math problem I am trying to solve Given a number
In trying to solve the ajax back button problem I have found the Really
I am trying to learn ASP.NET MVC and I hit this problem: I have
I have been trying to tackle this problem , but I am having difficulty
I'm trying to solve the 3n+1 problem and I have a for loop that
I'm trying out ASP.NET MVC routing and have of course stumbled across a problem.

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.