Skip to Content
0

Access Data from XML Model

Sep 09, 2017 at 01:01 PM

36

avatar image
Former Member

I have the following code using which I load the XML data. I want to access the data in my controller. However, when I try the getProperty method, it gives me null. Where am I going wrong?

XML File - https://www.w3schools.com/xml/books.xml

onInit: function () {
var oModel = new sap.ui.model.xml.XMLModel("https://www.w3schools.com/xml/books.xml");
console.log(oModel);
this.getView().setModel(oModel);
debugger;
var a = oModel.getProperty("/bookstore/book/title");
alert(a);
}

I am open to using any other method or way as well.

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

2 Answers

Akhilesh Upadhyay Sep 09, 2017 at 08:08 PM
0

i believe you will get same origin issue at first line while model initialisation,

check console (F12) if you are getting 'Access-Control-Allow-Origin' issue, you can use that url using proxy, and then try to get property n check.

Share
10 |10000 characters needed characters left characters exceeded
Sharath M G Sep 09, 2017 at 02:36 PM
0

Use a json model.

new sap.ui.model.json.JSONModel();

You need to either manually copy the content or execute the service URI to get the JSON or XML data.

By referring to an URI, it will not execute the service.

Share
10 |10000 characters needed characters left characters exceeded