‘tutorial’ Tagged Posts

Mastering The Essentials Of XML Schema

XML schema definition languages are derived from the recommendations of the World Wide Web Consortium (W3C). They use XML 1.0 syntax and their role ...

 

XML schema definition languages are derived from the recommendations of the World Wide Web Consortium (W3C). They use XML 1.0 syntax and their role is to explicit describe the structure of XML documents and constrain the data which they may contain. They offer a distinct improvement on the more limited schema features offered by the Document Type Definition (DTD) recommendation which formed part of the original XML specification released in 1998. The most widely used schema language is the one defined by the W3C in 2001: W3C XML Schema. However, there are alternatives, such as RELAX NG and Schematron.

Schema documents are the more sophisticated successors to DTDs and overcome some key limitations associated with them. Firstly, DTDs do not support data types. Secondly, DTDs do not support namespaces. Thirdly, DTDs do not allow developers to accurately define the number of permitted occurrences of elements within their parent element.

An XML schema is concerned with the structure of an XML instance document by defining what each element must or may contain. An element is limited by its type. For example, an element of complex type can contain child elements and attributes, whereas a simple-type element can only contain text. The diagram below gives a first look at the types of XML Schema elements.

Three main purposes are fulfilled by schema documents. Firstly, they can be used to validate XML documents. Secondly, they can be used as a dictionary or grammar for the creation of a given class of XML document. And, thirdly, they can be used to provide documentation for XML documents.

Each XML schema is itself an XML document and contains definitions of all elements and attributes permitted in a given class of XML documents. The schema also specifies the structure or hierarchy to which elements must adhere and the type of content each particular element may contain. Elements may be of the simple or complex type. Complex type elements may contain child elements as well as attributes. Simple type element may only contain data. XML documents using a particular schema are referred to as instances of the schema. An XML instance that correctly adheres to its associated schema is said to be valid.

Validation is usually the principal role of schema documents. Validation offers many benefits. It ensures the consistency of data within a document. It ensures that data has the right structure and internal hierarchy. It ensures that data within the document structure is of the correct type. It allows us to receive data from multiple sources.

Most XML documents are produced by programs and scripts written to extract information held in databases and transform it into XML. However, it is also possible for human beings to create XML documents. Schemas can be used during this process to assist in the document creation process. XML schemas also provide a mechanism for documenting XML documents and form an important part of the specification of XML vocabularies.

The author is a training consultant with Macresource Computer Training, a UK IT training company offering XML Classes in London and throughout the UK.

Using Looping Syntax In XSLT

 

Extensible Stylesheet Language (XSL) is an XML-related technology which is used to transform XML data. XML file are used to set the ground-rules for a given body of data and to describe the data itself. XSL allows us to take that data and convert it into information which can be displayed in a web browser window or opened with a text editor. It can also be used to create an XML file which is a modified version of an original XML file.

When displaying XML elements in a browser window, the XSL elements which enable looping through an XML tree and decision-making really come into their own. One of the key methods used in XSL for looping through elements in an XML file is the the “For-each” element. This requires the “select” attribute to specify which element is to be used in the loop. The “For-each” element normally requires both an opening and a closing tag and any lines of markup placed between the opening and closing tags will be repeated each time the element specified in the “select” attribute is encountered in the XML file.

For example, let’s say we have an XML file containing a list of companies and the addresses of their websites. Let’s also say that the element which we will be targeting in the XSL “For-each” statement is called “company” and that, within each company element, we have a “name”, “telephone” and “website” element. Before beginning our “For-each” loop, we could place the opening tag of an HTML “ul” element (an unordered or bulleted list).

Inside the “For-each” loop, we could output an HTML “li” element and, between the opening and closing tag, output the contents of the “name” and “telephone” elements from the XML file. The data in the “website” could be used to convert the “name” into a clickable link.

As for the appearance of the data in the resulting HTML output, this would be controlled by a linked CSS file. CSS can be used to format the output in any way we like, so our bulleted list can take on pretty much any appearance we desire.

The author is a training consultant with Macresource Computer Training, an independent computer training company offering XML, XSLT, XPATH, XQuery and XSL-FO training courses at their central London training centre.

XML Offers Neutral And Platform Independent Encapsulation Of Your Data

 

Extensible Mark-up Language (XML) has quickly established itself as a viable technology with a huge range of real-world applications. One of the key reasons for its importance and wide acceptance is that it offers a working solution to one of the key problems faced by software developers and computer users alike: the exchange of incompatible data. Each software environment produces its own unique type of binary file which only it can understand. Once data is exported in XML format, it becomes a known quantity, independent of the environment in which it was originated.

The PDF format is another example of a platform-independent format which has gained worldwide acceptance. Once a document is saved in PDF format, its format is set in stone, it can viewed and printed with its layout and formatting intact, without the need for the software which created the original document. However, where the PDF format concerns itself mainly with the presentation of information, XML is used to describe and encapsulate the information itself.

Though XML itself is still fairly new, the idea behind is over thirty years old. In the 1970s, Standard Generalized Markup Language (SGML) was developed in an attempt to create an application-independent method of describing and storing data. SGML is a text-based language which relies on the concept of adding mark-up to data which describes the data itself. An SGML document contains both the original data and a lexicon of rules defining the structure of that data. SGML is a fairly complex language and, unlike XML, has never gained wide popularity. In the early 1990s, SGML was used to develop and specify the rules of HyperText Markup Language (HTML) and in the late 1990s, SGML was again called upon, this time as the basis for the creation of XML. In a lot of ways XML is basically a restricted form of SGML.

XML has already proved itself an excellent medium for storing, describing and transporting data, particularly over the web. It offers flexibility, clarity and simplicity. An XML document looks similar to an HTML document and consists of the same human-readable tags. However, the tags used to markup an HTML document are pre-defined: only a limited set of tags can legitimately be used. XML allows you to create a markup language and define the tags which are legitimate for your data. It does this using a schema document, which can itself be an XML document. The schema document specifies the vocabulary and grammar which may be used within the XML document which contains your data.

The fact that, when creating and generating XML documents, you can invent all the rules, means that you never have to force your data into a container which was not designed to hold it. You design tags which reflect the nature of your data; you create a schema document which defines the hierarchical structure of your information; and you specify the type of information each element within your document is permitted to contain. In short, if you end up with an XML documents which is unsuitable for holding your information, you have only yourself to blame!

Author’s company runs public courses in web design 3.5 in London and throughout the UK.

Overview of XML Technologies

 

Core XML

Extensible Markup Language (XML) is a specification by the Worldwide Web Consortium (W3C) for creating markup languages such as XHTML. The XML specification is being used in an increasingly wide range of applications for exchanging data between different environments, platforms and media. One of the main reasons for its rapidly growing popularity is its flexibility. It allows developers to define their own hierarchy of tags which reflect the structure of their data. In addition to the core XML specification, a number of other technologies have been developed for working with XML projects.

XML Schema

Closely linked with XML documents, we have XML schema. XML schema documents and schema languages are used to validate and document XML markup languages. They allow developers to explicitly lay down the syntactical and structural ground rules for particular classes of XML documents. A number of schema languages have been developed but perhaps the two most important are those defined by the W3C: Document Type Definition (DTD) which was built into the original XML specification and the more XML schema language developed a few years later.

XSL, XSLT AND XSL-FO

XML also offers technologies for transforming XML documents. Extensible Stylesheet language (XSL) comprises two parts: XSL Transformations (XSLT) and XSL Formatting Objects (XSL-FO). XSLT stylesheets are essentially XML documents which transform a given class of XML document (referred to as the source tree) into a different class of XML document (referred to as the output tree). XSLT documents can be compared to CSS documents but are much more powerful. XSL-FO documents are written in XML and control the formatting layout in an output document in a very detailed manner. It allows the definition of layout masters from which are derived page sequences for generating the final document pages. Flow objects are then used to bind data to the various regions of pages.

XPath, XLink, XPointer and XQuery

XPath, XML Linking Language (XLink), and XML Pointer Language (XPointer) are all provide solutions for linking and addressing when working with XML documents. XPath is a declarative language which uses expressions that resemble the directory paths used to describe locations in computer file systems. XPath expressions are used in XSLT documents to address specific nodes within the hierarchy of the XML source document.

XLink is essentially a method of creating hyperlinks within XML documents. It overcomes some of the limitations of the hyperlinks used in XHTML, such as the fact that each hyperlink has only one source and one destination. XPointer allows you to create links which point to very specific points within the hierarchy of an XML document by including XPath expressions in its syntax. XQuery is designed to query XML data in much the same way that SQL is used to query databases. It uses XPath expressions to extract elements and attributes within the structure of an XML document.

Author is a developer and trainer with Macresource Computer Training, a UK IT training company offering XML training courses in London and throughout the UK.