NSXML and Character References
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" & "Dad's" Show</title>
</rss>
See the quotations and the apostrophe are not being converted to
" and ' 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