简体   繁体   中英

How to set array in xml Model in sap ui5

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

Try the setData method:

var oXmlModel= new sap.ui.model.xml.XMLModel();
oXmlModel.setData(oPropStored);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM