Search code examples
xmlpluginssketch-3export-to-xmlcocoascript

NSXMLElements breaking line before close TAG - Cocoascript


I'm creating an XML file. What I need is to have a line-break before close the TAG My expected printout is

<View 
    x=“0” y=“0" 
    width=“464” height=“287">
</View>

instead, the output I have is the following:

<View 
    x=“0” y=“0" 
    width=“464” height=“287"></View>

Here is the code that I have:

var layerElement = [NSXMLElement elementWithName:@"View"];
[layerElement addAttribute:[NSXMLNode attributeWithName:@"\n \tx" stringValue:layerXpos]];
[layerElement addAttribute:[NSXMLNode attributeWithName:@"y" stringValue:layerYpos]];
[layerElement addAttribute:[NSXMLNode attributeWithName:@"\n \twidth" stringValue:layerWidth]];
[layerElement addAttribute:[NSXMLNode attributeWithName:@"height" stringValue:layerHeight]];
[root addChild:layerElement];

In the doc page, I found only some reference for compact/expand the empty tags ( NSXMLNodeOptions), but nothing to format the TAG when it's not empty.


Solution

  • I found a solution, simpler than expected:

    var layerElement = [NSXMLElement elementWithName:@"View" stringValue:"\n"];
    

    Just adding the new line (@"\n") attribute to a stringValue parameter everything will work fine.

    If anyone else knows something that will work better, please add your answer.