See the function below for example:
- Code: Select all
function xmlTest()
{
var _xml = <xml/>
_xml.customer = <customer/>
_xml.customer.name = company_name;
var _rec, _rec_detail, _order, _orderDetail;
for (var i = 1; i <= companies_to_orders.getSize(); i++) {
_rec = companies_to_orders.getRecord(i);
_order = <order/>
_order.shipcity = _rec.shipcity;
_order.orderid = _rec.order_id;
_order.orderdate = _rec.order_date;
for (var j = 1; j <= _rec.orders_to_order_items.getSize(); j++) {
_rec_detail = _rec.orders_to_order_items.getRecord(j);
_order.orderDetail.product_id = _rec_detail.productid
_order.orderDetail.quantity = _rec_detail.quantity
}
_xml.customer.appendChild(_order);
}
application.output(_xml)
//application.output(_xml.customer.order[0].orderDetail[0].quantity)
}
This function you can add to a form based on the Companies table in the Servoy_Sample_CRM and when run it will generate the following output:
- Code: Select all
<xml>
<customer>
<name>ABC Company</name>
<order>
<shipcity>null</shipcity>
<orderid>7</orderid>
<orderdate>Wed Feb 08 09:00:00 CET 2006</orderdate>
<orderDetail>
<product_id>undefined</product_id>
<quantity>3</quantity>
</orderDetail>
</order>
<order>
<shipcity>null</shipcity>
<orderid>11</orderid>
<orderdate>Fri Mar 03 09:00:00 CET 2006</orderdate>
<orderDetail>
<product_id>undefined</product_id>
<quantity>2</quantity>
</orderDetail>
</order>
<order>
<shipcity>null</shipcity>
<orderid>13</orderid>
<orderdate>Tue Feb 21 09:00:00 CET 2006</orderdate>
<orderDetail>
<product_id>undefined</product_id>
<quantity>8</quantity>
</orderDetail>
</order>
</customer>
</xml>
If you want to learn more about the XMl support in JavaScript, check out the following url's:
http://www.w3schools.com/e4x/e4x_howto.asp
http://rephrase.net/days/07/06/e4x
http://www.ibm.com/developerworks/xml/library/x-javascript4x.html?S_TACT=105AGX54&S_CMP=B0717&ca=dnw-928
Also have a look at the XML and XMLList nodes under JSLibs in the Servoy Solution Explorer in Developer.
Paul