Parse XML View from String

天涯浪子 提交于 2021-02-05 08:25:42

问题


Is it possible to parse an XML string and use it as a UI5 view?

I like to do something like this:

var sXML = `<mvc:View
  xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m"
  controllerName="controller.App"
  displayBlock="true"
>
  <App>...</App>
</mvc:View>`;

var oView = sap.ui.view({
  id: "idstart1",
  view: sXML,
  type: "XML"
});

回答1:


Sure, by defining the property viewContent with the string in sap.ui.xmlview, it's possible as the API reference states:

viewContent [...] can hold a view description as XML string or as already parsed XML Document.

As of 1.56

The factory function sap.ui.xmlview is deprecated by now. Please use sap.ui.core.mvc.XMLView.create[API] instead with the string value assigned to the definition setting.

sap.ui.getCore().attachInit(() => sap.ui.require([
  "sap/ui/core/mvc/XMLView",
], XMLView => XMLView.create({
  definition:`<mvc:View
    xmlns:mvc="sap.ui.core.mvc"
    xmlns="sap.m"
    height="100%"
  >
    <App>
      <Page title="My String View">
        <Title text="Hello, world!"/>
      </Page>
    </App>
  </mvc:View>`,
}).then(view => view.placeAt("content"))));
<script>
  window["sap-ui-config"] = {
    libs: "sap.ui.core, sap.m",
    preload: "async",
    async: true,
    theme: "sap_belize",
    "xx-waitForTheme": true
  };
</script>
<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"></script>
<body id="content" class="sapUiBody sapUiSizeCompact"></body>


来源:https://stackoverflow.com/questions/44872228/parse-xml-view-from-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!