Answer the question
In order to leave comments, you need to log in
Parsing XML file. Why can't I see child elements?
Hello, I have a problem that I can't solve. I parse the XML file. With the help of Ajax I take the file, I start to transform it with the help of jQuery. XML file structure example:
<Row>
<Cell ss:StyleID="s158"><Data ss:Type="String">Номер товара</Data></Cell>
<Cell ss:StyleID="s160" ss:HRef="http://besttea.ru/smola-puer-shu-v-poroshke/"
x:HRefScreenTip="Объем"><Data ss:Type="String"><b>Название</b></Data></Cell>
<Cell ss:StyleID="s162"><Data ss:Type="String"><b>Объем</b></Data><Comment
ss:Author="Е.М"><ss:Data xmlns="none"><B><Font
html:Face="Tahoma" x:CharSet="204" html:Size="9" html:Color="#000000"><b>Описание</b></Font></B></ss:Data></Comment></Cell>
<Cell ss:StyleID="s158"><Data ss:Type="String">Акция!!!</Data><NamedCell
ss:Name="_FilterDatabase"/></Cell>
<Cell ss:StyleID="s163"><Data ss:Type="Number">400</Data></Cell>
<Cell ss:StyleID="s164"/>
<Cell ss:StyleID="s164" ss:Formula="=RC[-1]*RC[-2]"><Data ss:Type="Number">0</Data></Cell>
</Row>
jQuery(document).ready(function() {
var array = [];
var arrayHTML = [];
jQuery(".transform").click(
function() {
jQuery.ajax({
type: "GET",
url: "путь к файлу",
dataType: "xml",
error: function() {
console.log("Не вышло");
},
success: function(temp) {
var got = jQuery(temp).find("Row");
var maxL = 0;
for (i=0; i<got.length; i++) { // Перебор строк
var got2 = jQuery(got[i]).find("Cell");
var length2 = got2.length; //кол-во ячеек Cell в каждом Row
array[i] = [];
for (j=0; j<length2; j++) { // Перебор ячеек
var got31 = jQuery(got2[j]).find("Data").textContent;
var got32 = jQuery(got2[j]).find("Comment").textContent;
if (got31 && got32) { //если есть и Data и Comment
array[i][j] = got31;
j++;
length2; // увеличиваем дилну на 1, т.к. появилась доп. ячейка за счет наличия комментария
array[i][j] = got32;
}
else {
array[i][j] = got2[j].textContent;
}
if (maxL < length2) {
maxL = length2;
}
console.log("i="+ i + " " + "j=" + j + " " + "значение =" + array[i,j]);
}
}
console.log("конец");
}
});
}
);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question