SAP Fiori applications leverage modern UI technologies to provide rich, dynamic user experiences. A key aspect of developing Fiori apps is managing data effectively on the client side. Two commonly used data models in SAP Fiori development are JSON models and XML models. Understanding how to work with these models is essential for building efficient and responsive Fiori applications.
In SAP Fiori, models act as data containers that bind data to the user interface (UI) elements, enabling seamless synchronization between the UI and underlying data.
JSON Model: Uses JavaScript Object Notation (JSON), a lightweight, text-based format widely used for data interchange. The JSON model is client-side only and is ideal for handling local or temporary data in the app.
XML Model: Uses Extensible Markup Language (XML), a markup language that defines a set of rules for encoding documents. The XML model can be used for data that requires XML syntax or for legacy data sources.
var oModel = new sap.ui.model.json.JSONModel();
oModel.loadData("model/data.json"); // Load JSON file
// or
oModel.setData({
employees: [
{name: "John", role: "Manager"},
{name: "Lisa", role: "Developer"}
]
});
this.getView().setModel(oModel);
// or globally
sap.ui.getCore().setModel(oModel);
<List items="{/employees}">
<StandardListItem title="{name}" description="{role}" />
</List>
var oXMLModel = new sap.ui.model.xml.XMLModel();
oXMLModel.loadData("model/data.xml");
this.getView().setModel(oXMLModel);
<Text text="{/employees/employee/0/name}" />
| Aspect | JSON Model | XML Model |
|---|---|---|
| Data Format | JSON | XML |
| Usage | Client-side, modern apps | Handling XML data or legacy systems |
| Popularity | More widely used in SAP Fiori apps | Less common but still supported |
| Ease of Manipulation | Easy with JavaScript object methods | Requires XML parsing methods |
Working with JSON and XML models is fundamental for SAP Fiori developers to create dynamic, data-driven applications. While JSON models are preferred for their simplicity and compatibility with modern web standards, XML models still play a role when dealing with XML data sources. Mastery of both models enhances the ability to handle diverse data scenarios and build responsive SAP Fiori apps.