2013-07-24 62 views
2

創建XML文件成功的,但它不包含第一行:NSXMLDocument不具有<?XML版本= 「1.0」 編碼= 「UTF-8」 獨立= 「否」?>在可可觸摸

<?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

也許你應該嘗試使用下一個方法來設置此數據:

setCharacterEncoding: 
setStandalone: 
setVersion: 

詳見​​

+0

感謝它的工作原理 – HTKT611

相關問題