i-Lab Guide To: XML

What Is It ?

XML is simply a customisable mark-up language, in other words its a bit like HTML but with the exception that tags (or elements) and their attributes can be defined, along with the allowable content and relationships between them. The definition of an XML document's structure is contained in a DTD file, or (more completely) in an XML schema file.

The main reason that XML has caught on so quickly is that it facilitates platform and vendor-independant data storage which can be relatively easily translated (e.g. using XSLT) to other formats.

Note: The JAXP Java API allows parsing of XML documents.

   
Relative Paths  
"child"
Selects all child nodes in at the level of the current context
"@attribute" Selects the named attribute from the current context
"child/@attribute" Selects the named attribute from the child nodes
"." Selects the current context node
".." Selects the parent node

Absolute Paths

 
"/root/child/leaf"
Selects all leaf elements descended from child and root elements
"/"
Selects all nodes at the root level
Predicates  
"line[3]" 3rd line element
"line[3|7]" 3rd or 7th line element
"line[position() = 3]" 3rd line element
"line[last()]" Last line element
"line[position() mod 2]" Every other line element
"line[@type='xxx']" Elements with a type attribute whose value equals xxx
Axes  
"child::xxx" Abbreviated form "xxx"
"parent::xxx" Abbreviated form ".."
"self::xxx" Abbreviated form "."
"attribute::xxx" Abbreviated form "@xxx"
"ancestor::xxx"  
"ancestor-or-self::xxx"  
"descendant::xxx"  
"descendant-or-self::xxx"  
"preceding-sibling::xxx"  
"following-sibling::xxx"  
"preceding::xxx"  
"following::xxx"  
"namespace::xxx"  
Functions  
position()  
last() Returns the position of the last node in the node-set
   

© 2003 i-Lab Limited