简体   繁体   中英

Getting an XML value from an NSArray

I'm currently using SMXMLDocument as my parser and so far it does a fantastic job parsing some XML files. The only problem that I have encountered is that it cannot seem to handle children with the same name, well at least in my case. But this parser can return the parsed XML as an NSArray.

The NSArray would look like this:

    (
"<id>https://spreadsheets.goog\U2026</id>",
"<updated>2013-12-23T17:54:04.814Z</updated>",
"<category term=\"http://schemas.google.com/spreadsheets/2006#cell\" scheme=\"http://schemas.google.com/spreadsheets/2006\"/>",
"<title type=\"text\">A1</title>",
"<content type=\"text\">What?</content>",
"<link rel=\"self\" type=\"application/atom+xml\" href=\"https://spreadsheets.google.com/feeds/cells/some key/od6/private/full/R1C1\"/>",
"<link rel=\"edit\" type=\"application/atom+xml\" href=\"https://spreadsheets.google.com/feeds/cells/some key/18o84x\"/>",
"<cell row=\"1\" col=\"1\" inputValue=\"What?\">What?</cell>",
"<id>A1</id>",
"<status code=\"200\" reason=\"Success\"/>",
"<operation type=\"update\"/>")

So my question is, how would I get the values (and attributes) from the XML? If there is a way to tokenize this (ie going through the array as an NSString with a for-in loop or something) without having to use a big fancy library that would be great. Thanks in advance.

Update:

Here is the NSLog of what happens if I try to get id with SMXMLDocument:

Code:

    SMXMLElement* testEntry = [feed childNamed:@"entry"];

        NSLog(@"id: %@", [testEntry valueWithPath:@"id"]);

Output:

    id: https://spreadsheets.google.com/feeds/cells/some key/od6/private/full/R1C1

After hours of battling with the code, I ended up using another parser (as a secondary) called SHXMLParser because of it's neat syntax. It is capable returning multiple values from nodes with the same name as an NSArray. From there I just compared the contents in the array and picked the one I wanted.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM