• 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: simple string to NSData question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple string to NSData question


  • Subject: Re: simple string to NSData question
  • From: "Chris Suter" <email@hidden>
  • Date: Fri, 8 Aug 2008 15:57:34 +1000

On Fri, Aug 8, 2008 at 3:49 PM, Ken Thomases <email@hidden> wrote:

> On Aug 7, 2008, at 2:15 PM, phil swenson wrote:
>
>  I'm trying to parse an xml file, so to get started I put the xml in a
>> String:
>>
>> NSString *xml = @"<?xml version=\"1.0\"
>>
>> encoding=\"UTF-8\"?><person><first>Larry</first><last>Furg</last></person>";
>>
>>
>> Now I need to move this to a NSXMLDocument, which takes an NSData.
>>
>> Looking at NSData, I see there is a method initWithBytes.... but I'm not
>> sure how to put it in there from my NSString.
>>
>
> Rather than thinking about how to create an NSData yourself, ask the string
> to do it.  The easiest way would be [xml dataUsingEncoding:
> NSUTF8StringEncoding].
>

Looks like -[NSXMLDoucment initWithXMLstring:options:error:] might also do
the trick or if it's coming from a file, why use a string at all, use
-[NSXMLDocument initWithContentsOfURL:options:error].

-- Chris
_______________________________________________

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

References: 
 >simple string to NSData question (From: "phil swenson" <email@hidden>)
 >Re: simple string to NSData question (From: Ken Thomases <email@hidden>)

  • Prev by Date: Re: simple string to NSData question
  • Next by Date: Re: Basic Obj-C Question on Memory and Strings
  • Previous by thread: Re: simple string to NSData question
  • Next by thread: NSMultipleTextSelectionPboardType not working
  • Index(es):
    • Date
    • Thread