Database Reference
In-Depth Information
Type: maximum, Units: Fahrenheit
2011-11-16T07:00:00-05:00, Daily Maximum Temperature = 58
2011-11-17T07:00:00-05:00, Daily Maximum Temperature = 49
2011-11-18T07:00:00-05:00, Daily Maximum Temperature = 48
Type: minimum, Units: Fahrenheit
2011-11-16T19:00:00-05:00, Daily Minimum Temperature = 42
2011-11-17T19:00:00-05:00, Daily Minimum Temperature = 27
Generating XML for Submission to Services
Whereas you almost always want to use a parsed DOM to extract data from a service,
how you construct XML to send back to a server is more flexible. The particular web
service we used in the last example is GET-only, so we'll use a mythical service that
takes a POST for this one. Let's say that the server crew has finally gotten their act
together, and you can now post a news item by sending the following XML:
<newsitem postdate="2011-07-01" posttime="14:54">
<subject>
Buggy Whips Now Available in Brown
</subject>
<body>
Buggy whips are the hottest thing around these
days, and now they're available in a new
designer color, caramel brown!
</body>
</newsitem>
If you wanted to construct payloads that follow this format, and post them up to the
server, you could use the code snippet in Example 4-7 .
Example 4-7. Constructing XML by formatting strings
-(NSString *) constructNewsItemXMLByFormatWithSubject:(NSString *)
subject body:(NSString *) body
{
NSDate *now = [NSDate date];
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"YYYY-MM-dd"];
NSDateFormatter *tf = [NSDateFormatter new];
[tf setDateFormat:@"hh:mm"];
NSString *xml =
[NSString stringWithFormat:@"<newsitem\
postdate=\"%@\" posttime=\"%@\">\
<subject>%@<subject><body>%@</body></newsitem>",
[df stringFromDate:now],
[tf stringFromDate:now],
subject, body];
return xml;
 
Search WWH ::




Custom Search