Can't get XML element with colon in the name using TouchXML
I have the following code:
NSString *subtitle = [[[node elementsForName:@"subtitle"] objectAtIndex:0] stringValue];
NSString *duration = [[[node elementsForName:@"itunes:duration"] objectAtIndex:0] stringValue];
The first line works perfectly. The second line though won't开发者_JAVA技巧 work. I assume it has something to do with namespaces, but I'm pretty new to all of this so I would appreciate any guidance. Thank you!
It turns out that I can use the elementsForLocalName:URI:
to read the element correctly. Now the problem is that since I am using the TouchXML library, it doesn't seem like that method has been mapped over to the CXMLElement
structure (see here).
So the question now is: how can I convert a CXMLElement
to an NSXMLElement
so that I can use that method?
"itunes" is the namespace identifier. It doesn't actually have any significance on its own, it just links a URI with the element in question. It looks like you're using the iTunes RSS extensions, which live under the namespace http://www.itunes.com/dtds/podcast-1.0.dtd
.
So, for namespaced elements, I think (I'm not familiar with Objective-C or NSXML :P) you want to use elementsForLocalName
instead:
[node elementsForLocalName: @"duration" URI: @"http://www.itunes.com/dtds/podcast-1.0.dtd"]
For the answer to the second question, see comments below.
精彩评论