Introduction
This week we introduced XLink which is short for XML Linking Language, which is used in XML documents to create hyperlinks. All elements can be transformed into hyperlinks and behave like one. XLink appart from simple links supports extended links like linking multiple resources together. These links can be defined outside the linked files.
Quick questions:
Question 1
One of the advantages claimed for the “extended links”, that the W3C consortium intended to be part of the XLink language, was that the definition of a particular hyperlink could be located, not in the local resource (the document where the link starts), or the remote resource (the document where the link ends), but in a quite different “third party” document. Why might this be an advantage?
Answer
All XML elements can be turned into hyperlinks. Below is an example showing how the element myScgool is turned into a hyperlink using this facility of XLinks. If the type attribute was set to extended instead of single one would have been able to define multiple links.
<mySchool xlink:type = "simple" xlink:href="http://stcmalta.com"> Click to visit school site </mySchool>
Question 2
The XLink language provides an attribute for a hyperlink called show – it has several possible values. What is the effect of providing such a link with each of the following attribute values?
show=”replace”
show=”new”
show=”embed”
Which of these three attribute values is the default?
Answer
Below are the meaning to each one
show = "new"
When one clicks on the hyperlink a new window is opened.
show = "embed"
When one clicks on the hyperlink a new tab is opened in the same window
show = "replace"
When one clicks the hyperlink the current window which is open will be replaced with that link
By default windows are replaced therefore the default attribute is show = "replace"
Longer questions:
1. Here is an XML document:
<?xml version="1.0"?>
<!DOCTYPE memo SYSTEM memo.dtd">
<?xml-stylesheet href="stylesheet02.css" type="text/css"?>
</memo>
<heading>memo 1334</heading>
<date>date: 11 November 09</date>
<time>time: 09:30</time>
<sender>from: The Managing Director</sender>
<addressee>to: Heads of all Departments</addressee>
<message>I think we should be making wind-turbines. Have a look at this website. Tell me what you think. </message>
</memo>
The accompanying .dtd file looks like this:
<?xml version= "1.0" ?>
<!DOCTYPE memo [
<!ELEMENT memo (heading, date, time, sender, addressee, message)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT time (#PCDATA)>
<!ELEMENT sender (#PCDATA)>
<!ELEMENT addressee (#PCDATA)>
<!ELEMENT message (#PCDATA)>
]>
At the point where the document says this website, there is supposed to be a hyperlink that takes the reader to the website:
http://engineering.suite101.com/article.cfm/wind_power
a) Amend the document, so that the link is in fact there. Make any necessary changes to the .dtd file as well.
b) b) Suppose that the heading of one of the sections in the target website is <A NAME=“WE Elec Facts”>Wind Energy Electricity Facts</A>, including the tags as shown. What changes would you have to make to the link in the managing director’s memo, to make the hyperlink finish at that point rather than at the wind_power document as a whole?
Answer a
1.<memo xmlns:xlink="http://www.linkgoeshere">
2. <heading>memo 1334</heading>
3. <date>date: 11 November 09</date>
4. <time>time: 09:30</time>
5. <sender>from: The Managing Director</sender>
6. <addressee>to: Heads of all Departments</addressee>
7. <message>I think we should be making wind-turbines. Have a look at
8. <link xlink:type="simple"xlink:href="http://engineering.suite101.com/article.cfm/wind_power">this website
9.</link>.
10. Tell me what you think.
11. </message>
12. </memo>
Above is the modified XML document, including the HYPERLINK. First the namespace was declared which is found in line 1, which is the root node. On line 8 there is the new element which was added so that the hyperlink can be added. The attribute simple was used for the xlink:type. This shows that there is one hyperlink.
1. <?xml version= "1.0">
2. <!ELEMENT memo (heading, date, time, sender, addressee,message)>
3. <!ATTLIST memo xmlns:xlink CDATA #FIXED "http://www.linkgoeshere">
4. <!ELEMENT heading (#PCDATA)>
5. <!ELEMENT date (#PCDATA)>
6. <!ELEMENT time (#PCDATA)>
7. <!ELEMENT sender (#PCDATA)>
8. <!ELEMENT addressee (#PCDATA)>
9. <!ELEMENT message (#PCDATA|link)*>
10. <!ELEMENT link (#PCDATA)>
11. <!ATTLIST link xlink:href CDATA #REQUIRED xlinkL:type (simple |extended) #REQUIRED>
Above is the DTD arranged after the changes have been made to the XML file as this won’t validate anymore with the original DTD. Everything remained the same except some elements and attributes were added. Line 3 is a new line which defines the memo element and is the xmlns:xlink. Line 9 was changed to allow not only allow parsed data hence #PCDATA but also the link elements. Line 11 shows the link element needs and “href” and a “type” attribute, which can be set to either simple or extended.
Answer B
This can be arranged by adding an “#” followed with the name of the anchor
<link xlink:type = “simple”
Question 2.
Here is another XML document:
<?xml version="1.0"?>
<!DOCTYPE memo SYSTEM memo.dtd">
<?xml-stylesheet href="stylesheet02.css" type="text/css"?>
</memo>
<heading>memo 1335</heading>
<date>date: 11 November 09</date>
<time>time: 09:45</time>
<sender>from: The Managing Director</sender>
<addressee>to: Heads of all Departments</addressee>
<message>I think we should be making solar panels. Have a look at this website. Tell me what you think. </message>
</memo>
At the point where the document says this website, there is supposed to be a hyperlink that takes the reader to a suitable website. Find one, and amend the document, so that the link is in fact there. Is it necessary to make any changes to the .dtd file, or can we use the file as you amended it before?
Answer 2
This question is the same as the previous question, a namespace is to be declared within the root node. A new element is to be added where on can add the hyperlink as shown below. Since the link will be only replaced there is no need for the DTD to be fixed, therefore it will validate with the existing one.
<link xlink:type="simple" xlink:href ="http://vincent-lui.suite101.com/solar-paneling-for-the-home-a226122"> this website </link>