1

我对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内容,按顺序播放流。谢谢!

4

1 回答 1

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); 
于 2011-11-10T15:59:34.317 回答