How can I make two attributes in XML to be unique, for example in SQL I can do this by this code:
create table tablename(
StudentID varchar(20),
SubjectID varchar(20),
UNIQUE(StudentID,SubjectID)
)
On the other hand, I have the following code in XML:
<root>
<student StudentID="s1" />
<subject SubjectID="sb1" />
<tablename StudentID="s1" SubjectID="sb1" />
</root>
How can I make that the attributes StudentID
and SubjectID
both become UNIQUE?
From your comment ("
StudentID
is ID in elementStudent
,SubjectID
is ID in elementSubject
, andStudentID
,SubjectID
are IDREF intablename
. How can i make sure that the same value doesn't appear twice in these attributes?") it sounds as if this is what you already have in the DTD.In other words: you have already ensured that the same value does not appear twice in the
student/StudentID
andsubject/SubjectID
attributes. No value can appear more than once in a document as the value of an attribute declared as ID.If what you mean is "How do I ensure that no two
tablename
elements have the sameStudentID
,SubjectID
pair?", the answer is: with application code. There is no good way to do it with the DTD.