简体   繁体   English

iPhone NSXMLParse for .asx文件

[英]iPhone NSXMLParse for .asx files

I'm totally new to XML . 我对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? 是否有人提供示例代码来帮助我建立一个自定义类,该类将解析Microsoft .asx文件以在iPhone上顺序播放mms流?

Some Googling revealed to me that .xml and .asx are somewhat related, though the second one is very limited if compared to the first. 一些谷歌搜索向我透露.xml和.asx有点相关,尽管第二个与第一个相比非常有限。

I need to play three streams in sequence, inside an .asx container like this: 我需要在.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>

I'm already able to parse the mms stream, decode and play the wma file. 我已经能够解析mms流,解码并播放wma文件。 I'm just not able yet to parse .asx content, to play the streams in sequence. 我只是还无法解析.asx内容,无法按顺序播放流。 Thanks! 谢谢!

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): 就我而言,我已经能够使用此代码使用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); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM