Reputation: 589
i'm getting xml type of response from server but i'm unable to get the value by parsing do no where i am missing something
This was the sample Response from server :
<admin>
<logindetails
status="cdcdvfbgfhgfgfbff"
timestamp="1494499694240" isdaylighton="true"
isupdateavailable="false" updateurl="" user="1"
userParentID="0">Success</logindetails><admin>
my Parsing methods :
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(@"Element Name :%@",elementName);
recordResults =NO;
if ([elementName isEqualToString:@"logindetails"]) {
data = [soapResultsString dataUsingEncoding:NSUTF8StringEncoding];
json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"json===>%@",array);
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( recordResults )
{
[childElement appendString: string];
NSLog(@"inside%@",string);
}
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
xmlparserString=elementName;
NSLog(@"xmlparserString start -->%@",xmlparserString);
if( [xmlparserString isEqualToString:@"logindetails"])
{
recordResults =YES;
soapResultsString = [[NSMutableString alloc] init];
}
}
iam getting All tags name but i cant get the values from the Xml response please check the code and answer
Upvotes: 0
Views: 1568
Reputation: 285072
The data you are looking for are XML attributes and are returned in the attributes
dictionary in didStartElement
.
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *) elementName
namespaceURI:(NSString *) namespaceURI
qualifiedName:(NSString *) qName
attributes:(NSDictionary *) attributeDict
{
xmlparserString = elementName;
NSLog(@"xmlparserString start -->%@",xmlparserString);
if ([xmlparserString isEqualToString:@"logindetails"]) {
// soapResultsString = [[NSMutableString alloc] init];
NSLog(@"logindetails attributes --> %@", attributeDict);
}
The JSON deserialization in didEndElement
is wrong and cannot work. XML attributes are not JSON. Delete the entire if
expression
Upvotes: 2