[英]Add attribute to root element in schema XML
I have a root element named "Project". 我有一个名为“ Project”的根元素。 This root contains type named "Layer", but I don't know how to define attributes to the root (Project) element.
该根目录包含名为“ Layer”的类型,但是我不知道如何为根目录(Project)元素定义属性。
This attribute which want add to root: 要添加到根目录的此属性:
<attribute name="name" type="string" />
<attribute name="location" type="string" />
<attribute name="Description" type="string" />
<attribute name="CreationDate" type="string" />
This my schema: 这是我的架构:
<element name="Project" type="tns:Layer"></element>
<complexType name="Layer">
<sequence>
<element name="LayerName" type="string" maxOccurs="1"
minOccurs="0">
</element>
<element name="Order" type="integer"></element>
<element name="Visible" type="boolean"></element>
</sequence>
<attribute name="id" type="integer"></attribute>
</complexType>
Your schema has just one element. 您的架构只有一个元素。 It's type is called
Layer
. 它的类型称为
Layer
。 That means that <Project>
can contain the elements <LayerName>
, <Order>
and <Visible>
as well as an attribute named id
. 这意味着
<Project>
可以包含元素<LayerName>
, <Order>
和<Visible>
以及名为id
的属性 。
If you want to add attributes to the Project
element, you just have to place the attribute declarations after the one that already exists for ID: 如果要将属性添加到
Project
元素,则只需将属性声明放在ID已经存在的声明之后:
<complexType name="Layer">
<sequence>
<element name="LayerName" type="string" maxOccurs="1"
minOccurs="0">
</element>
<element name="Order" type="integer"></element>
<element name="Visible" type="boolean"></element>
</sequence>
<attribute name="id" type="integer"></attribute>
<attribute name="name" type="string"/>
<attribute name="location" type="string" />
<attribute name="Description" type="string" />
<attribute name="CreationDate" type="string" />
</complexType>
Now you can use: 现在您可以使用:
<Project name="..." location="..." ... > ... </Project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.