我完全不熟悉 XML 。
有没有人有一个示例代码来帮助我构建一个自定义类来解析Microsoft .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 内容,按顺序播放流。谢谢!
答案 0 :(得分:0)
在我的情况下,我已经能够使用 TouchXML 成功解析.asx文件,使用此代码(我在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);