FROM : Graff
DATE : Fri Aug 29 03:40:30 2008
On Aug 28, 2008, at 3:11 PM, Andrew R. Kinnie wrote:
> I am attempting to programmatically create an html (rather, xhtml)
> document using NSXMLDocument, NSXMLElement, etc.
>
> I am able to create the document and it works, but I am not sure how
> to create text which is not inside a paragraph or another tag which
> can be a node.
You can do that with the NSXMLNode class method textWithStringValue:
example:
NSXMLElement *root = (NSXMLElement *)[NSXMLNode
elementWithName:@"test"];
NSXMLDocument *aDoc = [[NSXMLDocument alloc] initWithRootElement:root];
[root addChild:[NSXMLNode textWithStringValue:@"some text"]];
NSString *aFile = [@"~/Desktop/test.txt"
stringByExpandingTildeInPath];
[[aDoc XMLData] writeToFile:aFile atomically:YES];
result:
<test>some text</test>
- Ken Bruno
DATE : Fri Aug 29 03:40:30 2008
On Aug 28, 2008, at 3:11 PM, Andrew R. Kinnie wrote:
> I am attempting to programmatically create an html (rather, xhtml)
> document using NSXMLDocument, NSXMLElement, etc.
>
> I am able to create the document and it works, but I am not sure how
> to create text which is not inside a paragraph or another tag which
> can be a node.
You can do that with the NSXMLNode class method textWithStringValue:
example:
NSXMLElement *root = (NSXMLElement *)[NSXMLNode
elementWithName:@"test"];
NSXMLDocument *aDoc = [[NSXMLDocument alloc] initWithRootElement:root];
[root addChild:[NSXMLNode textWithStringValue:@"some text"]];
NSString *aFile = [@"~/Desktop/test.txt"
stringByExpandingTildeInPath];
[[aDoc XMLData] writeToFile:aFile atomically:YES];
result:
<test>some text</test>
- Ken Bruno
| Related mails | Author | Date |
|---|---|---|
| Andrew R. Kinnie | Aug 28, 21:11 | |
| Nate Weaver | Aug 28, 21:51 | |
| Graff | Aug 29, 03:40 | |
| Andrew R. Kinnie | Aug 29, 14:00 |






Cocoa mail archive

