开发者

how to do multiple xml parsing in my class

I need to do xml parsing in my class.

i found

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

}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{


}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)ele开发者_运维知识库mentName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{

 }

But in need to do parsing two times one after another,How can i done using these methods

can any one pls help me.

Thank u in advance.


You want to do something like this?

Have a flag variable of any type. Let us consider the flag variable is NSString. And you are going to parse two XML files. Consider, one XML is for listing items and another one is for detail view.

Before you parse the first XML (the XML for list, in our case) you set the flag something like this,

NSString *xmlContentFlag = @"List";

Then, before you parse the second XML (the XML for detail) you set the flag something like this,

NSString *xmlContentFlag = @"Detail";

In your parser methods, do the following,

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

    if ([xmlContentFlag isEqualToString:@"List"]) {

        // your code here

    } else if ([xmlContentFlag isEqualToString:@"Detail"]) {

        // your code here
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

    if ([xmlContentFlag isEqualToString:@"List"]) {

        // your code here

    } else if ([xmlContentFlag isEqualToString:@"Detail"]) {

        // your code here
    }
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName 
    namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

    if ([xmlContentFlag isEqualToString:@"List"]) {

        // your code here

    } else if ([xmlContentFlag isEqualToString:@"Detail"]) {

        // your code here
    }
 }

Note: You can have the flag to be of any type, not necessarily NSString.

I hope this is what you expect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜