e X tensible M arkup L anguage P repared b y A ditya R aj e X tensible S tylesheet L anguage
By end of this presentation, we will be able to know What is XML? Why to choose XML? What is XML schema? XML structure Basics of XML coding
What is XML? XML is a general purpose, cross platform, markup language, that is supported by W3C (World Wide Consortium) and is used for communication between systems on different or same platform. XML is used to describe and store data and should not be misunderstood with a programming language. The good news is XML tags are not predefined and you can define your own tags
Why to choose XML? XML stores the data in a structured manner Data can just not be stored but also it can be described to any extent Systems using XML are considered to be highly scalable Structural changes to data can be managed easily Easy to learn and easy to use In machine and human readable format XML is FREE
What is a XML schema? XML Schema are guidelines or format for describing data using XML. In order to use XML data it must conform to these standards. The oldest schema format for XML is DTD (Document Type Definition) but it is now obsolete as: It has no support for new features Certain aspects of data cannot be described using DTD XSD (XML Schema Definition) is one of the most powerful XML schemas and is commonly used. They allow detailed constraints on an XML document’s logical structure. Finally it depends on the system requirement and data type that which XML schema should be used.
XML structure Data Structure of XML can best described as a hierarchy of information like a tree. A hierarchy structure has a parent, child and a sibling relationship with other entities. In XML every entity at any level can have its own properties. Siblings Parent Child Name Age Gender Properties
Basic XML coding <addressBook> <contact fName="john" lName="“ nickName="Johny" dob="1st January 1990"> </contact> <email>email@example.com</email> <numbers> </numbers> <address> </address> <streetAddress>123, x block, Vasant Vihar </streetAddress> <country>India</country> <state>New Delhi</state> <zipCode>110057</zipCode> <mobile>9988998899</mobile> <mobile>9988998800</mobile> <homeNumber>01126150000</homeNumber> <?xml version="1.0" encoding="ISO-8859-1"?> </addressBook> Address Book Contact Email Numbers Address Mobile Home Phone State Country Street Address Contact Email Numbers Address Mobile Home Phone State Country Street Address
Now we are about to know: What is XSL? What is XSLT? What is XPath? Example
What is XSL?
XSL is developed by W3C to facilitate need of style sheet to display formatted information stored in XML like CSS is there for HTML.
XSL is like a tripod supported by three legs called:
XSLT (eXtensible Stylesheet Language Transformation)
XPath (XML Path Language)
XSL-FO (eXtensible Stylesheet Language Formatting Objects)
XSL is classified under two operations, formatting and transformation. XSLT describes the transformation of XSL and XSL-FO is used for formatting but practically they are same .
What is XSLT? XSLT (eXtensible Stylesheet Language Transformation) transforms XML data using XSL to form a well formatted document, usually HTML. About XSLT processors One of the most simplest way of XSLT is client side, so when a XML document is requested by client application, it refers to its related XSL file and the transformation takes place at the client side. This method is not recommended due to compatibility concerns as it is highly possible that client might not support XML transformation or may not support the latest features. Hence it is recommended to perform the transformation at the server level and pass the resulted data to the client, avoiding any compatibility concerns. There are several standalone software and libraries available for performing transformation. Like for ruby on rails we have library named XSLT and for Windows XP we have MSXML 3.
What is XPath? XPath (XML Path Language) is used to navigate the data inside XML document to find required information and it is also used for computing values, in simple words XPath is a small query language . XPath expressions Selects first child element of the node nodename/node Selects all nodes in the document //* Selects all child nodes of the node nodename/* Selects attributes @ Selects the parent of the current node .. Selects the current node . Selects nodes in the document from the current node that match the selection no matter where they are // Selects from the root node / Selects all child nodes of the node nodename Description Expression
Now lets make XSL for the XML we made before !! Line 2 tells the XML document that which XSL should be used for transformation. FINALLY !!