XML
Fast Start
Smart Brain Training Solutions
Copyright 2014 Smart Brain Training Solutions
All rights reserved.
Thank you for purchasing XML Fast Start ! We hope youll look for other Fast Start guides from Smart Brain Training Solutions.
Table of Contents
1. Introduction
XML, or eXtensible Markup Language, is a programming language that can be used to describe other languages and a specification for storing information. Although XML and HTML may seem to have a lot in common, in reality the difference between them is like the difference between night and day. HTML is used to format information, but it isnt very useful when it comes to describing information. For example, you can use HTML to format a table, but you cant use HTML to describe the data elements within the table. The reason for this is that you cant really depict something as abstract as a distributor or a customer with HTML, which is where XML comes into the picture. XML can be, and is, used to define the structure of data rather than its format.
What makes XML so powerful is that any type of dataeven abstract data conceptscan be given form and structure. You give data conceptssuch as distributor, purchase order, and inventoryform by describing their components and the relationship between those components. Instead of the abstract concept of a distributor, you have a specified structure that describes the distributor-related information, such as distributor name, contact name, and address.
You could define the structure of an inventory item handled by the distributor with components such as item number, name, description, unit cost, and suggested retail price.
XML gets this power and versatility from SGML, but it does so without the complexities that make SGML difficult to implement and use on the Web. With this solution, you get the best aspects of SGML without the overhead, which makes XML practical for transmission and use in cyberspace. A key difference between XML and other similar technologies is that XML is used to define the structure of data rather than its format. This means you can use XML to describe the individual data components in a document. For example, using XML you could define the structure of an employee record with components such as employee ID number, full name, contact information, and position within the company. These components could then be further broken down to their basic level.
Although XML can give data structure, you cant use XML to detail how the content is to be rendered. To do this, you have to rely on another technology to format the information. One way to format XML data structures is to combine them with HTML. Here, you create so-called XML islands within standard HTML documents. You use HTML to format the contents of the document, including the data, and you use XML to define the structure of the data. Another formatting solution for XML is to create a style sheet detailing how each piece of the data structure should be formatted. Although a special style sheet language called Extensible Stylesheet Language (XSL) is designed specifically for this purpose, you could also use the cascading style sheet language.
Generally, XML-only documents end with the .xml extension. You can use this extension to tell the application reading the document that it contains XML data. To interpret the data structures within the document, the application relies on an XML processor. Two general types of XML processors are used: those that validate documents and those that dont. A validating XML processor checks the structure of documents; a nonvalidating XML processor doesnt.
Note In practice, XML-only documents created for Web browser display should end with the .xml extension. If youre developing for a different environment, the extension doesn't really matter. The XML parser classes that you use to interpret the document dont need the extension. However, for consistency, its best to use the .xml extension for files that contain XML. This ensures that other developers (including yourself at a later date) know what the files contain.
Most XML processors are implemented as extension modules for existing applications. In this context, the XML processor is used within the application to extract information from the XML document and display it in an application window. This window could be in your Web browser or in a stand-alone application.
XML processors are also implemented in programming languages like Java and C#. Here, you use the processor classes to help you extract information from an XML document and display it in an application or applet window.
Tip Another name for a processor is a parser. Not only are there XML parsers, but there are XSL parsers as well. XSL parsers are used to process style sheet definitions in XML documents and render the documents according to those definitions.
2. Using XML
Using XML is a lot easier than you might think. Thats because with XML youre in control. Unlike HTML, XML doesnt rely on predefined tags and attributes. This allows you to structure the data in an XML document anyway you like. You define the tags for components within the document. You add attributes to these tags as necessary, and you decide how the components fit together.
The general set of rules for a documents tags and attributes is defined in a document type definition (DTD). XML processors can use the DTD to determine if the document is constructed properly and the processor can pass this information along to the application rendering the document. Keep in mind that documents don't have to have DTDs. However, if they do have a DTD, they should be structured to conform to the DTD.
Once the DTD for a particular type of data is created, you can use the DTD either by inserting it directly into the document, or by referencing the DTD so that it can be imported into the document by the XML processor. Next, you need to create the body of the XML document. There are several ways to do this, and the method you choose depends primarily on how the data is used.
If youre working with fixed data records that change infrequently, you may want to create the necessary data structures using an authoring tool. Here, you insert the data directly into a document and save the result to a file so that it can be viewed directly in an application or compatible browser. You could then publish the document on the Web where others could access it. When you need to update the document, youd load the document into the authoring tools editor, make the necessary changes, and then publish the updated document.
If youre working with data that changes frequently, you probably need a more dynamic solution, and rather than creating static documents you could create documents on the fly. To do this, youd use a document publishing or content management system. These systems are usually integrated with a database. The database stores data records so they can be retrieved on demand. The management system reads in the data and converts it to the appropriate structure based on the DTD and then passes this data off to an application or browser for viewing. Users accessing the dynamic document dont know all this is happening in the background, and they can still access the document using a Uniform Resource Locator (URL).
Extensions to XML
As with most Web technologies, the XML specification is only a starting point. The specification describes XMLs core functionality, such as how XML documents are to be defined, and the necessary grammar that enables documents to comply with this definition.
Beyond the core language, several extensions have been defined, including XML Linking Language, XML Pointer Language, Extensible Stylesheet Language (XSL), XML Namespaces, and XML Schema. These technologies are direct extensions of XML that are defined in XML.
Next page