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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:35:55+00:00 2026-05-23T17:35:55+00:00

I’m getting a strange error with rapidxml when parsing a xml file like <?xml

  • 0

I’m getting a strange error with rapidxml when parsing a xml file like

<?xml version="1.0" encoding="UTF-8"?>
<IMG align="left"
 src="http://www.w3.org/Icons/WWW/w3c_home" />

It throws “expected >”.
Im using a code like the following to parse the data

std::fstream file("./test.xml");
std::istream_iterator<char> eos;
std::istream_iterator<char> iit (file);

std::vector<char> xml(iit, eos);
xml.push_back('\0');

xml_document<> doc;
doc.parse<0>(&xml[0]);

the “/” symbol in the IMG rag seems t be the problem. Is this a rapidxml bug or am I doing something wrong?

  • 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-23T17:35:56+00:00Added an answer on May 23, 2026 at 5:35 pm

    The way you load the XML data into vector is wrong. In C++ text mode streams have “skipws” flag set by default, which causes them to skip all whitespace in the input. You can verify this by examining the contents of your vector – it will have all spaces/endlines missing. This obviously causes the parser to complain.

    Unset skipws flag on the stream to get the correct behaviour:

    file.unsetf(ios::skipws);
    

    Alternatively, you can use file class from rapidxml_utils.hpp to load the file:

    using namespace rapidxml;
    file<> file("test.xml");
    xml_document<> doc;
    doc.parse<0>(file.data());
    

    Sadly, loading text files with C++ streams is very tricky and full of traps.

    As for sehe tests above, the “incorrectly accepted” cases are by design (I don’t have enough reputation to add comments to his answer). You need to use “parse_validate_closing_tags” parse flag to make the parser check whether end tag name matches starting tag name:

    doc.parse<parse_validate_closing_tags>(...);
    

    See parse_validate_closing_tags in rapidxml manual.
    The rationale for this behaviour is performance – verifying end tags is time consuming and in most cases not needed.

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

Sidebar

Related Questions

No related questions found

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.