Java API
XMLMapper mapper = new XMLMapper();
mapper.addMapping(new XMLMapping("orders", “customer_orders”);
mapper.addMapping(new XMLMapping("orders/order", “customer_orders/customer_order”, “customerName = 'Henry'”);
mapper.addMapping(new XMLMapping("orders/order/orderDate", “customer_orders/customer_order/@orderDate”);
mapper.addMapping(new XMLMapping("orders/order/orderRef", “customer_orders/customer_order/@orderRef”);
mapper.addMapping(new XMLMapping("orders/order/deliveryAddress/postCode", “customer_orders/customer_order/@postCode”);
mapper.addMapping(new XMLMapping("orders/order/status", “customer_orders/customer_order/@status”);
mapper.addMapping(new XMLDefault(“customer_orders/customer_order/@statusCode”, “status = ‘Dispatched’”, “DSP”);
mapper.addMapping(new XMLDefault(“customer_orders/customer_order/@statusCode”, “status = ‘Pending’”, “PND”);
mapper.addMapping(new XMLMapping("orders/order/item/price", “customer_orders/customer_order/@totalValue”, null, XSLTFunction.SUM);
String mappedXML = XMLUtil.toXMLString(mapper.apply(new File("Orders.xml")));
System.out.println(“Mapped XML=”+mappedXML);
|