Janub
Janub

Reputation: 1594

NSXMLParser issue-Tags comes Empty

This is example of my XML file

<head>
    <cat>some title here...
    <info>some info here
        <summary>bla bla bla</summary>
        <full>
        the full text here
        </full
    </info>
    </cat>
</head>

I'm using NSXMLParserDelegate method like this:

    -(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    if (qName) {
        elementName = qName;
    }

    // If it's the start of the XML, remove everything we've stored so far
    if([elementName isEqualToString:@"head"])
    {
        [self emptyDataContext];
        return;
    }
    else if([elementName isEqualToString:@"bgimage"])
    {
enter code here
    }
    // Create a new Category
    else if ([elementName isEqualToString:@"cat"]) 
    {


//array catching the values 
    }

    else if ([elementName isEqualToString:@"info"])
    {
            [add addObject:currentElementValue];
    } 
    else if([elementName isEqualToString:@"summary"])
    {

    }
    else if([elementName isEqualToString:@"full"])
    {

     }
    else if([elementName isEqualToString:@"quote"])
    {
    }

if have an array that catching all the values from the current string using the following function:

    -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if (!currentElementValue) {
        // init the ad hoc string with the value     
        currentElementValue = [[[NSMutableString alloc] initWithString:string]autorelease];
    } else {
        // append value to the ad hoc string    
        [currentElementValue setString:string]; //appendString:string];
    }
   NSLog(@"Processing value for : %@", string);

}

for some reason the "cat" and the "info" are getting blank string ... I have used some NSlogging to figure it out and igot something like this:

2011-12-19 00:40:07.557 LAO[39912:bc03] Processing value for :

2011-12-19 00:40:07.557 LAO[39912:bc03] Processing value for :"some info title..."

2011-12-19 00:40:07.558 LAO[39912:bc03] Processing value for :

2011-12-19 00:40:07.559 LAO[39912:bc03] Processing value for :

2011-12-19 00:40:07.560 LAO[39912:bc03] Processing value for : "some info title..."

2011-12-19 00:40:07.560 LAO[39912:bc03] Processing value for : "some summary contact goes here...." 2011-12-19 00:40:07.560 LAO[39912:bc03] summary 2011-12-19 00:40:07.561 LAO[39912:bc03] Processing value for :

???? please help

Upvotes: 0

Views: 85

Answers (1)

i300
i300

Reputation: 116

The XML example you posted is not valid XML. Here is a valid example XML document.

<head>
    <cat>
        <title>some title here...</title>
        <info>some info here...</info>
        <summary>bla bla bla</summary>
        <full>
            the full text here
        </full>
    </cat>
</head>

You can't just throw out text and tags into one XML tag. For exmaple, this will not work:

<info>Hello, World
    <tag>Hello</tag>
    <tag>World</tag>
</info>

To make this valid, you could do something like the following:

<info>
    <text>Hello, World</text>
    <tag>Hello</tag>
    <tag>World</tag>
</info>

Upvotes: 1

Related Questions