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

  • Home
  • SEARCH
  • 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 494291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:29:00+00:00 2026-05-13T05:29:00+00:00

I’m using XML to send project information between applications. One of the pieces of

  • 0

I’m using XML to send project information between applications. One of the pieces of information is the project description. So I have:

<ProjectDescription>Test &amp; spaces around&amp;some  &amp;  amps!</ProjectDescription>

Or: “Test & spaces around&some & amps!” <– GOOD!

When I then use Expat to parse it, my data handler gets just parts of the entire string at a time.
“Test”, then “&”, then “spaces around”, the next “&”, etc, etc. When I then try to reconstruct the original string, all the spacing around the &’s is dropped because the data handler never gets to see them. When I then re-write the XML I get:

<ProjectDescription>Test&amp;spaces around&amp;some&amp;amps!</ProjectDescription>

Or: “Test&spaces around&some&amps!” <– BAD!

Is this a known problem with existing workarounds?
Is there some setting I can give Expat to control its behavior around escaped symbols?

My attempts at Googling an answer have met with dismal failure.

EDIT: In response to a question in the comments:
I have my own handler, which I register with the parser:

parser=XML_ParserCreate(NULL); 
XML_SetUserData(parser,&depth);
XML_SetElementHandler(parser,startElement,endElement); 
XML_SetCharacterDataHandler(parser,dataHandler); 

The handler is declared as follows:

static void dataHandler(void *userData,const XML_Char *s,int l) 

And then “s” contains the data in the element. Without any & stuff, it’s the entire string between the open and close tags, in the case of “a string with spaces”.

  • 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-13T05:29:00+00:00Added an answer on May 13, 2026 at 5:29 am

    I have just run a test with my own library that uses expat. My handler looks like this, with debug statements to display what is going on:

    void CharDataHandler( void * parser, 
                           const XML_Char *s,
                           int len ) {
        std::cerr << "[" << s << "]\n";
        std::cerr << len << "\n";
        // my own processing here - not important 
    }
    

    I don’t see the behaviour you are talking about. For the input data:

    XXX &amp; YYY
    

    I get three events with the char * and length data set as folows:

    char * = "XXX &amp; YYY"
    length = 4
    
    char * = "&"
    length = 1
    
    char * = " YYY"
    length = 4
    

    So the spaces are retained. As far as I know I am not using any specal settings. What version & platform of Expat are you using?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.