I have an NSXMLDocument that I am editing and then saving out. The problem is, it's escaping my & and <.
NSArray *nodes = [document nodesForXPath:@"JDF/JDF/ResourcePool/od:Ticket/od:Parameter/DefaultOutputOption" error:ni开发者_如何学Gol];
[[nodes objectAtIndex:0] setStringValue:@"34""];
NSLog(@"%@", [[nodes objectAtIndex:0]stringValue]);
[[nodes objectAtIndex:1] setStringValue:@"1<2"];
NSLog(@"%@", [[nodes objectAtIndex:1]stringValue]);
NSData *xmlData = [document XMLDataWithOptions:NSXMLNodePreserveAll];
[xmlData writeToFile:path atomically:YES];
In console I'm getting what you'd expect from the NSLog statements:
2011-09-06 16:05:56.480 My App[14369:707] 34"
2011-09-06 16:05:56.482 My App[14369:707] 1<2
But in my XML Document I get:
34&quot;
1<2
What am I doing wrong?
Technically you're not doing anything wrong. When you set the text value for a node, you should use the raw, unescaped form. When the nodes are serialized to XML, some characters will be escaped, e.g. " will become " and < will become <.
I guess what really want to enter as text in the first node is 34"
, which in XML serialized form is 34"
.
精彩评论