4

I'm running this code:

NSXMLElement *element = [NSXMLElement elementWithName:@"name" stringValue:@"value\n"];
NSXMLDocument *document = [[NSXMLDocument alloc] initWithRootElement:element];
NSLog(@"%@", document.XMLString);

And I'm getting this result:

<name>value
</name>

But I'm expecting the result to be:

<name>value&#xA;</name>

Does anybody know why NSXMLDocument doesn't escape \n? Is it an expected behavior?

I also tried XMLStringWithOptions: with different options, e.g. NSXMLNodePreserveWhitespace, but with no luck.

Anton Simakov
  • 293
  • 3
  • 14

1 Answers1

2

Because \n is valid xml. If you really want values to be URL encoded, you'll need to encode them.

How do I URL encode a string

slf
  • 22,595
  • 11
  • 77
  • 101