从字符串解析 XML 视图 [英] Parse XML View from String

查看:52
本文介绍了从字符串解析 XML 视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以解析 XML 字符串并将其用作 UI5 视图?

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

我喜欢做这样的事情:

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"
});

推荐答案

当然,通过使用sap.ui.xmlview 中的字符串定义属性viewContent,它可以作为API 参考 状态:

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

viewContent [...] 可以将视图描述保存为 XML 字符串或已解析的 XML 文档.

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

截至 1.56

工厂函数 sap.ui.xmlview 现已弃用.请使用 sap.ui.core.mvc.XMLView.create[API] 而不是分配给 definition 的字符串值设置.

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>

这篇关于从字符串解析 XML 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆