如何将XML数据插入HTML?

时间:2019-04-06 23:20:58

标签: javascript html xml

我正在尝试从VLC上的XML状态文件中获取数据,我想将其放入HTML中,以便在状态XML更新或请求状态XML时出现新信息。

这是status.xml运行时的XML信息。 OMFG-由于声誉原因,我无法发布图片。而是这些图片的链接。

enter image description here

我想要这些字段在这里:

enter image description here

我对任何直接编程都不了解。我已经运行了一些批处理文件,并且使用了一些python脚本,并且进行了编辑,但没有别的。我在某种程度上了解标签,功能和列表。

我尝试使用“ scr”以“ type:text / xml”出我的xml文件。-失败 我尝试使用viewer.js文件并对其进行编辑以指向所需的xml文件。 -失败了。 -我不明白如何将xml数据放入可在html内引用的javascript文件中。

这是html文件;我从twitch的钻机开发人员套件中获得了它的第一个扩展。

<!DOCTYPE html>
<html>
    <head>
        <title>Viewer Page</title>
    </head>
    <body style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
        <div id="app" class="full-height"></div>
        <script src="https://extension-files.twitch.tv/helper/v1/twitch-ext.min.js"></script>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"
        integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
        crossorigin="anonymous"></script>
        <script src="viewer.js" type="text/javascript"></script>
        <script type="http://192.168.0.22:8080/requests/status.xml">{
        </script>
        <h2>Video Game Music playlist</h2>
        <p>Here is what is playing currently</p>
        <div>
            <input type="button"  value="Refresh what's playing" />
        </div>
        <div id="list">
        </div>
    </body>
</html>

这是xml文件:     ]]?>

<?vlc

--package.loaded.httprequests = nil --uncomment to debug changes
require "httprequests"

httprequests.processcommands()

local statusTable=httprequests.getstatus(false)

print('<root>\n')


local item = vlc.input.item()

--data in the information section is presented in a non-standard way to             keep compatibility.

?>
<information>
    <category name="meta">
    <?vlc
      if item then
        local metas = item:metas()
        for k,v in pairs(metas) do
          local metadataContent = vlc.strings.convert_xml_special_chars(     httprequests.xmlString(v) )
          print("<info     name='"..httprequests.xmlString(k).."'>"..metadataContent.."</info>")
        end
      end
    ?>
    </category>
  </information>
</root>

我除了可以找到一种方法来将xml中的数据放入html或任何html文件中。实际上,如果有人可以告诉我如何将我拥有的xml数据放入html文件中,可以对其进行更新,那将是惊人的。

我一直在尝试在youtube上查找最简单的方法,但是我不断浏览视频,这些视频展示了如何将图像从xml转换为html;我不需要的。

事实上,说实话;我想我首先需要将xml文件放在Javascript中?我认为html必须是内联html,因此必须从.JS文件引用xml数据?

我不知道我在说什么。大声笑

1 个答案:

答案 0 :(得分:0)

混合XML和HTML非常棘手。这里有一个W3C任务组报告,该报告分析了哪些有效,哪些无效:

https://www.w3.org/2010/html-xml/snapshot/report.html

以及Norm Walsh的概述演讲:

https://norman.walsh.name/2011/03/26/HTML-XML-Prague

这项工作是几年前完成的,但我认为情况没有根本改变。