XML - XML Base
What XML Base Is
-
XML Base is a W3C specification that allows you to define a base URI for relative links inside an XML document.
-
It uses the attribute
xml:base
. -
Any relative URI in the document will be resolved using this base.
Why It’s Useful
-
Makes it easier to manage links in XML documents.
-
Instead of writing full absolute URLs everywhere, you set a base once and then use shorter relative paths.
-
If the base changes, you only update it in one place.
Example
<books xml:base="http://example.com/library/">
<book href="book1.xml">XML Guide</book>
<book href="book2.xml">Advanced XML</book>
</books>
How links resolve:
-
book1.xml
→http://example.com/library/book1.xml
-
book2.xml
→http://example.com/library/book2.xml
Key Points
-
Attribute:
xml:base="URI"
-
It can be applied at any element, and child elements will inherit it (unless overridden).
-
Useful in XML vocabularies like XLink, RDF, and SVG, where links often appear.
In Short
XML Base = a way to define a base URI inside an XML document so that relative links can be resolved consistently.