Skip to Content
0

How to display XML Model data which Contains multiple child records in sap.ui.table.Table?

Aug 29, 2017 at 05:25 AM

39

avatar image
Former Member

Hi UI5 Experts,

I am trying to display XML data in a table in UI5. Here i got an issue, that is, xml file has multiple child nodes. I am able to display one child node data but not all child nodes.

Can any one suggest me how to get all the child nodes into my table.

Example file:

<?xml version="1.0"?>

<Employee>

<Name>Alwin</Name>

<Country>SG</Country>

<Address>
<Block>641</Block>

<Street>Jurong East 61</Street>

<Pin>640641</Pin>

</Address>

<Address>

<Block>530</Block>

<Street>Jurong West 61</Street>

<Pin>640530</Pin>

</Address>

</Employee>

From the above XML model, i can be able to read first <Address> node data and can be able to bind but i am not able to get second <Address> node using sap.ui.table.Table.

any suggestions?....

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Jun Wu Aug 29, 2017 at 11:44 AM
0

your code

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Jun Wu,

Please take a look at my code.
@View Controller

sap.ui.define([
	"sap/ui/core/mvc/Controller"
], function(Controller) {
	"use strict";


	return Controller.extend("CBCRDummy.controller.View1", {
     onInit: function(){
     	var oModel = new sap.ui.model.xml.XMLModel();
     	oModel.loadData("localService/metadata.xml");
     	var otab = sap.ui.getCore().byId("tab");
     	otab.setModel(oModel);
     	otab.bindRows("/");
     }
	});
});

@View 

sap.ui.jsview("CBCRDummy.view.View1", {


	/** Specifies the Controller belonging to this View. 
	 * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
	 * @memberOf controller.View1
	 */
	getControllerName: function() {
		return "CBCRDummy.controller.View1";
	},


	/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed. 
	 * Since the Controller is given to this method, its event handlers can be attached right away.
	 * @memberOf controller.View1
	 */
	createContent: function(oController) {
		var oPage = new sap.m.Page({
			title: "{i18n>title}",
			content: [
				new sap.ui.table.Table("tab",{
					enableColumnFreeze:true,
					columns:[new sap.ui.table.Column({
				    width:"5em",
					label:	new sap.ui.commons.Label({text:"User Name"}),
					template:new sap.ui.commons.TextField().bindProperty("value","Name")
					}),
					new sap.ui.table.Column({
					width:"8em",
					label:	new sap.ui.commons.Label({text:"Country"}),
					template:new sap.ui.commons.TextField().bindProperty("value","Country")
					}),
					new sap.ui.table.Column({
					width:"10em",		
					label:	new sap.ui.commons.Label({text:"Block"}),
					template:new sap.ui.commons.TextField().bindProperty("value","Address/Block")
					}),
					new sap.ui.table.Column({
					width:"10em",	
					label:	new sap.ui.commons.Label({text:"Street"}),
					template:new sap.ui.commons.TextField().bindProperty("value","Address/Street")
					}),
					new sap.ui.table.Column({
					width:"8em",	
					label:	new sap.ui.commons.Label({text:"Pin"}),
					template:new sap.ui.commons.TextField().bindProperty("value","Address/Pin")
					})
					]
				})
				]
		});


		var app = new sap.m.App("myApp", {
			initialPage: "oPage"
		});
		app.addPage(oPage);
		return app;
	}


});
0
Jun Wu Aug 30, 2017 at 01:01 PM
0

table can only display one node, which have the same structure.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Jun Wu,

Thanks for the reply, so instead of using table can i use List?

Will that work?

0