I think what I want to do is simpler than I imagine. But I can’t find the solution.
I have an XML file that I need to pass to JSON, to make a Virtual List.
I can access the root of the XML, but I don’t know how to access the nodes / elements of the XML from javascript.
I try with parseXML() but this not work with Framework7.
I found some webs with examples but didn’t work.
Look in Google but what I found didn’t work.
I don’t know if I’m getting complicated or not.
Thanks in advance.
The code I have so far is:
$$('.busqueda-boton').on('click', function () {
var datosbusqueda = app.form.convertToData('#busqueda-form');
var busqueda = datosbusqueda.medicamento;
var busquedaUpper = busqueda.toUpperCase();
app.request({
url: 'http://xxxxxxxx/get_producto.php?NOM_LARGO=%' + busquedaUpper + '%',
method: 'GET',
dataType: 'XML',
crossDomain: true,
//data: busqueda,
success: function (data, textStatus) {
// var items = data;
console.log(data);
var virtualList = app.virtualList.create({
// List Element
el: '.virtual-list-busqueda',
// Pass array with items
items: data,
emptyTemplate: 'No se encontraron resultados.',
// List item Template7 template
itemTemplate: '<li>' +
'<a href="#" class="item-link item-content">' +
'<div class="item-inner">' +
'<div class="item-title-row">' +
'<div class="item-title">' + ITEM + '</div>' +
'</div>' +
'<div class="item-subtitle">' + ITE + '</div>' +
'</div>' +
'</a>' +
'</li>',
// Item height
height: app.theme === 'ios' ? 63 : (app.theme === 'md' ? 73 : 46),
});
virtualList.clearCache();
},
error: function (xhr, textStatus, errorThrown) {
},
});
});
The structure of the XML is:
<?xml version="1.0"?>
<Consulta_productos>
<NOM_LARGO>%AMOXI 250%</NOM_LARGO>
<Detalle>
<Producto>
<NOM_LARGO>AMOXI 250 MAR SUS EXT X 105</NOM_LARGO>
<COD_ALFABETA>2xxxxxx</COD_ALFABETA>
</Producto>
<Producto>
<NOM_LARGO>AMOXI 250 MAR SUS EXT</NOM_LARGO>
<COD_ALFABETA>2xxxxxx</COD_ALFABETA>
</Producto>
</Detalle>
</Consulta_productos>