XML - XML Linking
What is XML?
XML stands for eXtensible Markup Language. It's used to store and transport data. XML doesn’t DO anything — it just holds data in a structured format that both humans and machines can read.
Example:
<student>
<name>John</name>
<age>20</age>
</student>
What is XML Linking?
Just like you can add links to webpages using HTML (like <a href="...">
), XML allows you to link different parts of XML documents — or even link to other documents. This is called XML Linking.
XML Linking is done using XLink, XPointer, and sometimes XInclude.
Components of XML Linking
Let’s break it into 3 main concepts:
1. XLink (XML Linking Language)
XLink is a standard that allows elements in XML to behave like hyperlinks.
Types of links:
Type | Description |
---|---|
Simple Link | Like HTML's <a> tag. Links from one resource to another. |
Extended Link | Links from one element to multiple resources or from multiple elements to one. |
Example of Simple XLink:
<book xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="http://example.com/book1"
xlink:type="simple">
Learn XML
</book>
Here, the book
element acts like a hyperlink.
2. XPointer (XML Pointer Language)
XPointer is used to point to specific parts inside an XML document, like jumping to a particular paragraph in a book.
Example:
xlink:href="book.xml#xpointer(/bookstore/book[1]/title)"
This means: go to book.xml
and get the title of the first book.
Think of it like a GPS for XML — it helps you find exactly where something is in the file.
3. XInclude (XML Inclusion)
XInclude is used when you want to include one XML document inside another.
Example:
<xi:include href="chapter1.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
This means: "Include the content of chapter1.xml
here".
Why Use XML Linking?
-
To reuse content from other XML documents
-
To connect related data
-
To build complex XML documents from smaller ones
-
To improve organization and readability