我对XML完全陌生。
是否有人有一个示例代码来帮助我构建一个自定义类,该类将解析微软.asx文件以在iPhone上按顺序播放mms流?
一些谷歌用户向我透露,.xml和.asx有一定的关系,不过第二条相对于前者来说非常有限。
我需要在.asx容器中按顺序播放三个流,如下所示:
<asx version="3.0">
<TITLE>MYSONGS</TITLE>
<entry>
<TITLE>www.mysite.com</TITLE>
<ref href="mms://mysite.com/musicFolder/song1.wma" />
</entry>
<entry>
<TITLE>MYSONGS</TITLE>
<ref href="mms://mysite.com/musicFolder/song2.wma" />
</entry>
<entry>
<TITLE>www.mysite.com</TITLE>
<ref href="mms://mysite.com/musicFolder/song3.wma" />
</entry>
</asx>我已经能够解析mms流,解码和播放wma文件。我只是还无法解析.asx内容,无法按顺序播放流。谢谢!
发布于 2011-11-10 15:59:34
在我的例子中,我已经能够使用TouchXML成功地解析TouchXML文件(我从http://foobarpig.com/iphone/parsing-xml-element-attributes-with-touchxml.html):的原始版本中修改了这段代码)
// we will put parsed data in an a array
NSMutableArray *res = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString: @"http://www.yoursite.com/WindowsMediaDotCom/theFileToParse.asx"];
/* have TouchXML parse it into a CXMLDocument */
CXMLDocument *document = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];
NSArray *nodes = NULL;
// searching for piglet nodes
nodes = [document nodesForXPath:@"//ref" error:nil];
for (CXMLElement *node in nodes) {
NSMutableDictionary *item = [[NSMutableDictionary alloc] init];
int counter;
for(counter = 0; counter < [node childCount]; counter++) {
// common procedure: dictionary with keys/values from XML node
[item setObject:[[node childAtIndex:counter] stringValue] forKey:[[node childAtIndex:counter] name]];
}
// and here it is - attributeForName! Simple as that.
[item setObject:[[node attributeForName:@"href"] stringValue] forKey:@"href"]; // <------ this magical arrow is pointing to the area of interest
[res addObject:item];
[item release];
}
// and we print our results
NSLog(@"%@", res); https://stackoverflow.com/questions/6022454
复制相似问题