如何将 XML 数据插入到 HTML 中? [英] How can I insert XML data into HTML?

查看:42
本文介绍了如何将 XML 数据插入到 HTML 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是 status.xml 运行时的 XML 信息.OMFG - 由于声誉原因,我还不能发布图片.这里是图片的链接.

我想要这些字段在这里:

我对任何直接编程一无所知.我已经运行了一些批处理文件,我有一些我使用的 python 脚本,我编辑但没有别的.我在一定程度上了解标签、函数和列表.

我曾尝试使用scr"通过type:text/xml"来导出我的 xml 文件. - 失败我曾尝试使用 viewer.js 文件并对其进行编辑以指向我想要的 xml 文件.- 失败的.- 我不明白如何将 xml 数据放入一个 javascript 文件中,然后可以在 html 中引用.

这是html文件;我从 twitch 的 rig-developer kit 那里得到它作为第一个扩展.

<头><title>查看者页面</title><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"完整性="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="crossorigin="匿名"></script><script src="viewer.js" type="text/javascript"></script><脚本类型="http://192.168.0.22:8080/requests/status.xml">{<h2>视频游戏音乐播放列表</h2><p>这是当前正在播放的内容</p><div><input type="button" value="刷新正在播放的内容"/>

<div id="列表">

</html>

这里是xml文件:]]?>

\n')本地项目 = vlc.input.item()--信息部分中的数据以非标准方式呈现以保持兼容性.?><信息><类别名称=元"><?vlc如果项目然后本地元 = 项目:元()对于 k,v 成对 (metas) 做本地 metadataContent = vlc.strings.convert_xml_special_chars( httprequests.xmlString(v) )print("<info name='"..httprequests.xmlString(k).."'>"..metadataContent.."</info>")结尾结尾?></类别></信息></root>

除了我可以找到一种方法将 xml 中的数据放入 html 或任何 html 文件中.事实上,如果有人能告诉我如何将我拥有的 xml 数据放入一个可以更新的 html 文件中,那将是惊人的.

我一直在尝试在 youtube 上查找最简单的方法来执行此操作,但我一直在观看展示如何将图像从 xml 获取到 html 的视频;我不需要.

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

我不知道我在说什么.哈哈

解决方案

混合 XML 和 HTML 很棘手.这里有一份 W3C 任务组报告,其中分析了哪些有效,哪些无效:

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

以及 Norm Walsh 的概述性演讲:

https://norman.walsh.name/2011/03/26/HTML-XML-布拉格

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

I am trying to grab data from an XML status file that is on VLC and I want to put it into an HTML so that when the status XML updates or is requested, the new information appears in the HTML.

Here is the XML information from the status.xml when its ran. OMFG - I can't post images due to reputation yet. Here are the links to the images instead.

I want those fields in here:

I don't have any knowledge of any direct programming. I have run some batch files and I have some python scripts I use and I edit but nothing else. I understand tags, functions and lists to a degree.

I have tried using "scr" to path out my xml file with "type:text/xml. - failed I have tried using a viewer.js file and editing that to point to the xml file I wanted. - failed. - I didn't understand how to put the xml data into a javascript file that can then be referenced inside the html.

This is the html file; I got it from the rig-developer kit from twitch as there first extension.

<!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>

Here is the xml file: ]]?>

<?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>

I excepted that I can find a way to put the data from the xml into the html or any html file. Infact if someone can just show me how to put the xml data I have into an html file where it can be updated that would be amazing.

I have been trying to look up the easiest way to do this on youtube but I keep coming accross videos that show how to get images from xml to html; which I don't need.

Infact, to be honest; I think I need the xml file to be in Javascript first or something? I think the html has to be an inline html and thus the xml data has to be referenced from a .JS file?

I don't know what I am talking about. lol

解决方案

Mixing XML and HTML is tricky. There's a W3C task group report here which analyzes what works and what doesn't:

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

and an overview talk by Norm Walsh:

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

This work was done some years ago but I don't think the situation has fundamentally changed.

这篇关于如何将 XML 数据插入到 HTML 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆