• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Am I Reinventing the Wheel? (Part I)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Am I Reinventing the Wheel? (Part I)


  • Subject: Re: Am I Reinventing the Wheel? (Part I)
  • From: Keary Suska <email@hidden>
  • Date: Thu, 08 Jan 2015 09:08:28 -0700

On Jan 8, 2015, at 5:43 AM, Charles Jenkins <email@hidden> wrote:

> I need to deal with two issues that are probably already handled in some Cocoa API I just haven't found yet. This email asks about the first of these issues.
>
> I'm writing data to XML. When you create a node and set its string contents, the node will happily accept whatever string you give and allow you to serialize information XML deserialization cannot then recreate. In my case, the string in question contained curled quotes. I could serialize and save the data—and if I remember correctly* the output looked good when I inspected the file on disk—but reading it back and deserializing it led to disaster! Right now I'm using NSString stringByAddingPercentEncoding: and having no further problems with curled quotes, but I'm sure that's a poor long-term solution.
>
> *I encountered this problem a few weeks ago and put off a final solution by using the percent encoding.
>
> Is there already a Cocoa API call that would convert a string to use HTML entities so I could safely put any string into an XML node?

You can apparently route through NSAttributedString (found via StackOverflow):

NSAttributedString *s = [[NSAttributedString alloc] initWithString:sourceString];
NSDictionary *documentAttributes = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSData *htmlData = [s dataFromRange:NSMakeRange(0, s.length) documentAttributes:documentAttributes error:NULL];
NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];

HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Am I Reinventing the Wheel? (Part I)
      • From: Charles Jenkins <email@hidden>
References: 
 >Am I Reinventing the Wheel? (Part I) (From: Charles Jenkins <email@hidden>)

  • Prev by Date: Re: Am I Reinventing the Wheel? (Part I)
  • Next by Date: Re: Am I Reinventing the Wheel? (Part II)
  • Previous by thread: Re: Am I Reinventing the Wheel? (Part I)
  • Next by thread: Re: Am I Reinventing the Wheel? (Part I)
  • Index(es):
    • Date
    • Thread