xsd 模式中的自定义属性 [英] Custom attributes in an xsd-schema

查看:22
本文介绍了xsd 模式中的自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为一些基本但特定的需求制作一个简单的 xml 编辑器,但我不确定如何处理的是我希望能够在xsd 架构本身.

I'm trying to make a simple xml-editor for some basic but specific needs, the thing that I'm not sure how to handle is that I want to be able to have own custom attributes (or something) in the xsd-schema itself.

我的想法是这样的:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <xsd:element name="Book">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="Author" type="xsd:string" listable="1" />
            <xsd:element name="Pages" type="xsd:int" />
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
</xsd:schema>

我想要关于元素是否在架构中可列出"的信息(请注意,.xml 文件没有关于元素是否可列出的信息或线索,可列出属性只是一种方法在编辑器中组织元素).

Where I want information about whether the element is 'listable' or not in the schema (note that the .xml file have no information or clue as to whether the element is listable or not, the listable attribute is just a way to organize the elements in the editor).

它不需要是它自己的属性.如果有杂项属性或我可以玩的东西会很好.问题只是上面的模式没有验证(在这种情况下不支持'listable'属性.)

It doesn't need to be it's own attribute. If there's an misc attribute or something that I can play with that would be fine. Problem is just that the schema above doesn't validate (The 'listable' attribute is not supported in this context.)

有没有办法将这种信息存储在架构中?

Is there a way to store this kind of information in the schema?

似乎可以创建一个新的命名空间,但我不知道应该如何声明该命名空间,以便任何元素都可以在 xsd 中具有特殊属性(我宁愿避免弄乱 xml 文件这).而且仅仅为此创建一个新的命名空间似乎有点矫枉过正?

Seems like it would be possible to create a new namespace but I don't know how that namespace should be declared so that any element may have a special attribute in the xsd (I'd rather avoid messing with the xml file for this). And it seems a bit overkill to create a new namespace just for this?

还是我完全走错了路?

推荐答案

此信息应位于其自己的命名空间中.存储它的最佳位置是属性的注释中.您可以将注释附加到任何模式项,它们可以包含 xsd:documentation 元素,设计用于人类可读的文档,以及 xsd:appinfo,指定用于机器可处理的信息.所以你的例子看起来像:

This information should sit in its own namespace. The best place to store it would be in an annotation on the attribute. You can attach an annotation to any schema item and they can contain xsd:documentation elements, designed for human readable documentation, and xsd:appinfo, designated for machine-processable information. So your example would look like:

 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:foo="http://www.example.org/bar">
   <xsd:element name="Book">
      <xsd:complexType>
         <xsd:sequence>
            <xsd:element name="Author" type="xsd:string" >
        <xsd:annotation>
            <xsd:appinfo>
                <foo:listable value="true"/>
            </xsd:appinfo>
        </xsd:annotation>
             </xsd:element>
            <xsd:element name="Pages" type="xsd:int" />
         </xsd:sequence>
      </xsd:complexType>
   </xsd:element>
</xsd:schema>

这篇关于xsd 模式中的自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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