var data = {
columns: [{
field: "FirstName",
title: "First Name"
}, {
field: "LastName",
title: "Last Name"
}],
dataSource: {
data: [{
FirstName: "Joe",
LastName: "Smith"
}, {
FirstName: "Jane",
LastName: "Smith"
}]
}
}
var sourceStr =
'<data type="table"><table_field Title="Имя"><tableRow Value="Вася"/><tableRow Value="Коля"/><tableRow Value="Петя"/></table_field><table_field Title="Фамилия"><tableRow Value="Иванов"/> <tableRow Value="Петров"/><tableRow Value="Антонова"/></table_field><table_field Title="Телефон"><tableRow Value="02"/><tableRow Value="01"/><tableRow Value="03"/></table_field>';
var resultObj = {columns : new Array(), dataSource : {data : new Array()}}
var regExpCollumnWrapper = new RegExp('<table_field Title="(.*?)"(.*?)</table_field>', 'gim');
var regExpRowWrapper = new RegExp('tableRow Value="(.*?)"', 'gim');
var collumnIndex = 0;
while(currentCollumn = regExpCollumnWrapper.exec(sourceStr))
{
resultObj.columns.push({field: currentCollumn[1]});
var rowIndex = 0;
while(currentRow = regExpRowWrapper.exec(currentCollumn[2]))
{
if(collumnIndex == 0)
{
resultObj.dataSource.data.push({});
}
resultObj.dataSource.data[rowIndex][currentCollumn[1]] = currentRow[1];
rowIndex++;
}
collumnIndex++;
}
console.table(resultObj);