简体   繁体   English

使用上载以HTML显示XML数据

[英]Display XML data in HTML using Upload

Im working on a small project that allows a person to upload XML data to a HTML website and then display that data on the HTML page based on the value of a slider. 我正在做一个小型项目,该项目允许人们将XML数据上传到HTML网站,然后根据滑块的值在HTML页面上显示该数据。 This is an example of my XML data: 这是我的XML数据的示例:

<?xml version = "1.0" encoding = "UTF-8"?>
<CarList>
    <Car id="1">
        <model>Ferrari</model>
        <image>images/ferrari.jpg</image>
        <colour>red</colour>
    </Car>
    <Car id="2">
        <model>Ford GT</model>
        <image>images/FordGT.jpg</image>
        <colour>blue</colour>
    </Car>
    <Car id="3">
        <model>BMW</model>
        <image>images/bmw.jpg</image>
        <colour>grey</colour>
    </Car>
</CarList>

On my HTML page i have a simple upload button. 在我的HTML页面上,我有一个简单的上传按钮。 When the user uploads an XML file then some images should appear based on the colour sliders. 当用户上载XML文件时,应基于颜色滑块显示一些图像。

<div class="uploadContent">
     Upload Content
     <input type="file" class="upload-content" accept="text/xml" id="upload">
</div>

This is where the images should be displayed along with the model of the car. 这是图像和汽车型号一起显示的地方。

<div class = "car">
     <img class = "carImage" id = "carImage" src="images/NoContent.png">
     <p class = "carName" id = "car1Name"> No Content </p>
</div>

The sliders will determine what car is show, If for example the user wants to only see red cars then the slider will be move to the left and the above images will only show red cars. 滑块将确定显示的是什么汽车。例如,如果用户只想看到红色的汽车,则滑块将向左移动,而上面的图像将仅显示红色的汽车。

<div>
    <!--Red/Blue-->
    <p>Red</p>
        <input type="range", min="1", max="2", step="0.5"/>
    <p>Blue</p>
</div>

My gut feeling says i need to use Javascript for this but i have no idea where to start. 我的直觉说我需要为此使用Javascript,但是我不知道从哪里开始。

Any help will be appreciated. 任何帮助将不胜感激。

if you want to create an items list from the XML file you have to 如果要从XML文件创建项目列表,则必须

  1. Parse XML file and return an array. 解析XML文件并返回一个数组。 You can see XML to Array 您可以看到XML到数组

  2. After the parse, you can .map() the array. 解析之后,您可以.map()数组。 See Array.prototype.map() 参见Array.prototype.map()

  3. Least, you need to set image src attribute imageHTML.src = path; 至少,您需要设置图像src属性imageHTML.src = path;

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

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