• 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: NSXML encoding question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: NSXML encoding question...


  • Subject: RE: NSXML encoding question...
  • From: "John Stiles" <email@hidden>
  • Date: Sun, 26 Aug 2007 12:10:17 -0700
  • Thread-topic: NSXML encoding question...

A CDATA block is probably the correct way to go here.
I would still caution that one could construct valid C, ObjC or C++ code that contained "]]>" in it, so you still need to be a bit careful...

if( [a multiplyWith:[b value]]>25 )
{
    NSLog(@"whoops! CDATA trouble");
}

Unfortunately I don't have a lot of CDATA experience so I don't know the best workaround for this sort of situation.

Personally I've always just written a quick function which replaces < > & in a string with the appropriate XML entities. In fact Cocoa may already have such a function handy; not sure. (My XML parsing code has always needed to be cross platform.)


________________________________

From: cocoa-dev-bounces+jstiles=email@hidden on behalf of James Bucanek
Sent: Sun 8/26/2007 9:24 AM
To: Martin Linklater
Cc: email@hidden
Subject: Re: NSXML encoding question...



Martin Linklater <mailto:email@hidden> wrote (Sunday,
August 26, 2007 5:05 AM +0100):
><code>
>addr = *PC + ( *(PC + 1) &lt&lt 8);
></code>

As others have pointed out, it's '&lt;'. XML entities have the
general form '&' <entity description> ';', where the description
can be the name of a named entity or a literal constant (i.e. '&#60;').

However, if you want to encode literal data that may, or may
not, contain reserved XML characters it's easier to use a CDATA block:

     <code>
         <![CDATA[
             addr = *PC + ( *(PC + 1) << 8); // & other
<code>crazy</code> stuff!
         ]]>
     </code>

Everything between '<![CDATA[' and ']]>' is read as a literal
string of characters and is not interpreted as XML.

--
James Bucanek

_______________________________________________

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


_______________________________________________

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: NSXML encoding question...
      • From: James Bucanek <email@hidden>
References: 
 >Re: NSXML encoding question... (From: James Bucanek <email@hidden>)

  • Prev by Date: Re: How do you found your way around in the ref docs?
  • Next by Date: Re: How do you found your way around in the ref docs?
  • Previous by thread: Re: NSXML encoding question...
  • Next by thread: RE: NSXML encoding question...
  • Index(es):
    • Date
    • Thread