I have a strange problem with back button in NavigationController. If I use parser and then I click Back button, I get EXC_BAD_ACCESS. Why?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_lbRouteNum.text = self.RouteNumber;
self.InfoTableView.dataSource = self;
self.InfoTableView.delegate = self;
lbCity = [[NSMutableArray alloc] initWithCapacity:1];
// [lbCity addObject:#"sdfsdfsdfsdfsd"];
NSData * XMLData = [self.response dataUsingEncoding:NSUnicodeStringEncoding];
NSXMLParser * parser = [[NSXMLParser alloc] initWithData:XMLData];
[parser setDelegate:self];
[parser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:#"Citys"])
{
//do something
}
}
If I comment this
//NSData * XMLData = [self.response dataUsingEncoding:NSUnicodeStringEncoding];
//NSXMLParser * parser = [[NSXMLParser alloc] initWithData:XMLData];
//[parser setDelegate:self];
//[parser parse];
and for test uncomment this
[lbCity addObject:#"sdfsdfsdfsdfsd"];
all working good.
If I change parsing code for test on:
if ([elementName isEqualToString:#"Citys"])
{
[lbCity addObject:#"sdfsdfsdfsdfsd"];
}
2 times all open an back ok on 3rd when I click Back button App crash with EXC_BAD_ACCESS (
Solution:
I move to ARC and all problems gone. Thanks.
Related
I'm new to this web service in iOS. I made a sample web service app and made the first stage login successfully. While checking the url in web after login I got this output :
<Rows>
<Row>
<style>LW6001TA</style>
<thumbnail1>
/9j/4AAQSkZJRgABAQEAAAAAAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAHCAV8DASIAAhEBAxEB/8QAHwAAAQUBAQEB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UlePO1mAxkZq6kaxqFRQqjoAMAU6gAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACsrxHokXiPQLzSZppIUuU2mSPqvOf6Vq0UAfNWufA/wAT6ezNp/kalDnjy3CPj3Vv6GuVfwD4tRmU+HtQyvXEJP8AKvr+igD4tvtB1fTW232mXluT08yFh/SqXkTZC+VJk9BtNfbrxpIMOisPQjNRfY7YsGNtFuHQ7BkUAfFP2W4HW3l/74NNMEoGTE4+qmvtr7PAf+WMf/fIprWdq4w1tCQexQUAfEm1vQ1IlvPIMxwyOPVVJr7R/sjTf+gfa/8Aflf8Kmis7aBdsVtEi+ioAKAPir7JdAZNtMP+2Z/wqMwTZ/1Un/fJr7cMERH+qT/vkU37Jbf8+8X/AHwKAPiZ7aeNd7wSqvqUIFRV9uyWltNGY5LeJ0PVWQEGsQeA/CgnM3/CPafvJyT5A6/TpQB8eil7V9ReKvhF4c8QWxNnbJpl4v3ZbdAFP+8vQ/zrzCT4DeKFnKpdaeyZ4fzGGR64xQB5Xzmpktrh/uQSsPZCa+lPAnwj0zwygu9UWLUNSP8AEy5jj/3Qep9zXoiWtvGMJBGo9kAoA+LY9K1GVgsdhdOT0Cwsc/pWlH4M8Ty/c0DUT/27t/hX2II0HRFH0FOoA+SrL4Y+M75gI9BuIwf4piIx+pruNB+Ad9Ntk13UY7de8Nt87f8AfR4H6177RQBxmi/Czwhou1otKS4mX/lpdEyH8jx+ldikaRIEjRURRgKowBTqKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD/9k=
</thumbnail1>
</Row>
</Rows>
How to get these stuff back in Xcode and view it ? This is the first time I work on this web service I have no idea to get back this response back in Xcode. Please Help !
-(void)parseTheData
{
//Here convert your response to NSData type (NSData *data = [NSData data]; , i have used just for example)
NSData *data = [NSData data];
// Make sure that there is data.
if (data != nil) {
self.xmlParser = [[NSXMLParser alloc] initWithData:data];
self.xmlParser.delegate = self;
// Initialize the mutable string that we'll use during parsing.
self.foundValue = [[NSMutableString alloc] init];
// Start parsing.
[self.xmlParser parse];
}
}
//Delegate methods
-(void)parserDidStartDocument:(NSXMLParser *)parser{
// Initialize the array.
self.arrNeighboursData = [[NSMutableArray alloc] init];
}
-(void)parserDidEndDocument:(NSXMLParser *)parser{
// When the parsing has been finished then simply reload the table view or do what ever you want
}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
NSLog(#"%#", [parseError localizedDescription]);
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
// If the current element name is equal to "geoname" then initialize the temporary dictionary.
if ([elementName isEqualToString:#"Row"]) {
self.dictTempDataStorage = [[NSMutableDictionary alloc] init];
}
// Keep the current element.
self.currentElement = elementName;
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"thumbnail1"]) {
// Store the data like this
[self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:#"thumbnail1"];
}
else if ([elementName isEqualToString:#"style"]){
// Store the data like this
[self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:#"style"];
}
else if ([elementName isEqualToString:#"Row"])
{
//Add the dictionary in array and remove the data from dictionary, so that we can reuse the dictionary
[self.arrNeighboursData addObject:self.dictTempDataStorage];
self.dictTempDataStorage = nil;
}
// Clear the mutable string.
[self.foundValue setString:#""];
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
// Store the found characters if only we're interested in the current element.
if (![string isEqualToString:#"\n"]) {
[self.foundValue appendString:string];
}
}
Here I am just showing you the way to move on.
I'm trying to gather the data from an XML file and add to an array. The data looks something like this..
<Placemark>
<name><![CDATA[Kingsway (Start)]]></name>
<description><![CDATA[]]></description>
<TimeStamp><when>2014-04-30T17:03:28.681Z</when></TimeStamp>
<styleUrl>#start</styleUrl>
<Point>
<coordinates>-1.408894,52.13977,176.0</coordinates>
</Point>
</Placemark>
<Placemark id="tour">
<name><![CDATA[Kingsway]]></name>
<description><![CDATA[]]></description>
<styleUrl>#track</styleUrl>
<ExtendedData>
<Data name="type"><value><![CDATA[running]]></value></Data>
</ExtendedData>
<gx:MultiTrack>
<altitudeMode>absolute</altitudeMode>
<gx:interpolate>1</gx:interpolate>
<gx:Track>
<when>2014-04-30T17:03:28.681Z</when>
<gx:coord>-1.408894 52.13977 176.0</gx:coord>
<when>2014-04-30T17:03:31.071Z</when>
<gx:coord>-1.407839 52.139166 174.0</gx:coord>
<when>2014-04-30T17:03:32.070Z</when>
<gx:coord>-1.407486 52.138963 175.0</gx:coord>
<when>2014-04-30T17:03:33.073Z</when>
<gx:coord>-1.407142 52.138755 174.0</gx:coord>
<when>2014-04-30T17:03:34.073Z</when>
<gx:coord>-1.406805 52.138555 173.0</gx:coord>
<when>2014-04-30T17:03:35.073Z</when>
<gx:coord>-1.40663 52.138441 173.0</gx:coord>
<when>2014-04-30T17:03:36.601Z</when>
<gx:coord>-1.405929 52.138027 172.0</gx:coord>
<when>2014-04-30T17:03:37.601Z</when>
<gx:coord>-1.405574 52.137817 172.0</gx:coord>
I'm only interested in the values following the tag gx:coord, so I'm parsing the file using the code below.
- (void)loadMap:(NSInteger)selJourney
{
NSString *journey = #"KML_Sample";
NSString *path = [[NSBundle mainBundle] pathForResource:journey ofType:#"kml"];
[self parseXMLFile:path];
}
- (void)parseXMLFile:(NSString *)pathToFile
{
NSXMLParser *addressParser;
[myParser setShouldProcessNamespaces:NO];
[myParser setShouldReportNamespacePrefixes:NO];
[myParser setShouldResolveExternalEntities:NO];
NSURL *xmlURL = [NSURL fileURLWithPath:pathToFile];
myParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[myParser setDelegate:self];
[myParser setShouldResolveExternalEntities:YES];
[myParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ( [elementName isEqualToString:#"gx:coord"] ) {
polylineList = [[NSMutableArray alloc] init];
}
}
When the parser method runs and it finds the right elementName I want to retrieve the string data after the tag and add it to my NSMutableArray polylineList.
The other parameters in parser all return nil so am I missing something?
I managed to solve this myself using the method below
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ((addRec) && (![string isEqualToString:#"\n"]))
{
NSArray *tmpArray = [[NSArray alloc] initWithObjects:string, nil];
if (polylineList.count > 0)
[polylineList addObject:string];
else
polylineList = [[NSMutableArray alloc] initWithArray:tmpArray];
}
}
I hope this is helpful to those who are using KML, MapKit or just parsing XML.
I am creating an IOS application. In which I have to use SOAP web-service to get some details. So that I have used SUDZ-C to generate the stub. I can able to call web-service and got the response. But I can't parse the response. The below is the XML response.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ViewAppTrackResponse xmlns="http://service.cmp.app.com">
<ViewAppTrackResponseReturn>
<ns1:monthBO xmlns:ns1="http://response.cmp.app.com">
<monthListItem>
<ns2:date xmlns:ns2="http://bean.cmp.app.com">1-2-2014, Saturday (nonworking day)</ns2:date>
<ns3:lockStatus xmlns:ns3="http://bean.cmp.app.com">N</ns3:lockStatus>
<ns4:dailyTime xsi:nil="true" xmlns:ns4="http://bean.cmp.app.com"/>
<ns5:taskListNew xsi:nil="true" xmlns:ns5="http://bean.cmp.app.com"/>
</monthListItem>
<monthListItem>
<ns6:date xmlns:ns6="http://bean.cmp.app.com">2-2-2014, Sunday (nonworking day)</ns6:date>
<ns7:lockStatus xmlns:ns7="http://bean.cmp.app.com">N</ns7:lockStatus>
<ns8:dailyTime xmlns:ns8="http://bean.cmp.app.com">04:00</ns8:dailyTime>
<ns9:taskListNew xmlns:ns9="http://bean.cmp.app.com">
<taskListItem>
<ns9:trackId>1070</ns9:trackId>
<ns9:taskId>14</ns9:taskId>
</taskListItem>
<taskListItem>
<ns9:trackId>1094</ns9:trackId>
<ns9:taskId>44</ns9:taskId>
</taskListItem>
</ns9:taskListNew>
</monthListItem>
<monthListItem>
<ns10:date xmlns:ns10="http://bean.cmp.app.com">3-2-2014, Monday</ns10:date>
<ns11:lockStatus xmlns:ns11="http://bean.cmp.app.com">N</ns11:lockStatus>
<ns12:dailyTime xmlns:ns12="http://bean.cmp.app.com">08:00</ns12:dailyTime>
<ns13:taskListNew xmlns:ns13="http://bean.cmp.app.com">
<taskListItem>
<ns13:trackId>1071</ns13:trackId>
<ns13:taskId>14</ns13:taskId>
</taskListItem>
<taskListItem>
<ns13:trackId>1073</ns13:trackId>
<ns13:taskId>44</ns13:taskId>
</taskListItem>
</ns13:taskListNew>
</monthListItem>
</ns1:monthBO>
<ns14:userId xsi:nil="true" xmlns:ns114="http://response.cmp.app.com"/>5</ns14:userId>
</ViewAppTrackResponseReturn>
</ViewAppTrackResponse>
</soapenv:Body>
</soapenv:Envelope>
Can anyone help me to parse this response. This will helpful for me.
LibXML2 is included in Cocoa.
http://www.raywenderlich.com/553/xml-tutorial-for-ios-how-to-choose-the-best-xml-parser-for-your-iphone-project
http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
You can use NSXMLParser class to parse this.Using its delegate methods you can parse. I am posting my try to parse your xml.It is not completed.I am giving you a basic code for parsing. You have to do the remaining.
Here "xmlInput" is of type NSString with your xmlstring.
NSData* xmlData = [xmlInput dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser * xmlParser = [[NSXMLParser alloc] initWithData:[xmlData copy]];
[xmlParser setDelegate:(id)self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
Create an xmlparser object and input your xmlData.Set its delegates.
//this delegate calls when parsing start.Only once.
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
recordResults = NO;//declared in .h
MonthFlag = NO;//declared in .h
TaskFlag = NO;//declared in .h
Arry = nil;//declared in .h
}
// This delgate calls when each tag name is found.
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
strElementName = [elementName copy];//strElementName is declared in .h
NSLog(#"%#",strElementName);
if([elementName isEqualToString:#"monthListItem"]){
MonthFlag = YES;
}
if([elementName isEqualToString:#"taskListItem"]){
TaskFlag = YES;
}
strElementValue = #""; //strElementValue is declared in .h
}
//This is called when each tag value is found.
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
strElementValue = [NSString stringWithFormat:#"%#%#", strElementValue,[string copy]];
NSLog(#"%#",strElementValue);
//NSLog(#"%# : %#",strElmentName,strElementValue);
recordResults=(strElementValue.length > 0);
}
// This deleagte will call in the end of each tag name.
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(#"%# - %#",elementName,strElementValue);
if (recordResults) {
if (MonthFlag) {
if(dicTemp==nil){
dicTemp = [[NSMutableDictionary alloc] init];
for (int i=0; i<10; i++) {
[dicTemp setObject:#"" forKey:strElementName];
}
}
[dicTemp setObject:strElementValue forKey:elementName ];
}
}
if(([elementName isEqualToString:#"monthListItem"] ) && dicTemp!=nil) {
if(Arry==nil)Arry = [[NSMutableArray alloc] init];
[Arry addObject:[dicTemp copy]];
dicTemp = nil;
[dicTemp release];
MonthFlag = NO;
NSLog(#"arry test %#",[Arry description]);
}
}
// This delegate will call when parsing finishes . only once
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
recordResults = NO;
}
I am trying to grab a token from a website. Upon successful authentication, an XML document would be displayed.
I created a connection as shown below:
NSString *strURLQueryString = [NSString stringWithFormat:#"%#?username=%#&password=%#", kURL_LOGIN, nameString, passwordString];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:strURLQueryString]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
In order to display the output, I used this:
unsigned char byteBuffer[[receivedData length]];
[receivedData getBytes:byteBuffer];
NSLog(#"Output: %s", (char *)byteBuffer);
So some of the output of the returned document is as shown below:
<status>0</status><reason>User fetched.</reason><token>9cb7396dccabe68c067521db219afb83</token>
I have read many XML parsing implementation but I just could not implement it as it does not fulfil my need, and I just could not understand the complexity of its explanation.
Would appreciate if anyone could give me a good advice on how to go about.
- (XMLParserViewController *) initXMLParser {
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"Books"]) {
appDelegate.books = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:#"Book"])
{
aBook = [[Books alloc] init];
}
NSLog(#"Processing Element: %#", elementName);
}
- (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([elementName isEqualToString:#"Books"])
return;
if([elementName isEqualToString:#"Book"])
{
[appDelegate.books addObject:aBook];
aBook = nil;
}
else if([elementName isEqualToString:#"name"])
{
aBook.name=currentElementValue;
}
else if([elementName isEqualToString:#"address"])
{
aBook.address=currentElementValue;
}
else if([elementName isEqualToString:#"country"])
{
aBook.country=currentElementValue;
}
currentElementValue = nil;
NSLog(#"%#",aBook.name);
NSLog(#"%#",aBook.address);
NSLog(#"%#",aBook.country);
}
Try this ,, I hope this works....
The relevant NSXMLParserDelegate methods:
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName //etc
{ _inToken = [elementName isEqualToString:#"token"]; }
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName //etc
{ _inToken = NO; }
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (_inToken) {
_token = string;
[parser abortParsing];
}
}
You should use XML parser.
It is easy to use, go all below steps to get best result:
Create XMLParser class subclasses from NSXMLParser, so you have a NSXMLParser.h and NSXMLParser.m class
your .h class must be like this:
#import <Foundation/Foundation.h>
#interface XMLParser : NSXMLParser <NSXMLParserDelegate>{
NSUInteger parsedCounter;
BOOL accumulatingParsedCharacterData;
BOOL didAbortParsing;
}
#property (nonatomic, strong) NSMutableString *currentParsedCharacterData;
#property (nonatomic, strong) NSMutableArray *currentParsedCharacterArray;
#end
And .m class :
#import "XMLParser.h"
#implementation XMLParser
#pragma mark Parser constants
// Limit the number of parsed data to 100.
static const NSUInteger kMaximumNumberOfFilesToParse = 100;
static NSUInteger const kSizeOfFileBatch = 10;
// Reduce potential parsing errors by using string constants declared in a single place.
static NSString * const kEntryElementName = #"dlResult";
static NSString * const kStringElementName = #"string";
#pragma mark NSXMLParser delegate methods
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
// NSLog(#"didStart");
// If the number of parsed earthquakes is greater than kMaximumNumberOfEarthquakesToParse, abort the parse.
if (parsedCounter >= kMaximumNumberOfFilesToParse) {
// Use the flag didAbortParsing to distinguish between this deliberate stop and other parser errors.
didAbortParsing = YES;
[self abortParsing];
}
if ([elementName isEqualToString:kEntryElementName]) {
_currentParsedCharacterArray = [[NSMutableArray alloc]init];
} else if ([elementName isEqualToString:kStringElementName]) {
accumulatingParsedCharacterData = YES;
_currentParsedCharacterData = [[NSMutableString alloc]init];
}
}
// return string between tags
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
// NSLog(#"foundCh");
if (accumulatingParsedCharacterData) {
// If the current element is one whose content we care about, append 'string'
// to the property that holds the content of the current element.
[_currentParsedCharacterData appendString:string];
NSLog(#"currentParsedCharacterData:%#",_currentParsedCharacterData);
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
// NSLog(#"didEnd");
if ([elementName isEqualToString:kStringElementName]) {
[_currentParsedCharacterArray addObject:_currentParsedCharacterData];
}
accumulatingParsedCharacterData = NO;
}
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError {
if (didAbortParsing == NO) {
// Pass the error to the main thread for handling.
[self performSelectorOnMainThread:#selector(handleError:) withObject:parseError waitUntilDone:NO];
}
}
#end
In .m class there are two const string:
static NSString * const kEntryElementName = #"dlResult";
static NSString * const kStringElementName = #"string";
those are string tags,the tags that you should implement are "status", "reason" "token"
from connection class, send data connection to XMLParser class like below:
#autoreleasepool {
// It's also possible to have NSXMLParser download the data, by passing it a URL, but this is not desirable
// because it gives less control over the network, particularly in responding to connection errors.
//
XMLParser *parser = [[XMLParser alloc] initWithData:data];
parser.currentParsedCharacterArray = [NSMutableArray array];
parser.currentParsedCharacterData = [NSMutableString string];
[parser setDelegate:parser];
[parser parse];
// depending on the total number of earthquakes parsed, the last batch might not have been a "full" batch, and thus
// not been part of the regular batch transfer. So, we check the count of the array and, if necessary, send it to the main thread.
if ([parser.currentParsedCharacterArray count] > 0) {
// send parsed data to another class or ...
// parser.currentParsedCharacterArray is parsed data
}
parser.currentParsedCharacterArray = nil;
parser.currentParsedCharacterData = nil;
}
if you have any question, ask me!
I got an iOS app. All data stores in xml files.
<?xml version="1.0" encoding="utf-8"?>
<objects>
<object
name="Скульптура Р. Исмагилова «Пермяк – соленые уши»"
xcoord="58.00998487478568"
ycoord="56.239829063415527"
type=""
description=""
external_name="gl1" />
</objects>
So, i want to parse this XML file to NSMutableArray
I do it with NSXMLParser deleagate class. This is class's code:
#implementation XMLParser
#synthesize aPLace;
- (XMLParser *) initXMLParser {
[super init];
appDelegate = (XMLAppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
NSLog(#"parsing");
if([elementName isEqualToString:#"objects"]) {
//Initialize the array.
appDelegate.books = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:#"object"]) {
//Initialize the book.
aPLace = [[Place alloc] init];
//Extract the attribute here.
aPLace.name = [[attributeDict objectForKey:#"name"] string];
NSLog(#"Reading name :%#", aPLace.name);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:#"objects"])
return;
if([elementName isEqualToString:#"object"]) {
[appDelegate.greenLine addObject:aPLace];
}
}
#end
You can see that there is NSLog(#"parsing"); in didStartElement function. But output is empty.
So, i implement parsing in AppDelegateClass's function applicationDidFinishLaunching
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSURL *url = [[NSURL alloc] initWithString:#"greenline_ru.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
and every time output is Error Error Error!!! why? What's the problem?
NSURL *url = [[NSURL alloc] initWithString:#"greenline_ru.xml"];
I think this is your problem. If you have file you should use something like
NSString *path = [[NSBundle mainBundle] pathForResource:#"greenline_ru"
ofType:#"xml"];
[[NSXMLParser alloc] initWithData:[NSData dataWithContentsOfFile:path]]
Use TBXML, this is quite easy to use...
Study this- http://www.tbxml.co.uk/TBXML/API.html