0
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..
                }
            }
RamGrg
  • 296
  • 1
  • 4
  • 20

1 Answers1

0

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.

Community
  • 1
  • 1
TMob
  • 1,278
  • 1
  • 13
  • 33
  • i haven't define xml namespace in my xml. – RamGrg Oct 13 '14 at 06:25
  • Yeah I am sorry, I didn't mean the namespace part. I meant the querying with XPath. As there is some functionality for querying with a namespace, maybe theres also just a method for getting nodes by XPath queries. – TMob Oct 13 '14 at 06:27