• 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 and Character References
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSXML and Character References


  • Subject: Re: NSXML and Character References
  • From: Juan Alvarez <email@hidden>
  • Date: Mon, 21 Nov 2005 11:27:42 -0500

Yes I know that.. But if you look at the iTunes Podcast Specifications page http://phobos.apple.com/static/iTunesRSS.html you clearly see at the bottom that the apostrophe and the quotations must be escaped in order for the feed to work. I need the xml to be parsed that way or else it will not work. Also, I cannot do it manually because the NSXML class automatically escapes the ampersand but nothing else. Do you know how to get it to escape the other characters? Thanks.

On Nov 21, 2005, at 10:50 AM, James Housley wrote:

On Nov 21, 2005, at 10:26 AM, Juan Alvarez wrote:

Hi,
I am creating an NSXMLDocument and adding the children as NSXMLNodes. The problem I am having is that the xml being written out escapes only "&" characters and not apostrophes or quotations. Why is that? Is there a way to have all the characters escape properly. I have already tried to replace the characters with the appropriate escaping, but for some reason the xml still wants to escape the & character that are in there. Please help. I have provided sample code below and the ouput:


Code:
NSXMLElement *root = (NSXMLElement *)[NSXMLNode elementWithName:@"rss"];


NSXMLDocument *xmlDoc = [[NSXMLDocument alloc] initWithRootElement:rootElement];
[xmlDoc setVersion:@"1.0"];
[xmlDoc setCharacterEncoding:@"UTF-8"];


NSXMLNode *node = [NSXMLNode elementWithName:@"title"];
[node setStringValue:@"My \"Mom\" & \"Dad's\" Show"];

[root addChild:node];

NSData *data = [xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
[data writeToFile:filepath atomically:YES];

Output:
<?xml version="1.0" encoding="UTF-8"?>
<rss>
    <title>My "Mom" &amp; "Dad's" Show</title>
</rss>


&amp;, &lt; and &gt; are required to always be escaped by the spec. Quotations and apostrophes only are needed in certain instances. In your above example there is no need to escape them and are valid like that. However, they must be escaped in the case below.


<?xml version="1.0" encoding="UTF-8"?>
<rss>
<title>My "Mom" &amp; "Dad's" Show</title>
<tag2 attribute="My &quot;Mom&quot; &amp; &quot;Dad's&quot; Show">I is a good show</tag2>
<tag3 attribute='My "Mom" &amp; "Dad&apos;s" Show'>I is a good show</tag3>
</rss>


From http://www.w3.org/TR/2004/REC-xml-20040204/#syntax

To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as "&apos;", and the double-quote character (") as "&quot;".


Jim --

/"\   ASCII Ribbon Campaign  .
\ / - NO HTML/RTF in e-mail  .
 X  - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
email@hidden      http://www.FreeBSD.org     The Power to Serve
email@hidden  http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
    good with ketchup.



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: NSXML and Character References
      • From: Greg <email@hidden>
    • Re: NSXML and Character References
      • From: James Housley <email@hidden>
References: 
 >NSXML and Character References (From: Juan Alvarez <email@hidden>)
 >Re: NSXML and Character References (From: James Housley <email@hidden>)

  • Prev by Date: Re: app icons
  • Next by Date: Re: Custom NSOutlineView - Almost resolved
  • Previous by thread: Re: NSXML and Character References
  • Next by thread: Re: NSXML and Character References
  • Index(es):
    • Date
    • Thread