XSD 元素 - 为 UI 显示添加显示名称 [英] XSD elements - adding displayname for UI display

查看:25
本文介绍了XSD 元素 - 为 UI 显示添加显示名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们有一个 XSD 模式,我们用它来生成 UI,创建符合模式的 XML 文档.对于架构中的所有 XElement,我们希望有一个用于 UI 的显示名称,而不仅仅是不太易读的元素名称.

So we have an XSD schema which we use to generate a UI, to create an XML document that conforms to the schema. For all the XElements in the schema, we want to have a display name to be used for the UI, rather than just the element name which is not very human readable.

我们使用 C# 和 Linq 来解析 XSD 并生成 UI.没有工具.

we use C# and Linq to parse the XSD and generate the UI. There is no tool.

最初的想法是使用 annotations/appInfo 为每个元素添加自定义的评论类型"属性,但它变得非常冗长,混淆了模式的核心目的.所以我们想知道我们是否可以只向 XSD 架构元素添加一个displayName"属性,这不一定会转换为需要该属性的 XML 数据.

The original idea was to use annotations/appInfo to add custom 'comment type' attributes to every element, but it got extremely verbose, obfuscating the core purpose of the schema. So we were wondering whether we can just add a 'displayName' attribute to the XSD schema elements, that will not necessarily translate to the XML data requiring that attribute.

例如之前的 XSD :-

E.g. XSD before :-

<xs:element name="grnBulb" type="xs:string">
  <xs:annotation>
    <xs:appinfo>
      <displayname>Bulbasaur</displayname>
    </xs:appinfo>
  </xs:annotation>
</xs:element>

XSD 之后:-

<xs:element name="grnBulb" type="xs:string" displayname="Bulbasaur" />

无论哪种情况,所需的 XML 数据都是相同的 :-

in either case, the require XML data is the same :-

<grnBulb>Awesome</grnBulb>

并且显示名称仅用于 UI 显示(Bulbasaur : 文本框).这是可能的/可行的,还是它们是完成相同任务的更好方法?

and the displayname is only used for UI display (Bulbasaur : textbox). Is this possible / feasible, or are they better ways to accomplish the same task?

推荐答案

我最后的学位项目是一个多平台移动应用程序,该应用程序使用 XML Schema 用于相同目的,此外,如果用户愿意,他/她也可以使用 XSLT将 XML 文档转换为 HTML 或 PDF,并使用 Schematron 添加允许我实施错误预防的语义限制(断言).DisplayName 对应用来说是一个很大的改进,所以我之前也遇到过这个问题,来看看你说的解决方案.

My final degree project was a multiplatform mobile app that used XML Schema for the same purpose, in addition, if the user wants he/she could also use XSLT to transform the XML document to HTML or PDF, and used Schematron to add semantic restrictions (assertions) that allowed me to implement error prevention. DisplayName is a great improvement for the app, so I also had this problem before and come to the solution you are talking about.

正如 XML Schema Specs 在您可以添加的每个元素中所述

As XML Schema Specs says in every element you can add

{具有非架构命名空间的任何属性...}>

{any attributes with non-schema namespace . . .}>

并且 XML 架构对于这些属性仍然有效.这比使用 xs:appinfo 更容易,为什么不使用它?因此您可以创建自己的命名空间以进行改进.请注意,您可能希望在未来添加更多改进.

and the XML Schema is still valid with those attributes. This is easier than use xs:appinfo, why not use it? So you can create your own namespace for your improvements. Note that you maybe want to add more improvements in the future.

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:imp="http://myImprovementsURI.com">
    <xs:element name="grnBulb" type="xs:string" imp:displayname="Bulbasaur"/>
</xs:schema>

因为我实现了类似的功能,所以我会告诉你我添加到命名空间的一些改进,以防你想知道它们:

Since I implemented a similar functionality I will tell you some of the improvements that I added to the namespace just in case you want to know them:

  • imp:label - 这与 xs:elementxs:attributedisplayName 相同>.
  • imp:image - 在元素或属性的标签附近添加一个图标.
  • imp:newPage - 元素将显示在新页面中(我不得不实现多页导航,因为手机屏幕尺寸很小),所以一个元素会显示一个链接,当你按下链接时该元素以整页显示.我不认为这对桌面平台有用.
  • imp:view - 某些元素可能有不同的视图(例如:您可以将枚举或选项显示为单选按钮或选择,您可以将字符串元素显示为输入或作为文本区域等)
  • imp:listLabelimp:listImageimp:newPage - 这些与其他相同,但用于列表.当某些内容具有 maxOccurs>1minOccurs<1 时,我创建了一个列表,该列表可以有自己的标题和自己的改进.示例:列表标题中的一组人的图标和列表中每个 person 出现的标题中的一个人的图标.
  • imp:label - this is the same as your displayName for both xs:element and xs:attribute.
  • imp:image - adds an icon near the label of a element or attribute.
  • imp:newPage - the element will display in new page (I had to implement multi page navigation because of the little mobile screen sizes), so a element showed a link and when you press the link the element is displayed in full page. I don't think that this is useful for desktop platforms.
  • imp:view - some element could have different views (e.g.: you can display a enum or a choice as radio buttons or as a select, you can display a string element as an input or as a textarea, etc.)
  • imp:listLabel, imp:listImage, imp:newPage - those are the same as the others but for lists. When something has maxOccurs>1 or minOccurs<1 I created a List that could have its own header with its own improvements. Example: a icon of a group of people in the list header and a icon of a person in the header of every occurrence of person in the list.

这篇关于XSD 元素 - 为 UI 显示添加显示名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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