Skip to content
UoL CS Notes

Basics of XML

COMP207 Lectures

XML

XML files look similar to HTML files. This is an XML document representing the graph from last lecture:

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<lecturers>
	<lecturer>
		<name>J. Fearnley</name>
		<phone>7954…</phone>
		<teaches>
			<code>COMP105</code>
			<title>Progr. Paradigms</code>
		</teaches>
		<memberOf>Economics &</memberOf>
	</lecturer>
	...
</lecturers>

There are the following structures:

  • Tags - Enclosed between <>.
    • Open with <...>.
    • Close with </...>.
  • Element - The opening, closing tags and all data in-between.
  • Attributes:
    • Elements can have attributes (name/value pairs), which are put into the element’s opening tag:

        <lecturer name="J. Fearnley">
            <module code=”COMP105” title=“Programming Paradigms” />
        </lecturer>
      
    • Sub-elements should be used if there is a one to many relationship.

Nodes with Multiple Parents

These don’t exist in XML:

  • There is a notion of references like symbolic links in a file-system.

Other Features

  • There can be an optional document type definition or XML schema at the start of the XML document.
  • Entity References - Can serve as shortcuts to often repeated text or to distinguish reserved characters from content.
  • Comments - Enclosed in <!-- ... --> tags.
  • CDATA - These are processing instructions that can be used to provide information to the application.