繁体   English   中英

XML模式:具有此名称模式的元素具有此属性

[英]XML Schema: elements with this name pattern have this attribute

我有这个XML示例。

<root>
  <Ilhas_da_Madeira_e_Porto_Santo update-date="2016-04-01" update-time="14:14:46">
    <Santana update-author="sourceData" update-date="2016-04-01" update-time="14:14:48">
      <year1995 ncrimes="33"/>
      <year1994 ncrimes="58"/>
      <year1993 ncrimes="33"/>
    </Santana>
  </Ilhas_da_Madeira_e_Porto_Santo>
  <NE update-date="2016-04-01" update-time="14:14:48">
    <NE update-author="sourceData" update-date="2016-04-01" update-time="14:14:48">
      <year1995 ncrimes="163"/>
      <year1994 ncrimes="125"/>
      <year1993 ncrimes="126"/>
    </NE>
  </NE>
</root>

(XML架构-xsd)我已经使用xs:groupxs:attributeGroup对元素和属性进行了分组。

问题:是否可以这样做: elements with name_pattern="year(\\d){4}" have attribute=ncrimes吗?

XML Schema的设计不鼓励这样的XML词汇设计。 通常,具有这样的内部结构的元素或属性名称是不好的形式。 而不是

<year1995 ncrimes="163"/>

你应该使用类似

<year y="1995" ncrimes="163"/>

通过这种设计,您会发现XML堆栈中的所有内容(不仅是XML Schema,而且还包括XSLT,XPath和DOM之类的东西)都可以更加顺畅地工作。

但是,如果您不能或不会更改词汇表设计,那么您的下一个最佳选择是使用abstract="true"name="year"定义元素声明,然后将元素year1995year1994等定义为置换组的year

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM