Re: How to add a DOCTYPE declaration to an NSXMLDocument?
Re: How to add a DOCTYPE declaration to an NSXMLDocument?
- Subject: Re: How to add a DOCTYPE declaration to an NSXMLDocument?
- From: Steven Spencer <email@hidden>
- Date: Wed, 31 Mar 2010 15:14:01 +0100
The following code produces the equivalent XML :
NSXMLDocument *myDoc = [[NSXMLDocument alloc] initWithRootElement:[NSXMLElement elementWithName:@"myDocType"]];
NSXMLDTD *myDTD = [[NSXMLNode alloc] initWithKind:NSXMLDTDKind];
[myDTD setName:@"myDocType"];
[myDoc setDTD:myDTD];
[myDoc setVersion:@"1.0"];
[myDoc setCharacterEncoding:@"UTF-8"];
[[myDoc XMLData] writeToFile:[@"~/Desktop/TestXML.xml" stringByExpandingTildeInPath] atomically:YES];
- Steve
On 31 Mar 2010, at 09:31, email@hidden wrote:
>> Sounds promising, but the document type declaration doesn't get written
> out to file.
>
> If I create the document using a string instead, it works:
>
> NSString *docString = [NSString stringWithFormat:@"<!DOCTYPE
> myDocType><myDocType></myDocType>"];
> NSXMLDocument *myDoc = [[NSXMLDocument alloc] initWithXMLString:docString
> options:0 error:&err];
> [[myDoc DTD] setName:@"myDocType"];
>
> Seems equivalent to half a dozen other things I tried, but this is the only
> one that works.
>
> Bruce
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden