From HaFrWiki
Jump to: navigation, search


EXtensible Markup Language) An open standard for describing data from the W3C. It is used for defining data elements on a Web page and business-to-business documents. XML uses a similar tag structure as HTML; however, whereas HTML defines how elements are displayed, XML defines what those elements contain. While HTML uses predefined tags, XML allows tags to be defined by the developer of the page. Thus, virtually any data items, such as "product," "sales rep" and "amount due," can be identified, allowing Web pages to function like database records. By providing a common method for identifying data, XML supports business-to-business transactions and has become "the" format for electronic data interchange and Web services


Each W3C XML Schema document (XSD (eXtensible Schema Definition)) is bound to a specific namespace through the targetNamespace attribute, or to the absence of namespace through the lack of such an attribute. We need at least one schema document per namespace we want to define (elements and attributes without namespaces can be defined in any schema, though).

    targetNamespace      = "http://example.org/ns/books/" 
    xmlns:xs             = "http://www.w3.org/2001/XMLSchema" 
    xmlns:bk             = "http://example.org/ns/books/" 
    elementFormDefault   = "qualified"
    attributeFormDefault = "unqualified">


The namespace declarations play an important role. The first one (xmlns:xs="http://www.w3.org/2001/XMLSchema") says not only that we've chosen to use the prefix xs to identify the elements that will be W3C XML Schema instructions, but also that we will prefix the W3C XML Schema predefined datatypes with xs as we have done all over the examples thus far.
Understand that we could have chosen any prefix instead of xs. We could even make http://www.w3.org/2001/XMLSchema our default namespace and in this case, we wouldn't have prefixed the W3C XML Schema elements nor its datatypes.


Since we are working with the http://example.org/ns/books/ namespace, we define it (with a bk prefix). This means that we will now prefix the references to "objects" (datatypes, elements, attributes, ...) belonging to this namespace with bk:. Again, we could have chosen any prefix to identify this namespace or even have made it our default namespaces (note that the XPath expressions used in xs:unique, xs:key and xs:keyref do not use a default namespace, though).


The targetNamespace attribute lets you define, independently of the namespace declarations, which namespace is described in this schema. If you need to reference objects belonging to this namespace, which is usually the case except when using a pure "Russian doll" design, you need to provide a namespace declaration in addition to the targetNamespace.

elementFormDefault & attribueFormDefault

The final two attributes (elementFormDefault and attributeFormDefault) are a facility provided by W3C XML Schema to control, within a single schema, whether attributes and elements are considered by default to be qualified (in a namespace). This differentiation between qualified and unqualified can be indicated by specifying the default values, as above, but also when defining the elements and attributes, by adding a form attribute of value qualified or unqualified.

Importing definitions

W3C XML Schema, not unlike XSLT and XPath, uses namespace prefixes within the value of some attributes to identify the namespace of data types, elements, attributes, atc. For instance, we've used this feature all along our examples to identify the W3C XML Schema predefined datatypes. This mechanism can be extended to import definitions from any other namespace and so reuse them in our schemas.

Reusing definitions from other namespaces is done through a three-step process. This process needs to be done even for the XML 1.0 namespace, in order to declare attributes such as xml:lang. First, the namespace must be defined as usual.

    targetNamespace    = "http://example.org/ns/books/" 
    xmlns:xml          = "http://www.w3.org/XML/1998/namespace" 
    xmlns:bk           = "http://example.org/ns/books/" 
    xmlns:xs           = "http://www.w3.org/2001/XMLSchema" 
    elementFormDefault = "qualified"
  attributeFormDefault = "qualified">

Then W3C XML Schema needs to be informed of the location at which it can find the schema corresponding to the namespace. This is done using an xs:import element.

    namespace      = "http://www.w3.org/XML/1998/namespace"
    schemaLocation = "myxml.xsd"/>

W3C XML Schema now knows that it should attempt to find any reference belonging to the XML namespace in a schema located at myxml.xsd. We can now use the external definition.

<xs:element name="title">
        <xs:extension base="xs:string">
          <xs:attribute ref="xml:lang"/>


XMI (XML Metadata Interchange) is an OMG standard to generate XML-based representations of UML and other OO data models. It provides a vendor-neutral format to store and exchange models between UML tools. Most UML modeling tools support XMI.
The following is an excerpt from an XMI 2.0 file. It defines a public class "MyClass" with a private attribute "myAttr" and a public operation "myOperation":

<ownedMember xmi:type='UML:Class' xmi:id='id345' visibility='public' isAbstract='false' name='MyClass'>
  <ownedAttribute xmi:id='id1138' name="myAttr" visibility='private' type='id42'/>
  <ownedOperation xmi:id='id1139' name='myOperation' visibility='public'>
     <ownedParameter xmi:id='1140' name='par1' type='id123' />


(eXtensible Stylesheet Language Transformation) Processing extensions to the XSL stylesheet language that are widely used to convert XML to HTML for screen display. XSLT is also used to convert an XML document to text, PDF or even to another XML document with a different schema (different set of definitions).

Conversion is accomplished with an "XSLT processor," which transforms the input based on XSLT and XSL codes in the document. The XSLT processor uses an "XML parser" to separate the XML elements into a tree structure before it manipulates them.
Xpath is another XSL tool that may be used in conjunction for identifying input, calculating numbers and manipulating characters.


In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes. XML documents are treated as trees of nodes. The root of the tree is called the document node (or root node).

Take the following XML-file:

<?xml version="1.0" encoding="ISO-8859-1"?>
  <!-- Example bookstore -->
      <title lang="en">Harry Potter</title>
      <author>J K. Rowling</author> 
Node examples
Node Name XML-Example
Attribute lang="en"
Comment Node <!-- Example bookstore -->
Document (root) <bookstore>
Element <author>J K. Rowling</author>

External links