Enterprise-trusted document language.
<?xml version="1.0" encoding="UTF-8"?>
<Oh>
<My>
<XML what="XML">Hello XML & XSLT!</XML>
</My>
</Oh>
eXtensible Markup Language, like JSON or YAML, is a file format for stucturing documents containing nested key-value data. But, where JSON is just a data format, XML has many other powerful features that make it more suitable for complex documents. Blocks of data can also store additional metadata, xPath and XSL enable for easy document querying and modification,
Why does a markup language have its own manual? The complex systems built around XML warrant a unique umbrella page.
XML can be maniuplated in all popular programming languages, and like json, enables systems built with different data stores and languages to share objects.
=>
use a database.=>
use JSON.<?xml version="1.0" encoding="UTF-8"?>
<BusinessCard>
<name>Ryan Fleck</name>
<company>MNP LLP</company>
<email>[email protected]</email>
</BusinessCard>
An XML Document can include:
Name | Example |
---|---|
Document Declaration | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
Elements/Attributes | <element attribute="value">Element Value</element> |
Comments | <!-- Oh, it's like an HTML comment. --> |
Character Data | <![CDATA[Text to parse]]> |
Processing Instructions | <?CurrencyBase mode="USD"?> |
Entity References | This is a string that is (©)2018 |
Essentially, XML expresses data with elements:
<element attr-one="value" attr-two="another">Content</element>
Elements have tags, attributes and content. If the content is complex, it can be stored as character data by using a <![CDATA[ content ]]>
statement as the content of an element.
Point to a .css
file so the XML can be rendered in a browser:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="bizcard.css"?>
<rolodex>
<BusinessCard>
<name>Ryan Fleck</name>
<company>Unaffiliated</company>
<position>Consulting Developer</position>
<email type="work">[email protected]</email>
</BusinessCard>
<BusinessCard>
<name>Clone of Ryan Fleck 12</name>
<company>MNP LLP</company>
<position>Co-Op Developer</position>
<email type="work">[email protected]</email>
</BusinessCard>
<BusinessCard>
<name>Clone of Ryan Fleck 13</name>
<company>Starbucks Coffee</company>
<position>Barista</position>
<email type="work">[email protected]</email>
</BusinessCard>
<BusinessCard>
<name>Clone of Ryan Fleck 22</name>
<company>Unaffiliated</company>
<position>Consulting Analyst</position>
<email type="work">[email protected]</email>
</BusinessCard>
</rolodex>
rolodex {
padding: 1em;
}
BusinessCard {
background: #444;
text-align: left;
border: 1px solid gold;
color: gold;
margin: 1em;
padding: 1em;
display: block;
min-width: 100px;
max-width: 300px;
}
name,
company,
position,
email {
color: gold;
display: block;
}
name {
font-size: 1.3em;
}
position {
font-size: 0.8em;
}
XPath, eXtensible Path Language, is used for quickly gathering single/lists of nodes from an XML document. It could be described as a language for defining subsets of an XML document. Here is part of an XML document that will serve as an example throughout the remainder of this section:
<rss version="2.0">
<channel>
<title>OC Transpo - Live Updates</title>
<link>http://www.octranspo.com/</link>
<description>
Daily route changes resulting from detours and cancelled trips are listed here by OC Transpo staff on weekdays, Saturdays until 9 pm and Sundays until 5 pm.
</description>
<atom:link href="http://octranspo1.com/feeds/updates-en" rel="self" type="application/rss+xml"/>
<item urgent="urgent">
<title>DETOUR: Chapel Crescent Closure (Mann to Lees)</title>
<pubDate>Mon, 15 Oct 2018 14:51:00 EDT</pubDate>
<category>
<![CDATA[ Detours ]]>
</category>
<category>
<![CDATA[ affectedRoutes-16,85 ]]>
</category>
<link>http://octranspo1.com/update-details/215294</link>
<description>
<![CDATA[ October 15 2018 - <p> From <strong>9am to ...shortened... </em></a></p>]]>
</description>
<guid>http://octranspo1.com/update-details/215294</guid>
</item>
<item>
<title>DETOUR: Piperville Road Closure</title>
<pubDate>Wed, 03 Oct 2018 09:43:00 EDT</pubDate>
<!-- More data... -->
</item>
<!-- Many more items... -->
</channel>
</rss>
If I were programming a service that processes each update item, I would want to grab both the content of elements, and any useful attributes.
Basic XPATH functions are as follows:
//rss/channel/item
.//rss/channel/item[1]
.//rss/channel/item[last()]
.//item
.//title[@urgent]
.XSLT, XML Stylesheet Language Transformations, are like CSS for XML. You can still use CSS to style XML, but XSL is… also something you can use.
Not studied yet.
Not studied yet.
Not studied yet.
Title: XML
Word Count: 683 words
Reading Time: 4 minutes
Permalink:
→
https://manuals.ryanfleck.ca/xml/