0

我在使用 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

到目前为止,这是我能够使连接正常工作的唯一方法。再次感谢任何帮助。

4

1 回答 1

1

确保xml_str变量不为空或无效,并且GetXML函数运行良好。

于 2016-06-21T15:52:44.493 回答