how to export an xml file
Posted:
Mon Aug 02, 2010 9:49 pm
by nromeou
Hi,
i want to make an export into an xml file of some fields in a form, i tryied using the function printXML() but it doesnt do what i want that exports the entire form and i want to select only some of the record's fields. How can i do that? is there a servoy functionality for this or should i use a plugin?
Thanks in advance.
Re: how to export an xml file
Posted:
Tue Aug 03, 2010 10:24 am
by Roberto Blasco
Hi
nromeou If you don't want to use a plugin, do it directly. Xml is just a plain text tag formatted. Loop throw the foundset fulling a variable with the xml nodes and finally write the file with the variable content.
- Code: Select all
function doXml()
{
var xml = "<?xml version=\"1.0\" encoding=\"iso-18859-1\"?>" + "\n";
xml += "<mi_xml>" + "\n";
var num_reg = databaseManager.getFoundSetCount(foundset);
for (var x=0; x<num_reg;x++){
xml += "<articulo>" + "\n";
xml += "<id>" + id_aplicacion + "</id>" + "\n";
xml += "<nombre>" + nombre + "</nombre>" + "\n";
xml += "</articulo>" + "\n";
}
xml += "</mi_xml>";
}
Best regards. Roberto.
Re: how to export an xml file
Posted:
Tue Aug 03, 2010 11:15 am
by michel
Why not use JSLib->XML? Then you always have nicely formed xml and you don't have to worry about quotes etc.
For instance something like:
- Code: Select all
function doXml(fs)
{
var xml = <my_xml/>
var table_name = databaseManager.getDataSourceTableName(fs.getDataSource())
var table = <my_table name={table_name}/>
for(var i=1; i<=databaseManager.getFoundSetCount(fs); i++) {
fs.setSelectedIndex(i)
var record = <my_record index={i}/>
var fields = databaseManager.getTable(fs).getColumnNames()
for (var j=0; j<fields.length; j++) {
var name = fields[j]
var value = fs[name]
var field = <my_field name={name}>{value}</my_field>
record.appendChild(field)
}
table.appendChild(record)
}
xml.appendChild(table)
return xml
}
Re: how to export an xml file
Posted:
Tue Aug 03, 2010 11:25 pm
by nromeou
thanks guys. problem solved with roberto´s code and adding this line of code after the for sentence
- Code: Select all
for (var x=1; x<=num_reg;x++){
foundset.setSelectedIndexes(x)
xml += "<articulo>" + "\n";