Skip to Content

Access Data from XML Model

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 -

onInit: function () {
var oModel = new sap.ui.model.xml.XMLModel("");
var a = oModel.getProperty("/bookstore/book/title");

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Sep 09, 2017 at 02:36 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 09, 2017 at 08:08 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.