Archive

Posts Tagged ‘pdf’

XML And The Benefits Of Platform Independence

February 8th, 2010 Peter H. Spencer No comments

Extensible Mark-up Language (XML) has very quickly established itself as a viable technology with a huge range of real-world applications. One of the main reasons for its importance and wide acceptance is the fact 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 creates its own unique type of binary file which only it can understand. When data is exported in XML format, it becomes a known quantity, independent of the environment in which it was originated.

Adobe’s PDF format is another example of a platform-independent data format which has gained wide acceptance. When a document is saved as a PDF file, 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 file. However, whereas the PDF format concerns itself primarily with the presenting information, XML is used to describe and encapsulate the information itself.

Though XML itself is still fairly new, the idea behind it is not. Back in the 1970s, Standard Generalized Markup Language (SGML) was developed in an attempt to create an application-independent method of describing data. SGML is a text-based language which uses the concept of adding mark-up to data which describes the data itself. An SGML document contains both data and a set of rules defining the structure of the data. SGML is a pretty complex language and, unlike XML, has never become mainstream. In the early 1990s, SGML was used to develop HTML and in the late 1990s, SGML was also used as the basis for the development of XML. So, basically, XML is a restricted form of SGML.

XML has already proved itself to be an excellent medium for storing, describing and transporting data, particularly over the web. It offers developers flexibility, clarity and simplicity. An XML document resembles an HTML document and consists of the same human-readable tags. However, the tags used to markup an HTML document are predetermined: only a fixed set of tags can legitimately be used. XML allows you to create your own markup language and define the tags which are legitimate for your data. It does this via the mechanism of a schema document, which can itself be an XML document. The schema document defines the vocabulary and grammar which may be used within the XML document containing 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!

The writer of this article is part of an organisation that offers web design training courses in London and throughout the UK.

Understanding The For-each Element In XSLT

February 6th, 2010 Keira Albright No comments

Extensible Stylesheet Language (XSL) is an XML technology which is used to transform XML data. XML file can be used to set the ground-rules for a given body of data and to describe the data itself. XSL allows us to take that input XML 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 input XML file.

When displaying 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 XML elements is the “For-each” element. This uses the “select” attribute to specify which element is to be targeted in the loop. The “For-each” element has both an opening and a closing tag and any lines of code 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 input 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, for each company element, we have a “name”, “telephone” and “website” element. Before beginning our “For-each” loop, we could output 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 its opening and closing tags, output the contents of the “name” and “telephone” elements from the XML file. The data in the “website” element in the input XML could be used to convert the “name” into a clickable link.

As to 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 desire, so our bulleted list can take on pretty much any appearance we desire.

The The writer of this article is a trainer and developer with Macresource Computer Training, an independent computer training company offering XML, XSLT, XPATH, XQuery and XSL-FO training courses in London and throughout the UK.