开发者

Parsing xml from .xml responce.+iphone

开发者 https://www.devze.com 2023-03-25 20:46 出处:网络
i want to prase the xml like below:- <RoomType productId=\"1215560;1973855;189629\" name=\"Standard\" nights=\"2\" startDate=\"2011-08-10T00:00:00-04:00\" isAvailable=\"true\" roomId=\"3\" hotel

i want to prase the xml like below:-

    <RoomType productId="1215560;1973855;189629" name="Standard" nights="2" startDate="2011-08-10T00:00:00-04:00" isAvailable="true" roomId="3" hotelRoomTypeId="1973855">
    <Avail offset="0" status="true" />
        <Avail offset="1" status="true" />
            <Occup occupId="1215560;1973855;189629;2;2;2" maxAdult="4" maxChild="2" price="416.46" tax="60.66" dblBed="true" avrNightPrice="208.23">
            <Board bbId="1" name="Continental Breakfast" price="0" default="false" />
                <Room seqNum="1" adultNum="2" childNum="2">
                    <Child age="8" />
                        <开发者_开发知识库;Child age="10" />
                    </Room>
                    <Price offset="0" value="208.23" />
                    <Price offset="1" value="208.23" />
            </Occup>
</RoomType>

How do i parse such xml file in iphone.

Is there any method to parse such.

Please help me.. Thanks in advance


You can use NSXMLParser. In the delegate method you can get the values from the dictionary as follows:

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if(elementName isEqualToString:@"RoomType")
{
NSString *productId = [attributeDict objectForKey:@"productId"];
}
}

Similarly you can do for the other items.


You can use NSXMLParser for parsing xmls. You have to implement NSXMLParserDelegate methods. You can check the ParseOperation class in LazyTableImages code sample for a very basic implementation of xml parser delegate.

0

精彩评论

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

关注公众号