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
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: