简体   繁体   English

将数据加载到静态html表单页面或XML中并使用javascript

[英]Loading data into static html form page or XML and using javascript

I have a text data (CSV) file that needs to be converted into a static HTML page for user viewing. 我有一个文本数据(CSV)文件,需要将其转换为静态HTML页面以供用户查看。 In the HTML page, the user needs to be able to filter the data into views. 在HTML页面中,用户需要能够将数据过滤到视图中。 Each HTML file will be archived. 每个HTML文件都会被存档。

I plan to use JavaScript for the user filtering functions. 我计划将JavaScript用于用户过滤功能。 I plan to use a Perl script to convert the CSV file into an HTML file and include a form on the top of it for the user filter options. 我计划使用Perl脚本将CSV文件转换为HTML文件,并在其顶部包含一个用于用户过滤器选项的表单。 The HTML file will reference the JavaScript file. HTML文件将引用JavaScript文件。

My questions are: 我的问题是:

  1. I'm considering converting the data into an XML instead. 我正在考虑将数据转换为XML。 Is this better practice? 这是更好的做法吗?
  2. If so, is it possible to have web forms in XML and run javascript functions? 如果是这样,是否可以使用XML形式的Web表单并运行javascript函数?
  3. I have a CSS for the HTML file. 我有一个HTML文件的CSS。 Do I have to use XSLT for XML? 我必须对XML使用XSLT吗?
  4. Is there a way of combining XML and HTML into single file? 有没有一种将XML和HTML组合成单个文件的方法? Any benefit in this? 有什么好处吗?

You can use XML as SOURCE instead of CSV, since XML defines cleaner handling of data (commas, semicolons, ' and " in the values). 您可以将XML用作SOURCE而不是CSV,因为XML定义了更干净的数据处理(值中的逗号,分号,“和”)。

If the content is static, and you will store it, then I suggest you use a format that is most close to the end result. 如果内容是静态的,并且您将存储它,那么我建议您使用最接近最终结果的格式。 That would be HTML+JS+CSS files. 那将是HTML + JS + CSS文件。 (JS and CSS help you keep some repetitive info out of the HTML). (JS和CSS可帮助您将一些重复的信息排除在HTML之外)。

Now a little background. 现在有一点背景。 XML is not viewable by default, you should use it with an XSLT file. XML在默认情况下是不可见的,您应该将其与XSLT文件一起使用。 What happens is that the browser "opens" the XML by transforming it with the XSLT into HTML. 发生的情况是浏览器通过使用XSLT将XML转换为HTML来“打开” XML。 In this case you need the extra XSLT file, and a client capable of running it (most browsers are quite good at that nowadays). 在这种情况下,您需要额外的XSLT文件,以及一个能够运行该文件的客户端(如今,大多数浏览器都非常出色)。 But you would only use this solution for three reasons. 但是出于以下三个原因,您只会使用此解决方案。 1) If you have so many XML files (already at hand) that you do not want to process them with XSLT and save the resulting HTML instead of them, and leave this (wastly repetitive) computation burden to the clients. 1)如果您有太多的XML文件(手头已经准备好),不想使用XSLT处理它们,而是保存结果HTML而不是保存它们,而将这种(大量重复的)计算负担留给客户端。 2) You have other uses for the XML files. 2)XML文件还有其他用途。 3) The generated HTML is so much bigger than the source XML that it poses storage problems (although CSS and JS files should be enough to avoid that). 3)生成的HTML比源XML大得多,以至于造成存储问题(尽管CSS和JS文件应足以避免这种情况)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM