This spring I took Introduction to Databases a MOOC (Massive Open Online Class) from Stanford’s Jennifer Widom. It was very interesting, I learned a great deal from it. And one of the sections of the class that I really enjoyed, even though it sounded like it was going to be pretty dry, was the section on XML. I took quite a few pages of notes on the different XMl tools, so I figured I might as well post them to my blog.
XPath is a query language for selecting nodes from an XML document.
XML for the Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Selects all of countries from the country root node.
Path with Alternation
This will select countries with populations that speak Pashtu or Swedish.
Attributes are prepended with “@”
This will select the names of all countries
Path with Conditional
Select the names of all countries that have a population of less than 1,000,000.
Select all countries that have a population of less than 1,000,000.
data() prints out just the text value.