Use multiple xlink:href references inside the same tag, ideally under own, custom names

109 Views Asked by At

So I can have (pardon me for the bad schema structure of this example but it's only to make a point) the following XML:

<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
  <person id="W1" xsi:type="woman" eyes="blue"/>
  <person id="M1" xsi:type="man" eyes="brown"/>
  <person xsi:type="child">
        <parent ancestor="mother" xlink:href="W1"/>
        <parent ancestor="father" xlink:href="M1"/>
  </person>
</xml>

but could I make it much more dense?

In particular to collapse reference links into attributes of the person directly?

Something like having two hrefs (here hrefM and hrefF respectively as can't have multiple attributes of same name…):

<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
  <person id="W1" xsi:type="woman" eyes="blue"/>
  <person id="M1" xsi:type="man" eyes="brown"/>
  <person xsi:type="child" xlink:hrefM="W1" xlink:hrefF="M1"/>
</xml>

?

I know I can just drop whole xlink idea and use my own attribute names (uid and refM, refF):

<xml>
  <person uid="W1" xsi:type="woman" eyes="blue"/>
  <person uid="M1" xsi:type="man" eyes="brown"/>
  <person xsi:type="child" refM="W1" refF="M1"/>
</xml>

but then I am making my own, lame "standard".

I am wondering if XLink could be still used but with schema/structure adapted to cater for (1) custom names (uid, refF, refM) and (2) multiple reference attributes inside same tag?

1

There are 1 best solutions below

0
mamift On

I am wondering if XLink could be still used but with schema/structure adapted to cater for (1) custom names (uid, refF, refM) and (2) multiple reference attributes inside same tag?

What you're asking for is not possible. The Xlink standard defines all of its attributes, like href, type, role etc. as global attributes. If you use any attribute not part of the standard then you lose the benefit of using a common W3C standard that other consuming applications would already know. The nature of XML requires that any XML schema that defines attribute names, the names must be known in advance - basically, it does not allow variadic attribute names.

I think you should reconsider the first example XML you provided:

<xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
  <person id="W1" xsi:type="woman" eyes="blue"/>
  <person id="M1" xsi:type="man" eyes="brown"/>
  <person xsi:type="child">
        <parent ancestor="mother" xlink:href="W1"/>
        <parent ancestor="father" xlink:href="M1"/>
  </person>
</xml>

There's a section of the XLink standard ('Extended links') that basically recommends doing what you've already done here. Their own sample XML is pretty close:

  <person
    xlink:href="students/patjones62.xml"
    xlink:label="student62"
    xlink:role="http://www.example.com/linkprops/student"
    xlink:title="Pat Jones" />

  <person
    xlink:href="profs/jaysmith7.xml"
    xlink:label="prof7"
    xlink:role="http://www.example.com/linkprops/professor"
    xlink:title="Dr. Jay Smith" />