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

NSXML and Character References


  • Subject: NSXML and Character References
  • From: Juan Alvarez <email@hidden>
  • Date: Mon, 21 Nov 2005 10:26:17 -0500

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>

See the quotations and the apostrophe are not being converted to &quot; and &apos; respectively. Only the ampersand is being converted. Thanks for your help.
_______________________________________________
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: Ilan Volow <email@hidden>
    • Re: NSXML and Character References
      • From: James Housley <email@hidden>
  • Prev by Date: Obtaining an array of the names of the attributes and relations of a class
  • Next by Date: Re: Automagic instantiation of singletons?
  • Previous by thread: Re: Obtaining an array of the names of the attributes and relations of a class
  • Next by thread: Re: NSXML and Character References
  • Index(es):
    • Date
    • Thread