XML解析意外行为LiScroll

时间:2013-09-02 12:38:14

标签: javascript jquery html css xml

我从一些jquery xml解析中得到了意想不到的行为。

我从服务器获取具有以下代码的文件

$.ajax({
    type: "GET",
    url: "//path/test.xml",
    dataType: "xml",
    success: function(xml) { //do stuff }

它没有按预期执行,如果我直接从文件中获取数据并将其硬编码到我的JS中它按预期工作。文件中的数据采用

格式
<?xml version="1.0" encoding="utf-8"?><ProductRates xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Total="64" Region="UK"><ProductRate><Description>UAE - Dirham</Description><ProductType>CUR</ProductType><CurrencyCode>AED</CurrencyCode><Rate>5.4427</Rate></ProductRate><ProductRate><Description>Australia - Australia Dollar</Description><ProductType>CUR</ProductType><CurrencyCode>AUD</CurrencyCode><Rate>1.6726</Rate></ProductRate></ProductRates>

因此,一旦我获得了xml,就会像这样进行处理

var $xml = $(xml);
var $list = $('#ticker'); 
$prodtype = $xml.find("ProductType");
$prodtype.each(function() {
var self = $(this);
if( self.text() == "CUR") { 
    var 
        $CurrencyCode = self.next('CurrencyCode')
        $Rate         = $CurrencyCode.next('Rate')          
    ; 
    $( "#ticker" ).append("<li><a>" +$CurrencyCode.text()+" = "+ $Rate.text()+ " </a></li>");

}

});

我正在使用来自http://www.gcmingati.net/wordpress/wp-content/lab/jquery/newsticker/jq-liscroll/scrollanimate.html的liScroll js / css,它确实有效但列表项在垂直方向上堆叠而不是水平堆叠在自动收报器容器中。可能是如何解析xml文件?

页面运行时关联的css,希望有用......

element.style {
background-image: url(test.img);
}
Matched CSS Rules
currency_ticker_test.shtmlmedia="all"
#content-header {
background-repeat: no-repeat;
background-position: center top;
}
currency_ticker_test.shtmlmedia="all"
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
border: 0;
outline: 0;
font-size: 100%;
vertical-align: baseline;
background: transparent;
}
user agent stylesheetdiv {
display: block;
}
Inherited from div#shell
currency_ticker_test.shtmlmedia="all"
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
font-size: 100%;
}
Inherited from body
currency_ticker_test.shtmlmedia="all"
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
color: #2f2f2f;
}
currency_ticker_test.shtmlmedia="all"
body {
line-height: 1;
}
currency_ticker_test.shtmlmedia="all"
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
font-size: 100%;
}
Inherited from html
currency_ticker_test.shtml media="all"
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
font-size: 100%;
}

1 个答案:

答案 0 :(得分:1)

您的xml结构无效。你有两个开放的ProductRates元素。

<ProductRates xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Total="64" Region="UK">
<ProductRates>

检查有效xml的最佳方法是将输出保存到xml文件并在浏览器中打开。