其實我有這樣的代碼:如何從資源中讀取file.xml格式爲NSString?
NSString *path = [[NSBundle mainBundle] pathForResource: @"connect" ofType: @"xml"];
NSError *error = nil;
NSString *data = [NSString stringWithContentsOfFile: path
encoding: NSUTF8StringEncoding
error: &error];
NSString *message = [NSString stringWithFormat:data, KEY, COUNTRY_ID];
讀取從資源connect.xml。但是在格式化字符串(消息)應用程序退出時不顯示任何錯誤。如何從資源讀取connect.xml格式的NSString?
connect.xml看起來是這樣的:
<?xml version="1.0" encoding="utf-16"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:WebApi" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:doQuerySysStatus>
<sysvar xsi:type="xsd:int">1</sysvar>
<country-id xsi:type="xsd:int">%d</country-id>
<webapi-key xsi:type="xsd:string">%@</webapi-key>
</ns1:doQuerySysStatus>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
,並定義:
#define KEY @"f7ff34df7a"
#define COUNTRY_ID 228
file connect.xml中有%d和%@ – konradowy 2010-05-28 18:13:03
這些是整個文件中唯一發生的%嗎? – drawnonward 2010-05-28 18:23:53
發佈connect.xml和更多代碼(特別是KEY和COUNTRY_ID)。此外,它可能是逐行調試的時候,在每個語句之後調用NSLog以確保所有值都符合預期。 – KevinDTimm 2010-05-28 18:34:46