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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:57:40+00:00 2026-05-28T22:57:40+00:00

I’m working in an iOS application which uses libXML2 to read XML retrieved from

  • 0

I’m working in an iOS application which uses libXML2 to read XML retrieved from a backend system. I have the following XML, which is part of a larger XML document:

<properties uiValue="This is a multiline description with text that should wrap but should also preserve any whitespace:                         like this whitespace.

And preserve newlines.

espace:~` !@#$%^&amp;*()_+=-&lt;&gt;/  \" name="desc">
            <values value="This is a multiline description with text that should wrap but should also preserve any whitespace:                         like this whitespace.

And preserve newlines.

espace:~` !@#$%^&amp;*()_+=-&lt;&gt;/  \"/>
</properties>

As a whole, the document seems to parse OK. The problem that I have is that the newlines are not being processed, so when I read the attribute value, the result is:

This is a multiline description with text that should wrap but should also preserve any whitespace:                         like this whitespace.    And preserve newlines.    espace:~` !@#$%^&amp;*()_+=-&lt;&gt;/  

Is there any way to keep these new lines? If I print out the response XML from the server directly, the new lines are preserved. When I go through the parsing though, the new lines are stripped out. To complicate matters a bit, this is some third party code that I’m trying to fix, and I haven’t really used libXML2 that much. The relevant code (I believe) is:

NSLog(@"Response:\n%@", [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]);

xmlDocPtr doc = xmlReadMemory([data bytes], [data length], NULL, NULL, XML_PARSE_COMPACT | XML_PARSE_NOBLANKS);

xmlNodePtr cur = ....;
xmlChar *attrValue = xmlGetProp(cur, (const xmlChar *) "uiValue");
NSString *attrString = [NSString stringWithCString:(char*)attrValue encoding:NSUTF8StringEncoding];

I have tried taking the XML_PARSE_COMPACT and XML_PARSE_NOBLANKS options out, but that didn’t help (not that I expected it to, I believe those only affect nodes).

  • 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-28T22:57:41+00:00Added an answer on May 28, 2026 at 10:57 pm

    XML Parsers cannot and will not preserve linebreaks in attributes. From the spec:

    Before the value of an attribute is passed to the application or
    checked for validity, the XML processor MUST normalize the attribute
    value by applying the algorithm below:

    • All line breaks must have been normalized on input to #xA as described in 2.11 End-of-Line Handling, so the rest of this algorithm operates on text normalized in this way.
    • …
    • For a white space character (#x20, #xD, #xA, #x9), append a space character (#x20) to the normalized value.

    The library performs this normalization as it’s parsing, so the newlines are gone. You can escape your newlines with numeric entity references as &#xA; but usually if you need to depend on the linebreaks, element values are used.

    <properties uiValue="This is a multiline description with text that should wrap but &#xA;should also preserve any whitespace:                         like this whitespace.&#xA;&#xA;    And preserve newlines.&#xA;&#xA;    espace:~` !@#$%^&amp;*()_+=&#xA;&lt;&gt;/  ">
        <value>This is a multiline description with text that should wrap but should also preserve any whitespace:                         like this whitespace.
    
    And preserve newlines.
    
    espace:~` !@#$%^&amp;*()_+=-&lt;&gt;/  "</value>
    </properties>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.