Xml 为具有相同结构的元素重新命名多个名称
假设我有两条规则:Xml 为具有相同结构的元素重新命名多个名称,xml,relaxng,Xml,Relaxng,假设我有两条规则: JFalse = element JFalse { attribute label { xs:string }?, attribute jump { xs:string }?, attribute offset { xs:integer }? } JGt = element JGt { attribute label { xs:string }?, attribute jump { xs:string }?, attribute offs
JFalse = element JFalse {
attribute label { xs:string }?,
attribute jump { xs:string }?,
attribute offset { xs:integer }?
}
JGt = element JGt {
attribute label { xs:string }?,
attribute jump { xs:string }?,
attribute offset { xs:integer }?
}
(实际上要多得多)
我想做的显然是:
JFalseOrJGt = element (JFalse | JGt) {
attribute label { xs:string }?,
attribute jump { xs:string }?,
attribute offset { xs:integer }?
}
(但上述规定无效)。我可以用其他方法来做吗,这将导致更“压缩”的语法规则?这是一个选项:
JFalse = element JFalse { jFalseGt }
JGt = element JGt { jFalseGt }
jFalseGt =
attribute label { xs:string }?,
attribute jump { xs:string }?,
attribute offset { xs:integer }?
语法元素(JFalse | JGt)
实际上是声明元素的正确语法,该元素可以有两个名称中的任何一个。从压缩语法转换为XML语法时,trang
将其转换为:
JFalse
JGt
[...]
这正是你想要的
代码中有一个bug,但它与命名元素无关。问题是所有的xs:…
类型都无法解决。您有两个选择:要么添加datatypexs=”http://www.w3.org/2001/XMLSchema-datatypes“
在文件开头声明xs
前缀,或者编辑每个类型以使用xsd
前缀而不是xs
。默认情况下会声明xsd
前缀