NSXMLDocument没有<! - ?xml version =“1.0”encoding =“UTF-8”standalone =“no”? - >在Cocoa Touch中

时间:2013-07-24 09:22:09

标签: objective-c xml macos nsxmldocument

我创建了XML文件,但它不包含第一行:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

此代码为:

xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:url options:NSXMLDocumentTidyXML error:&error];
if(xmlDoc)
{
    root = [xmlDoc rootElement];
}
else
{
    root = [NSXMLNode elementWithName: @"P2Main"];
    [root addAttribute:[NSXMLNode attributeWithName:@"xmlns:xsi" stringValue:@"http://www.w3.org/2001/XMLSchema-instance"]];
    [root addAttribute:[NSXMLNode attributeWithName:@"xmlns" stringValue:@"urn:schemas-Professional-Plug-in:P2:ClipMetadata:v3.1"]];
    xmlDoc = [[NSXMLDocument alloc] initWithRootElement:root];

}

我不知道为什么?你有什么建议吗?提前致谢

1 个答案:

答案 0 :(得分:1)

您可能应尝试使用下一种方法设置此数据:

setCharacterEncoding:
setStandalone:
setVersion:

有关详细信息,请参阅NSXMLDocument reference