RelaxNG enumerated element names

只愿长相守 提交于 2019-12-12 03:19:14

问题


If I have element names that must look like this:

<myElem>
  <subElem_n/>
  <subElem_n+1/>
  <subElem_n+2/>
</myElem>

Where 'n' = 0;

How would I enforce this is RelaxNG?

The tricky part is the dynamically generated element names.


回答1:


Concerning your XML sample file :

The XML you provide is not well formed. The + is not allowed in XML names. See here, have a look at PrefixedName and UnprefixedName to have precise syntax.

Concerning your validation case :

As far as I know, you can't add dynamically generated validation rules on element names with Relax NG.

The only way to check this kind of structure is to use either ISO Schematron or the upcoming XML Schema 1.1 recommandation with the xs:assert element.

Those two solutions use XPath and you can check the names with the local-name() function.

One more thing

Be aware that it's not always considered a good practice to have such structure, you can also consider this kind :

<myElem>
    <subElem rank="1"/>
    <subElem rank="2"/>
    <subElem rank="3"/>
    ...
</myElem>


来源:https://stackoverflow.com/questions/9247467/relaxng-enumerated-element-names

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!