2011-05-16 65 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);