I am parsing a xml file which giving an error
NSXMLParserErrorDomain error 41
Will anyone tell me what is the reason of this error and how to solve this error.
Thank in Advance.
XML File Is Like
<GetOpenQuestionsForUserResult>
<Questions Count="2">
<Question id="44">
<Question Title>test for mitesh</Question Title>
<Question Description>please respond from mobile</Question Description>
<Creator Name>test@abc.com</Creator Name>
<Creation Date>08/29/2011</Creation Date>
<Respondent Names>test@abc.com</Respondent Names>
<Anonymous Answers>Yes</Anonymous Answers>
<Expiry Date>08/29/2011</Expiry Date>
</Question>
<Question id="45">
<Question Title>test for mitesh 2</Question Title>
<Question Description>second question for mitesh mobile</Question Description>
<Creator Name>test1@abc.com</Creator Name>
<Creation Date>08/29/2011</Creation Date>
<Respondent Names>test1@abc.com</Respondent Names>
<Anonymous Answers>Yes</Anonymous Answers>
<Expiry Date>08/31/2011</Expiry Date>
</Question>
</Questions>
</GetOpenQuestionsForUserResult>
</GetOpenQuestionsForUserResponse>
Please Tell Me How to parse This xml File
I did Following Code for parsing
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:@"Question"])
{
[QuesIdArray addObject: [attributeDict objectForKey:@"id"]];
}
else if([elementName isEqualToString:@"Question Title"])
{
}
else if([elementName isEqualToString:@"Question Description"])
{
}
else if([elementName isEqualToString:@"Creator Name"])
{
}
else if([elementName isEqualToString:@"Creation Date"])
{
}
else if([elementName isEqualToString:@"Respondent Names"])
{
}
else if([elementName isEqualToString:@"Anonymous Answers"])
{
}
else if([elementName isEqualToString:@"Expiry Date"])
{
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];
NSLog(@"Processing Value: %@", currentElementValue);
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if(currentElementValue)
currentElementValue = [currentElementValue stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([elementName isEqualToString:@"Error"])
{
//appDelegate.ErrorString = [ [ NSString alloc ] initWithString: currentElementValue ] ;
}
else if([elementName isEqualToString:@"Question Title"])
{
[QuesTitleArray addObject:currentElementValue];
}
else if([elementName isEqualToString:@"Question Description"])
{
[QuesTextArray addObject:currentElementValue];
}
else if([elementName isEqualToString:@"Creator Name"])
开发者_Go百科{
[QuesCreatorArray addObject:currentElementValue];
}
else if([elementName isEqualToString:@"Creation Date"])
{
[QuesCreationDateArray addObject:currentElementValue];
}
else if([elementName isEqualToString:@"Respondent Names"])
{
[ResNamesArray addObject:currentElementValue];
}
else if([elementName isEqualToString:@"Anonymous Answers"])
{
[QuesAnswerArray addObject:currentElementValue];
}
else if([elementName isEqualToString:@"Expiry Date"])
{
[QuesExpiryDateArray addObject:currentElementValue];
}
//[currentElementValue release];
currentElementValue = nil;
}
can Anyone tell me what mistake i done here. It giving an error: NSXMLParserErrorDomain error 41
From NSXMLParser reference - 41 error code value is NSXMLParserAttributeHasNoValueError
The problem is that your xml is malformed as xml tag names cannot contain spaces. For example
<Question Title>...
Here tag name is 'Question' and 'Title' is interpreted as attribute name, which has no value. You should correct your xml to fix that (i.e. remove spaces in tag names).
try dont giving spaces for the tag names,
say, u gave <Question Title>test for mitesh</Question Title>
make it
<QuestionTitle>test for mitesh</QuestionTitle>
Other tags also, and try
NSXMLParserErrorDomain error 41
means that an attribute doesn't have a value. Because you are not naming elements correctly, you ultimately get an attribute without a value.
精彩评论