NSStringでXML直書き

Contributed by: akira on 2010年 7月15日(木) 08:36 JST

Last modified on

[NSString stringWithFormat:
@"<?xml version="1.0" encoding="utf-8"?>"
"<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance[*1] "
xmlns:xsd="http://www.w3.org/2001/XMLSchema[*2] "
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/[*3] ">"
"<soap:Body>"
"<FindCountryAsXml
xmlns="http://www.ecubicle.net/webservices/[*4] ">"
"<V4IPAddress>%@</V4IPAddress>"
"</FindCountryAsXml>"
"</soap:Body>"
"</soap:Envelope>",
ipAddress.text
]; 上記の場合にエラーが発生、原因は ダブルクォートで囲われた物は1行で表現する必要があるらしい。
よって、下記のようにしなければならない。
<soap:Envelope>
<FindCountryAsXml>のxmlnsタグは1行で
[NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\[*5] " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\[*6] " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\[*7] ">"
"<soap:Body>"
"<FindCountryAsXml xmlns=\"http://www.ecubicle.net/webservices/\[*8] ">"
"<V4IPAddress>%@</V4IPAddress>"
"</FindCountryAsXml>"
"</soap:Body>"
"</soap:Envelope>",
ipAddress.text
];

コメント (0件)

Geeklog Site - NSStringでXML直書き
https://geeklog.craine.ne.jp/article.php?story=201007150836398

[*1] http://www.w3.org/2001/XMLSchema-instance
[*2] http://www.w3.org/2001/XMLSchema
[*3] http://schemas.xmlsoap.org/soap/envelope/
[*4] http://www.ecubicle.net/webservices/
[*5] http://www.w3.org/2001/XMLSchema-instance\
[*6] http://www.w3.org/2001/XMLSchema\
[*7] http://schemas.xmlsoap.org/soap/envelope/\
[*8] http://www.ecubicle.net/webservices/\