XML is the eXtensible Markup Language. It is designed to improve the functionality of the Web by providing more flexible and adaptable information identification. It is called extensible because it is not a fixed format like HTML (a single, predefined markup language). Instead, XML is actually a `metalanguage' -- a language for describing other languages -- which lets you design your own customized markup languages for limitless different types of documents. XML can do this because it's written in SGML, the international standard metalanguage for text markup systems.
XML documents conform to the following grammar:
XMLdocument ::= Pi* Element Pi* Element ::= Stag (char | Pi | Element)* Etag Stag ::= '<' Name Atts '>' Etag ::= '</' Name '>' Pi ::= '<?' char* '?>' Atts ::= ( Name '=' String )* String ::= '"' char* '"'
XML consists of tags and text. Tags come in pairs <date>8/25/2001</date> and must be properly nested:
<person> <name> ... </name> ... </person> --- valid nesting <person> <name> ... </person> ... </name> --- invalid nestingText is bounded by tags. For example,
<title> The Big Sleep </title> <year> 1935 </ year>Nesting tags can be used to express various structures. For example, the following represents a record:
<person> <name> Ramez Elmasri </name> <tel> (817) 272-2348 </tel> <email> elmasri@cse.uta.edu </email> </person>We can represent a list by using the same tag repeatedly:
<addresses> <person> ... </person> <person> ... </person> <person> ... </person> ... </addresses>An opening tag may contain attributes. These are typically used to describe the content of an element:
<author id="2787901">Philip A. Bernstein</author>
Please read XML in 10 points for more explanation.
The Document Object Model (DOM) is a platform- and language-neutral interface that allows programs and scripts to dynamically access and update the content, structure and style of XML documents. The following is part of the DOM Java interface:
public interface Node { public String getNodeName(); public NodeList getChildNodes(); public NamedNodeMap getAttributes(); ... } public interface Document extends Node { public NodeList getElementsByTagName(String tagname); ... } public interface NodeList { public Node item(int index); public int getLength(); } public interface NamedNodeMap { public Node getNamedItem(String name); ... }Read the DOM Java binding for the complete interface. The following Java code finds the telephone numbers of the CSE departments from the XML file depts.xml, which contains all UTA departments:
Parser parser = new Parser( "depts.xml" ); Document doc = parser.readStream( new FileInputStream( "depts.xml" )); NodeList nodes = doc.getDocumentElement.getChildNodes(); for (int i=0; i<nodes.getLength(); i++) { Node n = nodes.item(i); NodeList ndl = n.getChildNodes(); for (int k=0; k<ndl.getLength(); k++) { if ( (n.tagName = "dept") && (((CharacterData) n.getFirstChild).getData = "cse") ) { Nodelist ncl = n.getElementsByTagName("tel"); for (int j=0; j<ncl.getLength(); j++) { nc = ncl.item(j); System.out.print(((CharacterData) nc.getFirstChild).getData); } } } }Oracle 9i includes the Oracle XML Developer's Kit (XDK) for Java, which supports DOM. But Oracle 8i (available on Omega) does not support DOM.
Last modified: 8/24/01 by Leonidas Fegaras