Re: NSXMLDocument question
Re: NSXMLDocument question
- Subject: Re: NSXMLDocument question
- From: Jim Correia <email@hidden>
- Date: Sat, 4 Mar 2006 23:12:03 -0500
On Mar 4, 2006, at 11:29 AM, malcom wrote:
This is a short part of my code. Is there another way to convert
automatically <? Or need I do to it with replace functions of
NSString?
[...]
NSXMLElement *quoteNode = [[NSXMLElement alloc]
initWithKind:
NSXMLElementKind options:NSXMLNodePreserveAll];
[quoteNode setName: @"QUOTE"];
[quoteNode setStringValue: [NSString
stringWithFormat:@"%d", [[_text
objectAtIndex:k] state]]];
It seems like you are going out of your way to make things more
difficult than they need to be. Using the NSXMLElement convenience
methods, and you'll the the right answer as an added bonus.
NSXMLElement *rootElement = [NSXMLNode elementWithName: @"root"];
NSXMLDocument *xmlDocument = [NSXMLNode documentWithRootElement:
rootElement];
NSXMLElement *subElement = [NSXMLNode elementWithName: @"subelement"
stringValue: @"<?"];
[rootElement addChild: subElement];
NSData *xmlData = [xmlDocument XMLData];
NSString *xmlString = [[[NSString alloc] initWithData: xmlData
encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"%@", xmlString);
_______________________________________________
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