RelaxNG枚举的元素名称 [英] RelaxNG enumerated element names
问题描述
如果我的元素名称必须看起来像这样:
If I have element names that must look like this:
<myElem>
<subElem_n/>
<subElem_n+1/>
<subElem_n+2/>
</myElem>
其中'n'= 0;
我将如何实施RelaxNG?
How would I enforce this is RelaxNG?
棘手的部分是动态生成的元素名称.
The tricky part is the dynamically generated element names.
推荐答案
关于XML示例文件:
您提供的XML格式不正确. XML名称中不允许+
. 请参见此处,看看PrefixedName
和UnprefixedName
具有精确的语法.
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.
关于您的验证案例:
据我所知,您不能使用Relax NG在元素名称上添加动态生成的验证规则.
As far as I know, you can't add dynamically generated validation rules on element names with Relax NG.
检查这种结构的唯一方法是使用ISO Schematron或即将带有xs:assert
元素的XML Schema 1.1重新命令.
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.
这两种解决方案都使用XPath,您可以使用local-name()
函数检查名称.
Those two solutions use XPath and you can check the names with the local-name()
function.
还有一件事
请注意,拥有这种结构并不总是被视为一种好习惯,您也可以考虑采用这种结构:
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>
这篇关于RelaxNG枚举的元素名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!