我正在创建一个XML文件。我需要的是在关闭我期望的打印输出标签之前有一个换行符。
<View
x=“0” y=“0"
width=“464” height=“287">
</View>相反,我的输出如下:
<View
x=“0” y=“0"
width=“464” height=“287"></View>下面是我的代码:
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];在doc页面中,我只找到了一些用于压缩/展开空标记( NSXMLNodeOptions)的引用,但是当标签不是空的时候,它没有任何格式。
发布于 2017-09-09 10:32:17
我找到了一个比预期更简单的解决方案:
var layerElement = [NSXMLElement elementWithName:@"View" stringValue:"\n"];只要将新行(@"\n")属性添加到stringValue参数中,一切都会正常工作。
如果其他人知道什么事情会更好,请补充你的答案。
https://stackoverflow.com/questions/46079595
复制相似问题