Relax NG 架构中的 xsd:ID
我有以下 xml 文件
<bookshop>
<book bid="1"> Programming in C# </book>
<book bid="2"> programming in Java </book>
<authors>
<author bidref="1"> person1 </author>
<author bidref="2"> person2 </author>
<author bidref="1"> person3 </author>
</authors>
</bookshop>
,然后我制作了以下 Relax NG 模式
start=element bookshop{
element book {attribute bid{xsd:ID},
text}
element authors{
element author { attribute bidref{xsd:IDREF},
text}
}}
但是,它总是给我错误,说属性 bid 的值无效必须是不带冒号的 XML 名称
I have the following xml file
<bookshop>
<book bid="1"> Programming in C# </book>
<book bid="2"> programming in Java </book>
<authors>
<author bidref="1"> person1 </author>
<author bidref="2"> person2 </author>
<author bidref="1"> person3 </author>
</authors>
</bookshop>
then I made the following Relax NG schema
start=element bookshop{
element book {attribute bid{xsd:ID},
text}
element authors{
element author { attribute bidref{xsd:IDREF},
text}
}}
However, it always gives me error said that value of attribute bid is invalid must be an XML name without colons
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我已经修复了您的 XML 示例中的错误。您的模式无法验证您在那里提供的 XML,因为它是错误的。无论如何,这可能至少部分是复制和粘贴错误。我认为你的意思是下面的模式(插入一个或多个标记和序列逗号):
顺便说一句,这种“俄罗斯娃娃”模式是非常难以维护的。如果您使用 RelaxNG,那么最好使用命名模式。
现在,您的根本问题是您已将属性
bid
和bidref
分别建模为ID
和IDREF
。这些类型让人想起 DTD。 ID 类型被定义为与“名称”生产相匹配其定义(在同一文档中)为:简单地说,“您不能以数字开头 ID,ID 也不能只是数字”。 XML ID(和 IDREF)值必须以字母开头。
顺便说一句,您的架构可能更好地表示为:
OK, I've fixed the errors in your XML example. Your schema can't validate the XML you've given there because it's, well, wrong. Anyway, that's probably at least partly a copy and paste error. The schema I think you mean is below (one or more marker and sequence comma inserted):
As an aside, this sort of 'russian doll' schema is horribly unmaintainable. If you are using RelaxNG you'd be better off with named patterns.
Now, your fundamental problem here is that you've modelled the attributes
bid
andbidref
asID
andIDREF
respectively. These types hark back to DTDs. An ID type is defined as matching the 'Name' production which is defined (in the same document) as:In simple terms that says "you can't start an ID with a number nor can an ID be just a number". XML ID (and IDREF) values must start with a letter.
Your schema, btw, might be better expressed as: