解析xml w /多个图像到html

时间:2015-05-22 17:23:50

标签: html xml parsing

我遇到了如何使用xml解析多个图像的问题。我得到的错误是它在一个img中重复所有图像数据。

$(document).find('slider > image').each(function(){ 
          var img = $(document).find("slider > image > src").text();
          var desc = $(document).find("slider > image > description").text();
          $("<img src='"+img+"' alt='"+desc+"' />").appendTo('slider');
});

例如。

<img alt="The Last of usGTA VMirror Edge" src="assets/images/fullimage1.jpgassets/images/fullimage2.jpgassets/images/fullimage3.jpg">
<img alt="The Last of usGTA VMirror Edge" src="assets/images/fullimage1.jpgassets/images/fullimage2.jpgassets/images/fullimage3.jpg">
<img alt="The Last of usGTA VMirror Edge" src="assets/images/fullimage1.jpgassets/images/fullimage2.jpgassets/images/fullimage3.jpg">

这是xml语法

<carousal>
        <slider>        
            <image>
                <src>assets/images/fullimage1.jpg</src>
                <description>The Last of us</description>
            </image>           
            <image>
                <src>assets/images/fullimage2.jpg</src>
                <description>GTA V</description>
            </image>           
            <image>
                <src>assets/images/fullimage3.jpg</src>
                <description>Mirror Edge</description>
            </image>             
        </slider>
</carousal>

这是html

<slider></slider>

0 个答案:

没有答案