2011-05-16 58 views
1

我完全是XML的新手。iPhone NSXMLParse用于.asx文件

有没有人有一个示例代码来帮助我构建一个自定义类,它将解析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

在我来说,我已经能够使用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);