0

I'm using Element parser to parse some xml from a local file right now but I'm wanting to be able to retrive this xml file from the web and then parse it with Element Parser. However, my app crashes when I try to use NSURL to get the xml file. So far the code I was trying to use was:

    NSURL *url = [[NSURL alloc] initWithString:@"http://example.com/file.xml"]

The code I use for retrieving the local xml file is:

NSString* path = [[NSBundle mainBundle] pathForResource: @"file" ofType: @"xml"];
NSStringEncoding encoding;
self.source = [NSString stringWithContentsOfFile: path usedEncoding: &encoding error:     NULL];
DocumentRoot *document = [Element parseXML:source];

So how can this be done? I also tried to do parseXMLFromURL but it doesn't work so I'm lost. Any help would be much appreciated. Thanks

2
  • Where is the documentation for this parser you're using? I googled it and can't find any reference to "Element" parser. Commented Dec 20, 2010 at 4:35
  • The only documentation is from here: touchtank.wordpress.com/element-parser Commented Dec 20, 2010 at 4:46

1 Answer 1

1
    NSString *stringUrl = @"http://yourDomain.com/yourXml"
    NSURL *finalURL = [NSURL URLWithString:[stringUrl stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];
    NSString *xmlString = [NSString stringWithContentsOfURL:finalURL    
                                                   encoding:NSUTF8StringEncoding 
                                                      error:nil];
Sign up to request clarification or add additional context in comments.

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.