I wrote a program that produces an xml file; all works fine except that empty elements appear
as follows in the xml file
<key id="0"><key/>
instead of:
<key id="0"/>
This causes errors when the xml is accessed.
P.S. I have to follow the DTD stored here: /System/Library/DTDs/KeyboardLayout.dtd
This is how I create the NSXMLElements:
NSXMLElement* space = [[NSXMLElement alloc] initWithName:@"key"];
[space addAttribute:[NSXMLNode attributeWithName:@"id" stringValue:[NSString stringWithFormat:@"0"]]];
So my question is, how is the code above to be modified i order to produce xml nodes as shown in the second example?
UPDATE:
Used the NSXMLCompactEmpyElement option as suggested and also used the NSXMLNodePrettyPrint option else all the nodes appear in one line.
NSData *xmlData = [mapping XMLDataWithOptions:NSXMLNodeCompactEmptyElement | NSXMLNodePrettyPrint];
[xmlData writeToFile:path atomically:YES];
How exactly do you write it out? In any case, the option you are looking for is
NSXMLNodeCompactEmptyElement, which for instance is a valid option forXMLStringWithOptions:on a node.