• 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: XML-/HTML-safe formatted output from NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML-/HTML-safe formatted output from NSString


  • Subject: Re: XML-/HTML-safe formatted output from NSString
  • From: Scott Anguish <email@hidden>
  • Date: Tue, 29 Oct 2002 21:10:56 -0500

On Tuesday, October 29, 2002, at 07:07 PM, Terence Goggin wrote:

Hi all,

I have some data that I'm writing to disk via an NSString... However, the resulting data gets spit out as XML or HTML formatted data which means that I need a way to catch and replace any XML/HTML reserved characters such as <, <, &, etc.

Does anyone have any thoughts on easiest ways to accomplish this? I could go through the NSString one character at a time and just replace as needed, but I was hoping there was already code or methods to do this available somewhere.


I think this escapes everything needed (if not, someone should let me know)

@implementation NSString(youtalkintome)

- (NSString *)stringByEncodingXMLCharacters
{
NSMutableString *_theString=[self mutableCopy];
[_theString replaceOccurrencesOfString:@"&" withString:@"&amp;"
options:NSLiteralSearch
range:NSMakeRange(0, [self length])];
[_theString replaceOccurrencesOfString:@"<" withString:@"&lt;"
options:NSLiteralSearch
range:NSMakeRange(0, [self length])];
[_theString replaceOccurrencesOfString:@">" withString:@"&gt;"
options:NSLiteralSearch
range:NSMakeRange(0, [self length])];
NSString *_nonMutableVersion=[NSString stringWithString:_theString];
[_theString release];
return _nonMutableVersion;
}

@end
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >XML-/HTML-safe formatted output from NSString (From: "Terence Goggin" <email@hidden>)

  • Prev by Date: DO Connections
  • Next by Date: Re: Status 255
  • Previous by thread: XML-/HTML-safe formatted output from NSString
  • Next by thread: Re: XML-/HTML-safe formatted output from NSString
  • Index(es):
    • Date
    • Thread