Links In Xml Documents
<h3 class="heading-h6"><a name="THLToolboxhomegtDevelopersZonegtWebDevelopmentgtXmlMarkupinTHLgtLinksinXMLDocuments" class="anchorpoint"></a><a href="/tools/wiki/home.html">THL Toolbox</a> > <a href="/tools/wiki/Developers%27%20Zone.html">Developers' Zone</a> > <a href="/tools/wiki/Web%20Development.html">Web Development</a> > <a href="/tools/wiki/Xml%20Markup%20in%20THL.html">Xml Markup in THL</a> > Links in XML Documents</h3><p class="paragraph">
</p><h3 class="heading-h1"><a name="LinksinTHLXMLdocuments" class="anchorpoint"></a>Links in THL XML documents</h3><p class="paragraph"><strong class="bold">Contributor(s):</strong> Than Grove</p><p class="paragraph">There are two basic types of links in an XML document. Internal links are links to a section within the same document, much like hash URLs and anchor tags in an HTML document. External links, as the name implies, are links to other, external documents.
</p><h3 class="heading-h2"><a name="InternalLinksandAnchors" class="anchorpoint"></a>Internal Links and Anchors</h3><p class="paragraph">The two elements used for internal links in THL essays are <ref></ref> and <ptr />. The difference being that the <ref> element can be wrapped around text including other elements, whereas a <ptr /> element has no text within it but points to another location in the same document. The more common of these is the <ref> element. The only attribute that the <ref> element requires is a target attribute which <strong class="bold">must</strong> be set to the ID of another element, most likely a <div>, within the same document. For example,</p><div class="code"><pre>.... See the section on <ref target=<span class="java-quote">"b2"</span>>the Dalai Lama</ref>.</pre></div><p class="paragraph">where the div for that section has an id of "b2" as in:</p><div class="code"><pre><div id=<span class="java-quote">"b2"</span>>
<head>The Dalai Lama</head>
....
</div></pre></div><p class="paragraph">This will work for <div>s that are a different section from where the link or <ref> element is. To link to another part of the same section, which appears on the same webpage, the markup is slightly different. To do this one must place an <anchor> tag with a unique ID just above the place where one wants to link to. An example is in Debreczeny article in JIATS 06. In the second section there are links to Figure 4 which is in that same section. To mark these up, an <anchor> tag with an id of "img04" was placed above the <figure> tag thus:</p><div class="code"><pre><anchor id=<span class="java-quote">"img04"</span> /></pre></div><p class="paragraph">And the <ref> links set their target to that same ID, but add a rend attribute equal to "samepage", as in:</p><div class="code"><pre><ref target=<span class="java-quote">"img04"</span> rend=<span class="java-quote">"samepage"</span>>Fig. 4</ref></pre></div><p class="paragraph">Finally, if one wants to link to another section in the document <em class="italic">and</em> scroll to a specific anchor in that section, such as is done in Debreczeny section 3, one uses the section ID as the target value and the n attribute for the anchor's id, as in this link:</p><div class="code"><pre><ref target=<span class="java-quote">"b2"</span> n=<span class="java-quote">"img04"</span>>Fig. 4, no. 14</ref></pre></div><p class="paragraph">The <ptr /> has not been implemented for THL because there has been no call for it.</p><ul class="star"><li><strong class="bold">Element:</strong> <ref> <em class="italic">{text of link}</em> </xref></li>
<li><strong class="bold">Attributes and Values:</strong><ul class="star"><li><strong class="bold">target:</strong> must be the ID value of another element in the same document.</li>
<li><strong class="bold">rend:</strong> for internal links with in the same section that involve only scrolling to the position on the page, use rend="samepage"</li>
<li><strong class="bold">n:</strong> for internal links to different sections from where the <ref> tag is located, use the n attribute to indicate an anchor name to scroll to on the target page.</li></ul></li></ul><p class="paragraph">
</p><h3 class="heading-h2"><a name="ExternalLinks" class="anchorpoint"></a>External Links</h3><p class="paragraph">External links are marked up using the <xref type="url"> element. In THL essays all external links open up in popup “lightboxes” <em class="italic">unless</em> the rend attribute is set to either "_self" or "_top" (to open the content in the same window as the present essay) or "_blank" (to open up the content in a new window). The <xref> element has a doc attribute that is set to the name of a predefined entity, which contains the actual URL for the link. The entities for links are defined in one of two files:</p><ol><li><img src="/" alt="external link: " title="external link"/><span class="nobr"><a href="http://texts.thlib.org/essays/external-links.dtd" target="rwikiexternal">http://texts.thlib.org/essays/external-links.dtd</a></span></li>
<li><img src="/" alt="external link: " title="external link"/><span class="nobr"><a href="http://texts.thlib.org/essays/internal-links.dtd" target="rwikiexternal">http://texts.thlib.org/essays/internal-links.dtd</a></span></li></ol><p class="paragraph">An example entity declaration is:</p><div class="code"><pre><!ENTITY dept-ed-us SYSTEM <span class="java-quote">"http://www2.ed.gov/"</span> NDATA HTML ></pre></div><p class="paragraph">This defines an entity by the name of "dept-ed-us" to have the value of "http://www2.ed.gov/" which is HTML. The doc attribute of the <xref> element would be then set to "dept-ed-us".
</p><h3 class="heading-h2"><a name="Summary" class="anchorpoint"></a>Summary</h3><p class="paragraph">Below is a summary of the <xref> element:</p><ul class="star"><li><strong class="bold">Element:</strong> <xref> <em class="italic">{text of link}</em> </xref></li>
<li><strong class="bold">Attributes and Values:</strong><ul class="star"><li><strong class="bold">type:</strong> must be "url" for links</li>
<li><strong class="bold">doc:</strong> contains the name of the URL link entity defined in either the external-links.dtd or files-links.dtd files, usually this is a site's home URL.</li>
<li><strong class="bold">n:</strong> contains the internal path within the site that points to the page in question. Thus, to get to the grants page in the U.S. Department of Educations web-site. The doc attribute might be set to "dept-ed-us" which is defined as "http://www2.ed.gov/" and then the n attribute would be set to "fund/grants-apply.html".</li>
<li><strong class="bold">rend:</strong> can contain the same values as the target attribute in an HTML <a> tag – "_blank" (opens in new window), "_top" or "_self" (opens in same window).</li></ul></li></ul><p class="paragraph">
</p><h3 class="heading-h2"><a name="Example" class="anchorpoint"></a>Example</h3><div class="code"><pre><xref doc=<span class="java-quote">"moe"</span> n=<span class="java-quote">"edoas/website18/en/laws_e.htm"</span> type=<span class="java-quote">"url"</span> rend=<span class="java-quote">"_blank"</span>><img src="/" alt="external link: " title="external link"/><span class="nobr"><a href="http://www.moe.edu.cn/​edoas/​website18/​en/laws_e.htm</xref>" target="rwikiexternal">http://www.moe.edu.cn/​edoas/​website18/​en/laws_e.htm</xref></a></span></pre></div><p class="paragraph">The character entities “&#x200b;” insert a zero-width space. This is used to allow the longer URLs in the text to break and line-wrap.
</p><h3 class="heading-h6"><a name="ProvidedforunrestrictedusebythespanclassnobrimgsrcsakairwikitoolimagesicklearrowgifaltexternallinktitleexternallinkahrefhttpwwwthliborgtargetrwikiexternalTibetanandHimalayanLibraryaspan" class="anchorpoint"></a><em class="italic">Provided for unrestricted use by the <span class="nobr"><img src="/" alt="external link: " title="external link"/><a href="http://www.thlib.org" target="rwikiexternal">Tibetan and Himalayan Library</a></span></em></h3>