在 XML 中,是否可以重用元素?
具体来说,我要解决的问题如下。我想定义一个table
包含一个元素tableSchema
和一个元素的元素dataSource
。table
我想以一种s 可以引用tableSchema
其他地方定义的方式来做到这一点。因此,我可以有多个报告table
根据相同的定义 s tableSchema
。
为了澄清,我希望能够做到以下几点:
<report name="Report1">
<page>
<table>
<!--reference to tableSchema named "foo"-->
<dataSource>fooData</dataSource>
</table>
</page>
<page>
<table>
<!--reference to tableSchema named "bar"-->
<dataSource>barData</dataSource>
</table>
</page>
</report>
和
<report name="Report2">
<page>
<table>
<!--reference to tableSchema named "foo" (same as above!)-->
<dataSource>anotherFooData</dataSource>
</table>
</page>
</report>
并且有tableSchema
sbar
和foo
在别处定义,可能在同一个 XML 文档中。
编辑添加:这里,tableSchema,我不是指另一个 Xml 模式。我的意思是定义 a 中的字段table
。例如,我希望能够执行以下操作:
<tableSchema name="bar">
<field>
<displayName>bar1</displayName>
<sourceName>bar1Source</sourceName>
<format>Currency</format>
</field>
<field>
<displayName>bar2</displayName>
<sourceName>bar2Source</sourceName>
<format>Text</format>
</field>
</tableSchema>
<tableSchema name="foo">
<field>
<displayName>foo1</displayName>
<sourceName>foo1Source</sourceName>
<format>Percent</format>
</field>
</tableSchema>
然后,在上面Report1
定义了一个包含两个table
s 的报告,一个根据 格式化tableSchema
foo
,第二个根据 格式化tableSchema
bar
,并Report2
定义一个报表,其中包含一个table
根据 格式化tableSchema
foo
并且架构与 中相同的报告Report1
。