簡體   English   中英

在Brightscript中使用XML的困難

[英]difficulties using XML in Brightscript

我既沒有使用Brightscript也沒有使用XML內容的經驗,但是我目前在開發roku應用程序方面都面臨挑戰。 目前,我需要弄清楚如何對在線文檔中的一些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

到目前為止,這是我能夠使連接正常工作的唯一方法。 再次感謝您的幫助。

確保xml_str變量不為空或無效,並且GetXML函數運行良好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM