0

Can someone help me to find a easy way to parse XML?

I have an iOS 7 Application using Google Map API. I tried to learn this on my own. I try to create an application that uses Web Services like Google Map. These web services use HTTP requests to specific URLs, passing URL parameters as arguments to the services. Generally, these services return data in the HTTP request as either JSON or XML for parsing and/or processing by my application.

I would appreciate it.

0

Ono is pretty straightforward:

ONOXMLDocument *document = [ONOXMLDocument XMLDocumentWithData:data error:&error];

for (ONOXMLElement *element in document.rootElement.children) {
    NSLog(@"%@: %@", element.tag, element.attributes);
}

As is GDataXMLDocument:

NSData* xmlData = [[NSMutableData alloc] initWithContentsOfURL:[NSURL URLWithString:link]];

GDataXMLDocument *document = [[GDataXMLDocument alloc] initWithData:xmlData options:0 error:nil];

NSArray* entries = [document.rootElement elementsForName:@"entry"];

for(GDataXMLElement* element in entries)
{
    published = [element elementsForName:@"published"][0];
}

or NSXMLParser:

func parser(parser: NSXMLParser, didEndElement elementName: String, namespaceURI: String?, qualifiedName qName: String?) {
    if elementName == "author" {
        self.item.author = self.foundCharacters;
    }

    if elementName == "description" {
        self.item.desc = self.foundCharacters;
    }

    if elementName == "item" {
        let tempItem = Item();
        tempItem.author = self.item.author;
        tempItem.desc = self.item.desc;
        tempItem.tag = self.item.tag;
        self.items.append(tempItem);
        self.item.tag.removeAll();
    }
    self.foundCharacters = ""
}   

References

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.