简体   繁体   English

Javascript中的XML解析。 需要帮助

[英]XML Parsing in Javascript. Help Needed

Firstly I have created a javascript which positions, and animates certain parts of a site 首先,我创建了一个JavaScript,该JavaScript可以对网站的某些部分进行定位和动画处理

example: 例:

<ul>
<li transition="fade" amount="5" thumb="images/thumb1.jpg>
<div class="item rotate"
      width = "18"
      height= "550"
      speed="600"
      start="1100"
      easing="easeOutExpo"><img src="images/cheese.png" alt="Cheese">
<div>

<div class="caption black sfb stb"
      width = "950"
      height= "600"
      speed="600"
      start="1100"
      easing="easeOutExpo">10.99
<div>
</li>

<li transition="cut" amount="15" speed="300" delay="9400" thumb="images/thumb2.jpg>
<div class="item rotate"
      width = "18"
      height= "550"
      speed="600"
      start="1100"
      easing="easeOutExpo"><img src="images/pork.png" alt="Pork">
<div>

<div class="caption white lfl stl"
      width = "950"
      height= "600"
      speed="600"
      start="1100"
      easing="easeOutExpo">15.99
<div>
</li>
</ul>

Now instead of having to place this in the html, I am now wanting to place this in an XML since later I will be making a webservice. 现在,不必将其放置在html中,现在我想将其放置在XML中,因为稍后我将制作一个Web服务。

But for now, I need to get my javascript to work so it will read all these from an xml. 但就目前而言,我需要使我的JavaScript正常工作,以便它将从xml中读取所有这些内容。

What I was thinking of (maybe I am on the wrong path here) is the following for the xml 我在想的(也许我在错误的路径上)是针对xml的以下内容

<spot>
 <effect type="fade"></effect>
 <amount>5</amount>
 <thumb>thumb1.jpg</thumb>
   <item ="item rotate">
    <width>18</width>
    <height>550</height>
    <speed>600</speed>
    <start>1100</start>
    <easing>easeOutExpot</easing>
    <img alt="Cheese">images/cheese.png></image>
   </item>
  </spot>

Now I have no clue as in how to sort this out within a javascript. 现在,我不知道如何在JavaScript中进行分类。 Could someone please give me some hints tips etc.? 有人可以给我一些提示技巧吗?

You can find an example of how to parse XML using jQuery in this StackOverflow answer . 您可以在此StackOverflow答案中找到有关如何使用jQuery解析XML的示例。 Just look for the tags you want by using css selectors, and extract the data you need. 只需使用CSS选择器查找所需的标签,然后提取所需的数据。 You can build the necessary HTML using jQuery or the javascript DOM methods( document.createElement# etc.) 您可以使用jQuery或javascript DOM方法(document.createElement#等)构建必要的HTML。

If you don't want to use jQuery, this blog entry explains how to create a XML-DOM object from the XML string. 如果您不想使用jQuery,那么此博客条目将说明如何从XML字符串创建XML-DOM对象。 You can then use the browsers DOM methods to get the data you want. 然后,您可以使用浏览器的DOM方法获取所需的数据。

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

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