0

I need to get XML data from this particular address (https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml). But when I run the application, nothing happens. Also honestly I do not know how to get from the above xml id 1, id 2 and so on. I'll be happy for any of your advice. Thx

- (id)initWithArray: (NSMutableArray *)slovoArray {
    self = [super init];
    if (self) {
        self.slovoArray = slovoArray;
    }
    return self;
}
- (void)parseXMLFile
{
    NSURL *url = [[NSURL alloc] initWithString:@"https://www.cnb.cz/cs/financni_trhy/devizovy_trh/kurzy_devizoveho_trhu/denni_kurz.xml"];

    self.parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
      self.parser.delegate = self;
     [self.parser parse];  
}
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qualifiedName
    attributes:(NSDictionary *)attributeDict {

    self.element = elementName;

    if ([_element isEqualToString:@"radek"]) {

        _item    = [[NSMutableDictionary alloc] init];
        self.kod   = [[NSMutableString alloc] init];
        self.kurz    = [[NSMutableString alloc] init];   
    }
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    if ([self.element isEqualToString:@"kod"])
    {
        [self.kod appendString:string];
    }
    else if ([self.element isEqualToString:@"kurz"])
    {
        [self.kurz appendString:string];
    }
}
- (void)parser:(NSXMLParser *)parser
 didEndElement:(NSString *)elementName
  namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName {

    if ([elementName isEqualToString:@"radek"]) {
        Slova *thisSlovo = [[Slova alloc] initWithName:self.kod
                                              kurz:self.kurz];
        [self.slovoArray addObject:thisSlovo];
    }
    self.element = nil; 
}
@end

2 Answers 2

1

Try this

 NSURL *url = [NSURL URLWithString: @"Enter Here your webservice url" ];
 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
  NSURLResponse* response;
  NSError* error;
 NSData* result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
 NSString *  rsltStr = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];
 NSError *parseError = nil;
 NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:rsltStr error:&parseError];  // In this I have used XMLReader file

Download XML Reader file from here : - XML Reader Download

For more help about XMLReader Visit here :- SOAP webservice calling in iOS with xml parsing

Sign up to request clarification or add additional context in comments.

Comments

0

To read XML data from URLs, I recently wrote a simple XML parser for iOS called ConiferXML that might do what you're looking for. You can check it out at GitHub. If this doesn't work out there is also another library on GitHub that is a little more complex but does the same thing.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.