Search code examples
xmlxml-validationdtd

Can XML DTD force different values for two attributes on same element?


Is there a way in XML DTD to force two attributes of the same element to have different values?

I'm writing an XML application representing a graph, using DTD and not XML Schema.

I declared the element Link, having two attributes host1 and host2 referring to the attribute hostName of the Host element with IDREF.

I would like to add a kind of constraint (if any) to forbid host1 and host2 having the same value (referring to the same host).


Solution

  • No, DTD can't express that constraint. Other options include:

    • XSD
    • Schematron [Credit: Thanks, @C.M.Sperberg-McQueen]
    • Application-level validation