2016-06-21 48 views
0

我在使用Brightscript和處理XML內容方面都很缺乏經驗,但我目前面臨同時開發roku應用程序的挑戰。目前,我需要弄清楚如何從聯機文檔中對一些XML進行排序以獲取必要的數據。任何意見,將不勝感激。在Brightscript中使用XML的困難

這裏是XML文檔的樣子。 (MediaModel節點中存在更多的項目,但我不認爲我需要他們。)

<ArrayOfMediaModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/BlueBridgeIntegration.Models"> 
    <MediaModel> 
    <Archive_ID>...</Archive_ID> 
    <Archive_Title>...</Archive_Title> 
    <Description>...</Description> 
    <Image_Path>...</Image_Path> 
    <MP3>...</MP3> 
    <MP4>...</MP4> 
    <RTMP_Path>...</RTMP_Path> 
    <Series_ID>...</Series_ID> 
    <Title>...</Title> 
    </MediaModel> 
    <MediaModel>...</MediaModel> 
    <MediaModel>...</MediaModel> 
    ... 
    <MediaModel>...</MediaModel> 
</ArrayOfMediaModel> 

雖然總結,這是該文件的程度。我需要從XML中提取的最重要的信息是標題,說明,圖像和mp4。

在目前的狀態下,我所做的代碼只不過是解析XML內容,但這是迄今爲止我所擁有的代碼。

sub CreateRecentMenu() 
    screen = CreateObject("roGridScreen") 
    port = CreateObject("roMessagePort") 
    xml = CreateObject("roXMLElement") 

    xml_str = GetXML("[url to the XML document]") 
    xml.Parse(xml_str) 

    ... 

    return 
end sub 

到目前爲止,我試圖從文檔中獲取我需要的信息已被證明是破壞程序。再次,非常感謝任何建議。謝謝。

編輯:我能夠確定xml_str字符串是作爲無效,因爲什麼原因我不知道。這是我用來獲取XML代碼的字符串代碼。

Function GetXML(url as String) as string 
    data = "" 
    port = CreateObject("roMessagePort") 
    link = CreateObject("roUrlTransfer") 
    link.setPort(port) 
    link.setUrl(url) 
    link.SetCertificatesFile ("common:/certs/ca-bundle.crt") 
    link.InitClientCertificates() 

    if(link.AsyncGetToString()) 
     finished = False 
     while not finished 
      msg = wait(0, port) 
      if msg = invalid 
       finished = True 
       print "failure to connect" 
       link.AsyncCancel() 
      else 
       if type(msg) = "roUrlEvent" 
        finished = True 
        if msg.GetInt() = 1 
         response = msg.GetResponseCode() 
         if response <> 200 
          print response 
         else 
          data = msg.GetString() 
         end if 
        end if 
       else 
        return invalid 
       end if 
      end if 
     end while 
    end if 
    return data 
End Function 

到目前爲止,這是我能夠使連接工作的唯一方法。再次,任何幫助表示讚賞。

回答

1

確保xml_str變量不是空的或無效的的getXML功能效果很好。

+0

看來我的字符串無效,你說得對。謝謝你的建議。問題是,爲什麼它被認爲是無效的?我必須初始化一些東西才能使其有效嗎? –

+0

嘗試調試該http請求。爲了簡化你可以使用同步調用:'return link.getToString()'而不是循環。 –

+0

好吧,我盡我所能,但此刻我真的不知道我在做什麼。我可能會轉向別的東西。謝謝你的幫助。 –