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

问题描述

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

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 文件没有关于元素是否可列出的信息或线索,listable 属性只是一种方式在编辑器中组织元素).

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).

它不需要是它自己的属性.如果有一个 misc 属性或我可以玩的东西,那就没问题了.问题只是上面的架构没有验证(此上下文中不支持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?

还是我完全用错了方法?

Or am I going about this the wrong way entirely?

推荐答案

此信息应位于其自己的命名空间中.存储它的最佳位置是在属性的注释中.您可以将注释附加到任何模式项,它们可以包含 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-schema 中的自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:11