Professional Documents
Culture Documents
XML Tutorial
I/ What is XML?
XML is a markup language for documents containing structured information. Structured information contains both content :
. words, pictures, etc. . some indication of what role that content plays. For example : content in a section heading has a different meaning from content in a footnote, which means something different than content in a figure caption or content in a database table, etc.
A markup language is a mechanism to identify structures in a document. The XML specification defines a standard way to add markup to documents.
All of the semantics of an XML document will either be defined by the applications that process them or by stylesheets.
Why XML?
XML was created so that richly structured documents could be used over the web. HTML, as we've already discussed, comes bound with a set of semantics and does not provide arbitrary structure. SGML provides arbitrary structure, but is too difficult to implement just for a web browser. In many organizations, filtering SGML to XML will be the standard procedure for web delivery.
3. XML shall be compatible with SGML. 4. It shall be easy to write programs that process XML documents. 5. The number of optional features in XML is to be kept to an absolute minimum, ideally zero.
Elements
Elements are the most common form of markup. Delimited by angle brackets <>
<Person> <FirstName>Janet</FirstName> <Middle>Q</Middle> <LastName>Leverling</LastName> <Address> <Address1>123 Elm</Address1> <Address2></Address2> <City>Pleasantville</City> <State>MA</State> <Zip>12345</Zip> </Address> </Person>
Attributes
Attributes are name-value pairs that occur inside start-tags after the element name.
<Person ID=0001> <FirstName>Janet</FirstName> <Middle>Q</Middle> <LastName>Leverling</LastName> <Address> <Address1>123 Elm</Address1> <Address2></Address2> <City>Pleasantville</City> <State>MA</State> <Zip>12345</Zip> </Address> </Person>
Entity References
Entities are used to represent these special characters.
< produces the left angle bracket, < > produces the right angle bracket, > & produces the ampersand, & ' produces a single quote character (an apostrophe), ' " produces a double quote character, "
It can be used to insert arbitrary Unicode characters into your document, ex : ℚ
Comments
Comments begin with <!-- and end with -->. Comments can contain any data except the literal string --. Comments are not part of the textual content of an XML document.
Example : <!-- This is a comment -->
Processing Instructions
Processing instructions (PIs) are an escape hatch to provide information to an application. Like comments, they are not textually part of the XML document, but the XML processor is required to pass them to an application. Processing instructions have the form: <?name pidata?>.
Example : <?xml-stylesheet type="text/css" href="cd_catalog.css"?>
CDATA Sections
In a document, a CDATA section instructs the parser to ignore most markup characters. Consider a source code listing in an XML document.
<![CDATA[ *p = &q; b = (i <= 3); ]]>
Between the start of the section, <![CDATA[ and the end of the section, ]]>, all character data is passed directly to the application, without interpretation.
<!ENTITY % personcontent "#PCDATA | quote"> <!ELEMENT burns (%personcontent;)*> <!ELEMENT allen (%personcontent;)*>
Notation Declarations
Notation declarations identify specific types of external binary data. This information is passed to the processing application, which may make whatever use of it it wishes.
<!NOTATION GIF87A SYSTEM "GIF">
Validity
Given the preceding discussion of type declarations, it follows that some documents are valid and some are not. There are two categories of XML documents: well-formed and valid.
Well-formed Documents : A document can only be wellformed if it obeys the syntax of XML. A document that includes sequences of markup characters that cannot be parsed or are invalid cannot be well-formed. If a document is not well-formed, it is not XML. Valid Documents : A well-formed document is valid only if it contains a proper document type declaration and if the document obeys the constraints of that declaration (element sequence and nesting is valid, required attributes are provided, attribute values are of the correct type, etc.).
Validity
It must meet all of the following conditions
1. 2. The document instance must conform to the grammar of XML documents. The replacement text for all parameter entities referenced inside a markup declaration consists of zero or more complete markup declarations. No attribute may appear more than once on the same starttag. String attribute values cannot contain references to external entities. Non-empty tags must be properly nested. Parameter entities must be declared before they are used. All entities except the following: amp, lt, gt, apos, and quot must be declared. A binary entity cannot be referenced in the flow of content, it can only be used in an attribute declared as ENTITY or ENTITIES. Neither text nor parameter entities are allowed to be recursive, directly or indirectly.
3. 4. 5. 6. 7. 8.
9.
XLink
XLink introduce a standard linking model for XML. A link expresses a relationship between resources. A resource is any location (an element, or its content, or some part of its content, for example) that is addressed in a link. The exact nature of the relationship between resources depends on both the application that processes the link and semantic information supplied.
Simple Links
<link xml:link="simple" href="locator">Link Text</link>
A Simple Link identifies a link between two resources, one of which is the content of the linking element itself. This is an in-line link. The locator identifies the other resource. The locator may be a URL, a query, or an Extended Pointer.
Extended Links
Extended Links allow you to express relationships between more than two resources:
<elink xml:link="extended" role="annotation"> <locator xml:link="locator" href="text.loc">The Text </locator> <locator xml:link="locator" href="annot1.loc">Annotations </locator> <locator xml:link="locator" href="annot2.loc"> More Annotations</locator> <locator xml:link="locator" href="litcrit.loc"> Literary Criticism</locator> </elink>
This example shows how the relationships between a literary work, annotations, and literary criticism of that work might be expressed. Note that this link is separate from all of the resources involved.
Mapping process
Adding an XSD file to an Excel workbook Once you add the XSD file, Excel creates an XML map in the XML Source task pane Excel also uses this map to manage the relationship between those mapped ranges and the elements in the XML schema. Excel also uses this map to manage the relationship between those mapped ranges and the elements in the XML schema.
A workbook can contain many XML maps where each map is an independent entity. Likewise, you can also have multiple maps refer to the same schema. When you import or export XML data, Excel uses the map to relate the contents of a mapped range to elements in the schema.
Example
Cascading Order
What style will be used when there is more than one style specified for an HTML element? Generally speaking we can say that all the styles will "cascade" into a new "virtual" Style Sheet by the following rules, where number four has the highest priority:
Browser default External Style Sheet Internal Style Sheet (inside the <head> tag) Inline Style (inside HTML element)
Syntax
The CSS syntax is made up of three parts: a selector, a property and a value:
selector {property: value}
The property and value are separated by a colon and surrounded by curly braces:
body {color: black}
If you wish to specify more than one property, you must separate each property with a semi-colon.
p {text-align:center;color:red}
Syntax (2)
To make the style definitions more readable, you can describe one property on each line, like this:
P { text-align: center; color: black; font-family: arial }
Syntax (3)
The class Selector : With the class selector you can define different styles for the same type of HTML element.
p.right {text-align: right} p.center {text-align: center}
<p class="right"> This paragraph will be right-aligned. </p> <p class="center"> This paragraph will be center-aligned. </p>
CSS Comments
You can insert comments in CSS to explain your code, which can help you when you edit the source code at a later date. A comment will be ignored by the browser. A CSS comment begins with "/*", and ends with "*/", like this:
/* This is a comment */ p { text-align: center; /* This is another comment */ color: black; font-family: arial }
Example-1.css:
h1 {font-size: 36pt} h2 {color: blue} p {margin-left: 50px}
url, none
top left, top center, top right, center left, center center, center right, bottom left, bottom center, bottom right, x-% y-%, x-pos yRepeat, repeat-x, repeat-y, norepeat
pos
backgroundrepeat Sets if/how a background image will be repeated
font-family font-size
font-size-adjust font-stretch
border-bottom border-bottom-color border-bottom-style border-bottom-width border-color border-left border-left-color border-left-style border-left-width border-right border-right-color border-right-style border-right-width border-style
border-top
margin-bottom
margin-left
margin-right
margin-top
Sets the right padding of length an element % Sets the top padding of an element length %
marker-offset
cursor
url, auto, crosshair, default, pointer, move, eresize, ne-resize, nw-resize, n-resize, se-resize, sw-resize, s-resize, w-resize, text, wait, help None,inline, block, list-item, run-in, compact, marker, table, inline-table, table-row-group, tableheader-group, table-footer-group, table-row, table-column-group, table-column, table-cell, table-caption Left, right, none Static, relative, absolute, fixed
display
float position
Sets where an image or a text will appear in another element Places an element in a static, relative or fixed position Sets if an element should be visible or invisible
visibility
verticalalign
Baseline, sub, super, top, text-top, middle, bottom, text-bottom, length, % Auto, number
z-index
CSS Pseudo-classes
Pseudo-classes are used in CSS to add different effects to some selectors, or to a part of some selectors.
Pseudo- NN IE classes active hover link visited :firstchild :lang 7.1 4.0 4.0 7.0 4.0 4.0 3.0 3.0 W3C CSS1 CSS1 CSS1 CSS1 CSS2 CSS2 Purpose Adds special style to a selected link Adds special style to a link when you mouse over it Adds special style to an unvisited link Adds special style to a visited link Adds special style to an element that is the first child of some other element Allows the author to specify a language to use in a specified element
XSL
XSL stands for eXtensible Stylesheet Language. The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML based Stylesheet Language. CSS - HTML Style Sheets :
HTML uses predefined tags and the meanings of tags are well understood. The <table> element defines a table and a browser knows how to display it. Adding styles to HTML elements is also simple. Telling a browser to display an element in a special font or color, is easily done with CSS.
XSL
XSL stands for eXtensible Stylesheet Language. The World Wide Web Consortium (W3C) started to develop XSL because there was a need for an XML based Stylesheet Language. CSS - HTML Style Sheets :
HTML uses predefined tags and the meanings of tags are well understood. The <table> element defines a table and a browser knows how to display it. Adding styles to HTML elements is also simple. Telling a browser to display an element in a special font or color, is easily done with CSS.
StyleSheets
Layout in HTML
XSL Transformations
XML
XML
XSL Transformation
Plain Text
WML
HTML
SGML
XML Deployment
System to System Application to Application Client to Server
e-Commerce e-Commerce
XSLT Transformation
Formatting Process
Resultant Document
Or :
<xsl:transform version="1.0"xmlns:xsl= "http://www.w3.org/1999/XSL/Transform">
Legal filter operators are: = (equal) != (not equal) < less than > greater than
A JavaScript Solution
A more versatile solution would be to use a JavaScript to do the XML to XHTML transformation. By using JavaScript, we can: do browser-specific testing use different style sheets according to browser and user needs One of the design goals for XSLT was to make it possible to transform data from one format to another, supporting different browsers and different user needs.
5.0
6.0
include
6.0
6.0
6.0 6.0
XSLT Functions
Here is the source code needed to transform the XML file to XHTML on the server:
Name current() document() elementavailable() formatnumber() functionavailable() generateid() key() systemproperty() unparsedentity-uri() Description Returns the current node Used to access the nodes in an external XML document Tests whether the element specified is supported by the XSLT processor Converts a number into a string Tests whether the function specified is supported by the XSLT processor Returns a string value that uniquely identifies a specified node Returns a node-set using the index specified by an <xsl:key> element Returns the value of the system properties Returns the URI of an unparsed entity