2011-12-20 247 views
0

我正在開發一個應用程序完全基於Web服務。我有一個簡單的XML一樣, 托馬斯庫克 院長 網址 [email protected] 67-876-65433 Xml遞歸解析?

<Contact:2> 
    <Name>John Appleseed</Name> 
    <Position>Department of accounting</Position> 
    <Photo>url</Photo> 
    <Email-Id>[email protected]</Email-Id> 
    <Phone-Number>45-876-65433</Phone-Number> 
    </Contact2> 

    <Contact:3> 
    <Name>Amar Smith</Name> 
    <Position>Department of Human Resource</Position> 
    <Photo>url</Photo> 
    <Email-Id>[email protected]</Email-Id> 
    <Phone-Number>54-876-65433</Phone-Number> 
    </Contact3> 

    <Contact:4> 
    <Name>Mary Cold</Name> 
    <Position>HOD of Computer Department</Position> 
    <Photo>url</Photo> 
    <Email-Id>[email protected]</Email-Id> 
    <Phone-Number>52-876-65433</Phone-Number> 
    </Contact4> 

    <Contact:5> 
    <Name>John Jobs</Name> 
    <Position>Department of Physics</Position> 
    <Photo>url</Photo> 
    <Email-Id>[email protected]</Email-Id> 
    <Phone-Number>12-876-65433</Phone-Number> 
    </Contact5> 

    <Contact:6> 
    <Name>Clark Kristan</Name> 
    <Position>Contact Person</Position> 
    <Photo>url</Photo> 
    <Email-Id>[email protected]</Email-Id> 
    <Phone-Number>65-876-65433</Phone-Number> 
    </Contact6> 
</ContactList> 

我如何分析它遞歸的方式?

首先我使用的NSXMLParser的代表方法,該方法是

1)

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

2)datafound 3)的端部元件。 但我得到的結果只有一個東西,我的意思是它只解析contact1的東西形式XML。我如何解析完整的XML?

+0

可以張貼代碼才能夠在這個問題上 – Nakkeeran 2011-12-20 07:54:20

+0

@Nakkeeran幫助,我想上面的解析xml文件,它使用我如何解析的NSXMLParser? – Tirth 2011-12-20 07:57:44

回答