0

I have stored xml data in an array which i want to set it to xml Model. I have tried using oXmlModel.setXML(oPropStored); where oXmlModel is the name of xml Model and oPropStored is the name of array in which the xml data is stored. But it is not working.

here is the xml file

<book id="bk101">
    <bookno>1</bookno>
    <author>sum</author>
    <title> Be Careful what you wish for</title>
    <desc>an sumoz book</desc>
    <price>280</price>
    <publish>11-11-2014</publish>
    <sold>100000</sold>
</book>
<book id="bk102">
    <bookno>2</bookno>
    <author>San Bod</author>
    <title> Rich Dad poor Dad</title>
    <desc>an Sanjana Boddu book</desc>
    <price>1880</price>
    <publish>08-10-2004</publish>
    <sold>240000</sold>
</book>

This is the controller code:

var x=oData.getElementsByTagName("book");
    console.log("length of x:",x.length);

    for(var j=0; j<x.length;j++)
    {
        oProp[j]= oData.getElementsByTagName("book")[j];
        obookno[j]=oData.getElementsByTagName("bookno")[j].textContent;
    }

    for(var i=0;i<indexArray.length;i++)
        {
            for( var j=0;j<x.length;j++)
            {
                if(indexArray[i]===obookno[j])
                {
                    oPropStored[i]=oProp[j];
                    console.log("property is :",oPropStored[i]);
                }
            }

        }

    var oXmlModel= new sap.ui.model.xml.XMLModel();
    oXmlModel.setXML(oPropStored);
    console.log(oXmlModel);

in the above code iam taking the selected index and stored them in indexarray and then comparing the index with the bookno array in which i have stored bookno from the xml file. and what has been matched is stored in oPropStored array and the oProp holds all the xml data. This oPropStored array is to be set to oXmlModel.

Thankx for

1 Answer 1

0

Try the setData method:

var oXmlModel= new sap.ui.model.xml.XMLModel();
oXmlModel.setData(oPropStored);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.