On Tue, 12 Jun 2001, you wrote:
> Hi, Iīve got a doubt in xml.
We all suffer from these :-)
> I would like to make a link a "C language link" in XML. Iīm generating a
> DTD and I want to make a link from an element to another element. So imagine
> in this example I want to make a link from Binary Element to Term Element.
I'm not quite clear what you mean when you say "link" here.
> I donīt want to insert a Term element but just saying, that it has a
> reference to it. So:
> <!ELEMENT Binary (D, F, HERE IS WHERE I WANT A LINK TO TERM ELEMENT) // in
> order not to define again the element, but to say itīs a reference.
But putting Term in the content model for Binary doesn't
> <!ELEMENT Occurrence (#PCDATA)>
> <!ATTLIST Occurrence Id ID #REQUIRED>
> <!ELEMENT Term (#PCDATA)>
> <!ATTLIST Term Id ID #REQUIRED>
> <!ELEMENT Whatever (A, B)>
> <!ATTLIST Whatever Id ID #REQUIRED>
I don't see where these fit into the content model for Binary.
> So I thought doing like this:
> <!ELEMENT Binary (D, F)>
> <!ATTLIST Binary Mylink IDREF #REQUIRED>
> But the problem is that this IDREF can link not only to Term
> elements but to Occurrence and Whatever ones. Is there any chance to make
> this Mylink point to Id attributes but from Term element?
Probably not in XML. I think you can do this in full SGML with
a lot of HyTime architecture, but I'm not an expert in HyTime
and I know only a handful of people who are.
However, you could enforce it in an editor or whatever system
you use to create your XML by adding a macro or script or other
control which would check the IDREF at data entry time and
disallow it if it pointed to anything other than a Term element
I suspect you could also do it using a Schema rather than a DTD.
If your design is intended to guarantee that there is exactly
one such link in each instance and that the Term element type
will occur only one time, you could say something like
<!DOCTYPE Demo [
<!ELEMENT Demo (Binary,Term)>
<!ELEMENT Binary (D,F,Link)>
<!ELEMENT Link EMPTY>
<!ATTLIST Link foo IDREF #FIXED "blort">
<!ELEMENT D (#PCDATA)>
<!ELEMENT F (#PCDATA)>
<!ELEMENT Term (#PCDATA)>
<!ATTLIST Term bar ID #REQUIRED>
But ID attributes can only have #IMPLIED or #REQUIRED default
values, not #FIXED, so you'd still have to enter the required
value by hand (or force it in under program control).