iPhone NSXMLParse for .asx 文件

发布于 2024-11-07 06:41:13 字数 802 浏览 3 评论 0原文

我对 XML 完全陌生。

有谁有示例代码来帮助我构建一个自定义类,该类可以解析 Microsoft .asx 文件以在 iPhone 上按顺序播放彩信流?

一些谷歌搜索告诉我,.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 内容,以按顺序播放流。谢谢!

I'm totally new to XML.

Does anyone have a sample code to help me build a custom class that would parse Microsoft .asx files to play mms streams in sequence on the iPhone?

Some Googling revealed to me that .xml and .asx are somewhat related, though the second one is very limited if compared to the first.

I need to play three streams in sequence, inside an .asx container like this:

<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>

I'm already able to parse the mms stream, decode and play the wma file. I'm just not able yet to parse .asx content, to play the streams in sequence. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

煮酒 2024-11-14 06:41:14

就我而言,我已经能够使用 TouchXML 成功解析 .asx 文件,使用此代码(我从 http://foobarpig.com/iphone/ 上提供的原始版本修改了该代码)解析-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); 

In my case I've been able to successfully parse .asx files using TouchXML, using this code (that I modified from the original version available at 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); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文