Skip to Content
Technical Articles
Author's profile photo Lawanya Sunkara

Usage Of Client Side XML Model In SAPUI5

Hello Everyone!!!

From the past few days, I have been researching on Client side models. During my analysis, I came to know some of the differences between JSON & XML models binding in SAP UI5 which are the most common preferred formats for data interchange on web.



Javascript Object Notation.  Extensible Markup Language. 
Store information.  Store information. 
No display capabilities.  Capability to display data because it is a markup language. 
Supports only text and number data type.  support various data types such as number, text, images, charts, graphs. It also provides options for transferring the structure or format of the data with actual data. 
It does not provide any support for namespaces.  It supports namespaces. 
It is less secured.  It is more secure than JSON. 
It doesn’t support comments.  It supports comments. 
JSON types: string, number, array, Boolean.  All XML data should be string. 
JSON syntax has specific semantics built in stuff between {} is an object, stuff between []is an array, etc.  Particular element names don’t mean anything until a particular processing application processes them in a particular way. 

Representation of JSON & XML:

Usage of XML model:

SAP UI5 follows MVC pattern and binds data to the controls using client side models I.e., JSON & XML. We will look more into XML model usage and its binding syntax to bind the XML Views.

The XML model allows to bind controls to XML data. It is a client-side model intended for small datasets, which are completely available on the client. It supports two-way binding.

To instantiate the model, use the following code:

var oModel = new sap.ui.model.xml.XMLModel(); 

XML model can be loaded with XML data format or through web service call by HTTP requests. XML model will parse the provided XML format internally and binds its child nodes to the view. Below, it describes sample XML format exchanged over the server.

Types of Data Samples:


<?xml version="1.0" encoding="UTF-8"?>
		<Description>Notebook Basic 15</Description>
		<Description>Notebook Basic 18</Description>
		<Description>Notebook Basic 20</Description>
		<Description>Notebook Basic 25</Description>
		<Description>Notebook Basic 45</Description>


<?xml version="1.0" encoding="UTF-8"?>
		<OrderId id="4001" itemNo="1" Desc="Notebook Basic 15" qty="10" delivery="30-5-2020" shipping="NewYork">4001</OrderId>
		<OrderId id="4002" itemNo="2" Desc="Notebook Basic 18" qty="20" delivery="27-5-2020" shipping="London">4002</OrderId>
		<OrderId id="4003" itemNo="3" Desc="Notebook Basic 20" qty="40" delivery="23-5-2020" shipping="UK">4003</OrderId>
		<OrderId id="4004" itemNo="4" Desc="Notebook Basic 25" qty="20" delivery="20-5-2020" shipping="Russia">4004</OrderId>
		<OrderId id="4005" itemNo="5" Desc="Notebook Basic 45" qty="20" delivery="19-5-2020" shipping="France">4005</OrderId>

Binding Information:

XML model can be loaded with loadData() or setXML()


var oModel = new sap.ui.model.xml.XMLModel();


var oModel = new sap.ui.model.xml.XMLModel();  
oModel.setXML(“<?xml version=”1.0” encoding=”UTF-8”?><Sales><xml>data</xml></Sales>”); 

Binding Syntax for sample XML Document:

Assuming sample data(1) provided above, We have <SalesOrder> as the root element to the sample XML and we have the root path items for the table as {/Sales} since for XML model root must not be included in the path.

Binding Path Syntax for XML Model:


Similar to JSON model we would bind attributes with the binding path but for XML attributes, Special selector using the “@” character exists.

Assuming the Sampledata(2) provided above, In order to bind the attributes of XML data, We use root node “OrderId” followed by attribute as “OrderId/@id”.

Binding path syntax for the context text of an element:


“text()” can be used to reference the context text of an element for the child nodes.

Binding Context for XML model:

To get the binding context onItemPress for ColumnListItem we use below syntax:




Below is the output for the sample XML data listed above:


These are the brief introduction to client side XML model. I hope you will understand general syntax variations when compare to JSON. In the next blog, I am going to research more on OData V2 Models.

Thanks for your valuable time.


Good Day!!!

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Sebastiano Marchesini
      Sebastiano Marchesini

      Hi @Lawanya,
      thanks for the blog, I never hear about this.
      For you personally when do you prefer to use Json and when XML ?
      I saw all the difference but I don't catch when use the XML one in my project.

      Author's profile photo Daniil Pereverzev
      Daniil Pereverzev

      Щас бы секурность моделей сравнивать

      Author's profile photo Mohamed EL HANDOUS
      Mohamed EL HANDOUS

      Thanks a lot Lawanya Sunkara ! This is very educational indeed.

      However, I was having an XML model and I couldn't use the getProperty function. Can you please enlighten us on how to use it in an XML context, or if there is another function to use in order to retrieve specific data from the XML?

      Thanks again!