Reputation: 297
NSString *xml = @"<?xml version="1.0" encoding="ISO-8859-15"?>
<ServerDateTime DateRequested="" DateSent="20141013_114855">
<DateTime>20141013_114857</DateTime>
</ServerDateTime>";
In above xml, how to find the attribute value of 'DataSent'?
I have tried by following, but i didn't get the value.
CXMLDocument *documentParser = [[CXMLDocument alloc]initWithData:[xml dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
NSArray *arrayResult = [documentParser nodesForXPath:@"//ServerDateTime" error:nil];
for(CXMLElement *element in arrayResult){
NSString *value = [element name];
if ([value isEqualToString:@"ServerDateTime"]) {
NSString *newLastSyncDate = [[element attributeForName:@"DataSent"] stringValue]; //it gives nil..
}
}
Upvotes: 0
Views: 68
Reputation: 1278
You may want to use XPath-queries to search for elements inside a XML. You have to look up if CXML supports this. Maybe also take a look at this question.
There someone is searching for a given attribute with an XPath-query.
Upvotes: 0