What is XM1

19
Internet Programming and Tools - Assignment Name : R.karthikeyan PROGRAMME: M.TECH (CSE) Topic : XML

Transcript of What is XM1

Page 1: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 1/19

Internet Programming and Tools - Assignment

Name : R.karthikeyan

PROGRAMME: M.TECH (CSE)

Topic : XML

Page 2: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 2/19

What is XML?

• XML stands for EXtensible Markup Language

• XML is a markup language much like HTML.

• XML was designed to describe data. 

• XML tags are not predefined in XML. You must define your own tags.• XML is self describing.

• XML uses a DTD (Document Type Definition) to formally describe the data.

The main difference between XML and HTML

XML is not a replacement for HTML. XML and HTML were designed with different goals:

XML was designed to describe data and to focus on what data is. HTML was designed to

display data and to focus on how data looks. HTML is about displaying information, XML is

about describing information.

XML is extensible

The tags used to markup HTML documents and the structure of HTML documents are

predefined. The author of HTML documents can only use tags that are defined in the HTML

standard. XML allows the author to define his own tags and his own document structure.

XML is a complement to HTML

It is important to understand that XML is not a replacement for HTML. In the future

development of the Web it is most likely that XML will be used to structure and describe theWeb data, while HTML will be used to format and display the same data.

XML Syntax - An example XML document:<?xml version="1.0"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

The first line in the document: The XML declaration should always be included. It defines the

XML version of the document. In this case the document conforms to the 1.0 specification of XML:

<?xml version="1.0"?>

The next line defines the first element of the document (the root element):

Page 3: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 3/19

<note>

The next lines defines 4 child elements of the root (to, from, heading, and body):

<to>Tove</to>

<from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body>

The last line defines the end of the root element:

</note>

All XML elements must have a closing tag

In HTML some elements do not have to have a closing tag. The following code is legal inHTML:

<p>This is a paragraph<p>This is another paragraph

In XML all elements must have a closing tag like this:

<p>This is a paragraph</p><p>This is another paragraph</p>

XML tags are case sensitive

XML tags are case sensitive. The tag <Letter> is different from the tag <letter>. Opening and

closing tags must therefore be written with the same case:

<Message>This is incorrect</message>

<message>This is correct</message>

All XML elements must be properly nestedIn HTML some elements can be improperly nested within each other like this:

<b><i>This text is bold and italic</b></i>

In XML all elements must be properly nested within each other like this

Page 4: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 4/19

<b><i>This text is bold and italic</i></b>

All XML documents must have a root tag

All XML documents must contain a single tag pair to define the root element. All other elementsmust be nested within the root element. All elements can have sub (children) elements. Sub

elements must be in pairs and correctly nested within their parent element:

<root><child><subchild></subchild>

</child></root>

Attribute values must always be quoted

XML elements can have attributes in name/value pairs just like in HTML. In XML the attributevalue must always be quoted. Study the two XML documents below. The first one is incorrect,

the second is correct:

<?xml version="1.0"?><note date=12/11/99><to>Tove</to><from>Jani</from><heading>Reminder</heading>

<body>Don't forget me this weekend!</body></note>

<?xml version="1.0"?><note date="12/11/99"><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

How can XML be used?• XML can keep data separated from your HTML

• XML can be used to store data inside HTML documents

• XML can be used as a format to exchange information

• XML can be used to store data in files or in databases

XML can keep data separated from your HTML

Page 5: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 5/19

HTML pages are used to display data. Data is often stored inside HTML pages. With XML this

data can now be stored in a separate XML file. This way you can concentrate on using HTML

for formatting and display, and be sure that changes in the underlying data will not force changesto any of your HTML code.

XML can also store data inside HTML documents

XML data can also be stored inside HTML pages as "Data Islands". You can still concentrate on

using HTML for formatting and displaying the data.

XML can be used to exchange data

In the real world, computer systems and databases contain data in incompatible formats. One of 

the most time consuming challenges for developers has been to exchange data between such

systems over the Internet. Converting the data to XML can greatly reduce this complexity and

create data that can be read by different types of applications.

XML can be used to store data

XML can also be used to store data in files or in databases. Applications can be written to storeand retrieve information from the store, and generic applications can be used to display the data.

Introduction to DTD

The purpose of a DTD is to define the legal building blocks of an XML document. It defines the

document structure with a list of legal elements. A DTD can be declared inline in your XMLdocument, or as an external reference.

Internal DTD

This is an XML document with a Document Type Definition: (Open it in IE5, and select view

source)

<?xml version="1.0"?><!DOCTYPE note [<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)><!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>

]><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body>

Page 6: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 6/19

</note>

The DTD is interpreted like this:

!ELEMENT note (in line 2) defines the element "note" as having four elements:

"to,from,heading,body".

!ELEMENT to (in line 3) defines the "to" element to be of the type "CDATA".!ELEMENT from (in line 4) defines the "from" element to be of the type "CDATA"

and so on.....

External DTD

This is the same XML document with an external DTD: (Open it in IE5, and select view source)

<?xml version="1.0"?><!DOCTYPE note SYSTEM "note.dtd"><note>

<to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

This is a copy of the file "note.dtd" containing the Document Type Definition:

<?xml version="1.0"?><!ELEMENT note (to,from,heading,body)><!ELEMENT to (#PCDATA)><!ELEMENT from (#PCDATA)>

<!ELEMENT heading (#PCDATA)><!ELEMENT body (#PCDATA)>

Why use a DTD?

XML provides an application independent way of sharing data. With a DTD, independent groups

of people can agree to use a common DTD for interchanging data. Your application can use a

standard DTD to verify that data that you receive from the outside world is valid. You can also

use a DTD to verify your own data.

DTD – Elements - Declaring an Element

In the DTD, XML elements are declared with an element declaration. An element declaration has

the following syntax:

Page 7: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 7/19

<!ELEMENT element-name (element-content)>

Empty elements

Empty elements are declared with the keyword EMPTY inside the parentheses:

<!ELEMENT element-name (EMPTY)>example:<!ELEMENT img (EMPTY)>

Elements with data

Elements with data are declared with the data type inside parentheses:

<!ELEMENT element-name (#CDATA)>

or<!ELEMENT element-name (#PCDATA)>or<!ELEMENT element-name (ANY)>example:<!ELEMENT note (#PCDATA)>

#CDATA means the element contains character data that is not supposed to be parsed by a parser.

#PCDATA means that the element contains data that IS going to be parsed by a parser.

The keyword ANY declares an element with any content.

If a #PCDATA section contains elements, these elements must also be declared.

Elements with children (sequences)

Elements with one or more children are defined with the name of the children elements inside the

 parentheses:

<!ELEMENT element-name (child-element-name)>

or<!ELEMENT element-name (child-element-name,child-element-name,.....)>example:<!ELEMENT note (to,from,heading,body)>

When children are declared in a sequence separated by commas, the children must appear in the

same sequence in the document. In a full declaration, the children must also be declared, and the

children can also have children. The full declaration of the note document will be:

Page 8: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 8/19

<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#CDATA)><!ELEMENT from (#CDATA)><!ELEMENT heading (#CDATA)><!ELEMENT body (#CDATA)>

Wrapping

If the DTD is to be included in your XML source file, it should be wrapped in a DOCTYPEdefinition with the following syntax:

<!DOCTYPE root-element [element-declarations]>example:<?xml version="1.0"?><!DOCTYPE note [<!ELEMENT note (to,from,heading,body)><!ELEMENT to (#CDATA)>

<!ELEMENT from (#CDATA)><!ELEMENT heading (#CDATA)><!ELEMENT body (#CDATA)>

]><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend</body>

</note>

Declaring only one occurrence of the same element

<!ELEMENT element-name (child-name)>example<!ELEMENT note (message)>

The example declaration above declares that the child element message can only occur one time

inside the note element.

Declaring minimum one occurrence of the same element

<!ELEMENT element-name (child-name+)>example<!ELEMENT note (message+)>

The + sign in the example above declares that the child element message must occur one or moretimes inside the note element.

Declaring zero or more occurrences of the same element

Page 9: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 9/19

<!ELEMENT element-name (child-name*)>example<!ELEMENT note (message*)>

The * sign in the example above declares that the child element message can occur zero or more

times inside the note element.

Declaring zero or one occurrences of the same element

<!ELEMENT element-name (child-name?)>example<!ELEMENT note (message?)>

The ? sign in the example above declares that the child element message can occur zero or onetimes inside the note element.

Declaring mixed content

example<!ELEMENT note (to+,from,header,message*,#PCDATA)>

The example above declares that the element note must contain at least one to child element,

exactly one from child element, exactly one header, zero or more message, and some other 

 parsed character data as well. Puh!

DTD – Attributes-Declaring Attributes

In the DTD, XML element attributes are declared with an ATTLIST declaration. An attribute

declaration has the following syntax:

<!ATTLIST element-name attribute-name attribute-type default-value>

As you can see from the syntax above, the ATTLIST declaration defines the element which can

have the attribute, the name of the attribute, the type of the attribute, and the default attribute

value.

The attribute-type can have the following values:

Value Explanation

CDATA The value is character data

(eval|eval|..) The value must be an enumerated value

ID The value is an unique id

IDREF The value is the id of another element

Page 10: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 10/19

IDREFS The value is a list of other ids

NMTOKEN The value is a valid XML name

NMTOKENS The value is a list of valid XML names

ENTITY The value is an entity

ENTITIES The value is a list of entities

NOTATION The value is a name of a notation

xml: The value is predefined

The attribute-default-value can have the following values:

Value Explanation

#DEFAULT value The attribute has a default value

#REQUIRED The attribute value must be included in the element

#IMPLIED The attribute does not have to be included

#FIXED value The attribute value is fixed

Attribute declaration example

DTD example:<!ELEMENT square EMPTY><!ATTLIST square width CDATA "0">

XML example:<square width="100"></square>

In the above example the element square is defined to be an empty element with the attributeswidth of type CDATA. The width attribute has a default value of 0.

Default attribute value

Syntax:<!ATTLIST element-name attribute-name CDATA "default-value">DTD example:<!ATTLIST payment type CDATA "check">XML example:<payment type="check">

Specifying a default value for an attribute, assures that the attribute will get a value even if the

author of the XML document didn't include it.

Implied attribute

Syntax:<!ATTLIST element-name attribute-name attribute-type #IMPLIED>

Page 11: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 11/19

DTD example:<!ATTLIST contact fax CDATA #IMPLIED>XML example:<contact fax="555-667788">

Use an implied attribute if you don't want to force the author to include an attribute and you don'thave an option for a default value either.

Required attribute

Syntax:<!ATTLIST element-name attribute_name attribute-type #REQUIRED>DTD example:<!ATTLIST person number CDATA #REQUIRED>XML example:<person number="5677">

Use a required attribute if you don't have an option for a default value, but still want to force the

attribute to be present.

Fixed attribute value

Syntax:<!ATTLIST element-name attribute-name attribute-type #FIXED "value">DTD example:<!ATTLIST sender company CDATA #FIXED "Microsoft">XML example:<sender company="Microsoft">

Use a fixed attribute value when you want an attribute to have a fixed value without allowing the

author to change it. If an author includes another value, the XML parser will return an error.

Enumerated attribute values

Syntax:<!ATTLIST element-name attribute-name (eval|eval|..) default-value>DTD example:<!ATTLIST payment type (check|cash) "cash">XML example:

<payment type="check">or<payment type="cash">

Use enumerated attribute values when you want the attribute values to be one of a fixed set of 

legal values.

Page 12: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 12/19

DTD - XML building blocks

The building blocks of XML documents

XML documents (and HTML documents) are made up by the following building blocks:Elements, Tags, Attributes, Entities, PCDATA, and CDATA. This is a brief explanation of each

of the building blocks:

Elements

Elements are the main building blocks of both XML and HTML documents. Examples of HTML

elements are "body" and "table". Examples of XML elements could be "note" and "message".

Elements can contain text, other elements, or be empty. Examples of empty HTML elements are"hr", "br" and "img".

Tags

Tags are used to markup elements. A starting tag like <element_name> mark up the beginning of 

an element, and an ending tag like </element_name> mark up the end of an element. Examples:A body element: <body>body text in between</body>. A message element: <message>some

message in between</message>

Attributes

Attributes provide extra information about elements. Attributes are placed inside the start tag of 

an element. Attributes come in name/value pairs. The following "img" element has an additionalinformation about a source file:

<img src="computer.gif" />

The name of the element is "img". The name of the attribute is "src". The value of the attribute is

"computer.gif". Since the element itself is empty it is closed by a " /".

PCDATA

PCDATA means parsed character data. Think of character data as the text found between thestart tag and the end tag of an XML element. PCDATA is text that will be parsed by a parser.

Tags inside the text will be treated as markup and entities will be expanded.

CDATA

CDATA also means character data. CDATA is text that will NOT be parsed by a parser. Tagsinside the text will NOT be treated as markup and entities will not be expanded.

Page 13: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 13/19

Entities

Entities as variables used to define common text. Entity references are references to entities.

Most of you will known the HTML entity reference: "&nbsp;" that is used to insert an extraspace in an HTML document. Entities are expanded when a document is parsed by an XML

 parser.

The following entities are predefined in XML:

Entity References Character

&lt; <

&gt; >

&amp; &

&quot; "

&apos; '

DTD – Entities• Entities as variables used to define shortcuts to common text.

• Entity references are references to entities.

• Entities can be declared internal.

• Entities can be declared external

Internal Entity Declaration

Syntax:<!ENTITY entity-name "entity-value">DTD Example:<!ENTITY writer "Jan Egil Refsnes."><!ENTITY copyright "Copyright XML101.">XML example:<author>&writer;&copyright;</author>

 

External Entity Declaration

Syntax:<!ENTITY entity-name SYSTEM "URI/URL">DTD Example:<!ENTITY writer SYSTEM "http://www.xml101.com/entities/entities.xml"><!ENTITY copyright SYSTEM "http://www.xml101.com/entities/entities.dtd">XML example:<author>&writer;&copyright;</author>

Page 14: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 14/19

DTD - Examples from the Net

TV Scedule DTD

<!DOCTYPE TVSCHEDULE [

<!ELEMENT TVSCHEDULE (CHANNEL+)><!ELEMENT CHANNEL (BANNER, DAY+)><!ELEMENT BANNER (#PCDATA)><!ELEMENT DAY ((DATE, HOLIDAY) | (DATE, PROGRAMSLOT+))+><!ELEMENT HOLIDAY (#PCDATA)><!ELEMENT DATE (#PCDATA)><!ELEMENT PROGRAMSLOT (TIME, TITLE, DESCRIPTION?)><!ELEMENT TIME (#PCDATA)><!ELEMENT TITLE (#PCDATA)>

<!ELEMENT DESCRIPTION (#PCDATA)>

<!ATTLIST TVSCHEDULE NAME CDATA #REQUIRED><!ATTLIST CHANNEL CHAN CDATA #REQUIRED><!ATTLIST PROGRAMSLOT VTR CDATA #IMPLIED><!ATTLIST TITLE RATING CDATA #IMPLIED><!ATTLIST TITLE LANGUAGE CDATA #IMPLIED>

]> 

A Report DTD

<!DOCTYPE REPORT [

<!ELEMENT REPORT (TITLE,(SECTION|SHORTSECT)+)><!ELEMENT SECTION (TITLE,%BODY;,SUBSECTION*)><!ELEMENT SUBSECTION (TITLE,%BODY;,SUBSECTION*)><!ELEMENT SHORTSECT (TITLE,%BODY;)><!ELEMENT TITLE %TEXT;><!ELEMENT PARA %TEXT;><!ELEMENT LIST (ITEM)+><!ELEMENT ITEM (%BLOCK;)><!ELEMENT CODE (#PCDATA)>

<!ELEMENT KEYWORD (#PCDATA)><!ELEMENT EXAMPLE (TITLE?,%BLOCK;)><!ELEMENT GRAPHIC EMPTY>

<!ATTLIST REPORT security (high | medium | low ) "low"><!ATTLIST CODE type CDATA #IMPLIED><!ATTLIST GRAPHIC file ENTITY #REQUIRED>

<!ENTITY xml "Extensible Markup Language">

Page 15: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 15/19

<!ENTITY sgml "Standard Generalized Markup Language"><!ENTITY pxa "Professional XML Authoring"><!ENTITY % TEXT "(#PCDATA|CODE|KEYWORD|QUOTATION)*"><!ENTITY % BLOCK "(PARA|LIST)+"><!ENTITY % BODY "(%BLOCK;|EXAMPLE|NOTE)+">

<!NOTATION GIF SYSTEM ""><!NOTATION JPG SYSTEM ""><!NOTATION BMP SYSTEM "">

]> 

Newspaper Article DTD

<!DOCTYPE NEWSPAPER [

<!ELEMENT NEWSPAPER (ARTICLE+)><!ELEMENT ARTICLE (HEADLINE, BYLINE, LEAD, BODY, NOTES)><!ELEMENT HEADLINE (#PCDATA)><!ELEMENT BYLINE (#PCDATA)><!ELEMENT LEAD (#PCDATA)><!ELEMENT BODY (#PCDATA)><!ELEMENT NOTES (#PCDATA)>

<!ATTLIST ARTICLE AUTHOR CDATA #REQUIRED><!ATTLIST ARTICLE EDITOR CDATA #IMPLIED><!ATTLIST ARTICLE DATE CDATA #IMPLIED><!ATTLIST ARTICLE EDITION CDATA #IMPLIED>

<!ENTITY NEWSPAPER "Vervet Logic Times"><!ENTITY PUBLISHER "Vervet Logic Press"><!ENTITY COPYRIGHT "Copyright 1998 Vervet Logic Press">

]> 

Product Catalog DTD

<!DOCTYPE CATALOG [

<!ELEMENT CATALOG (PRODUCT+)><!ELEMENT PRODUCT (SPECIFICATIONS+, OPTIONS?, PRICE+, NOTES?)><!ELEMENT SPECIFICATIONS (#PCDATA)><!ELEMENT OPTIONS (#PCDATA)><!ELEMENT PRICE (#PCDATA)><!ELEMENT NOTES (#PCDATA)>

Page 16: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 16/19

<!ATTLIST PRODUCT NAME CDATA #IMPLIED><!ATTLIST CATEGORY (HandTool | Table | Shop-Professional) "HandTool"><!ATTLIST PARTNUM CDATA #IMPLIED><!ATTLIST PLANT (Pittsburgh | Milwaukee | Chicago) "Chicago"><!ATTLIST INVENTORY (InStock | Backordered | Discontinued) "InStock">

<!ATTLIST SPECIFICATIONS WEIGHT CDATA #IMPLIED><!ATTLIST POWER CDATA #IMPLIED><!ATTLIST OPTIONS FINISH (Metal | Polished | Matte) "Matte"><!ATTLIST OPTIONS ADAPTER (Included | Optional | NotApplicable) "Included"><!ATTLIST OPTIONS CASE (HardShell | Soft | NotApplicable) "HardShell"><!ATTLIST PRICE MSRP CDATA #IMPLIED><!ATTLIST PRICE WHOLESALE CDATA #IMPLIED><!ATTLIST PRICE STREET CDATA #IMPLIED><!ATTLIST PRICE SHIPPING CDATA #IMPLIED>

<!ENTITY AUTHOR "John Doe"><!ENTITY COMPANY "JD Power Tools, Inc."><!ENTITY EMAIL "[email protected]">

]>

DTD Validation - Validating with the XML Parser 

If you try to open an XML document, the XML Parser might generate an error. By accessing the

 parseError object, the exact error code, the error text, and even the line that caused the error can

 be retrieved:

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

xmlDoc.async="false"xmlDoc.validateOnParse="true"xmlDoc.load("note_dtd_error.xml")document.write("<br>Error Code: ")document.write(xmlDoc.parseError.errorCode)document.write("<br>Error Reason: ")document.write(xmlDoc.parseError.reason)document.write("<br>Error Line: ")document.write(xmlDoc.parseError.line)

Turning Validation off 

Validation can be turned off by setting the XML parser's validateOnParse="false".

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")xmlDoc.async="false"xmlDoc.validateOnParse="false"xmlDoc.load("note_dtd_error.xml")document.write("<br>Error Code: ")document.write(xmlDoc.parseError.errorCode)

Page 17: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 17/19

document.write("<br>Error Reason: ")document.write(xmlDoc.parseError.reason)document.write("<br>Error Line: ")document.write(xmlDoc.parseError.line)

The XML DOM - The Document Object Model

The DOM is a programming interface for HTML and XML documents. It defines the way a

document can be accessed and manipulated. Using a DOM, a programmer can create a

document, navigate its structure, and add, modify, or delete its elements. As a W3Cspecification, one important objective for the DOM has been to provide a standard programming

interface that can be used in a wide variety of environments and applications.

The Node Interface

As you will se in the next section, a program called an XML parser can be used to load an XMLdocument into the memory of your computer. When the document is loaded, it's information can

 be retrieved and manipulated by accessing the Document Object Model (DOM). The DOM

represents a tree view of the XML document. The documentElement is the top-level of the tree.This element has one or many childNodes that represent the branches of the tree. A Node

Interface is used to read and write (or access if you like) the individual elements in the XML

node tree. The childNodes property of the documentElement can be accesses with a for/each

construct to enumerate each individual node. The Microsoft XML parser used to demonstratethe DOM in this Web, supports all the necessary functions to traverse the node tree, access the

nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.

A total of 13 node types are currently supported by the Microsoft XML parser. The followingtable lists the most commonly used node types:

Node Type Example

Document type <!DOCTYPE food SYSTEM "food.dtd">

Processing instruction <?xml version="1.0"?>

Element <drink type="beer">Carlsberg</drink >

Attribute type="beer"

Text Carlsberg

To view the examples in this Web, you have to use Microsoft Internet Explorer 5.0 !

Parsing the DOM - Using the XML parser 

To read and update - create and manipulate - an XML document, you need an XML parser. TheMicrosoft XML parser is a COM component that comes with Microsoft Internet Explorer 5.0.

Page 18: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 18/19

Once you have installed IE 5.0, the parser is available to scripts inside HTML documents and

ASP files. The Microsoft XMLDOM parser features a language-neutral programming model

that:

• Supports JavaScript, VBScript, Perl, VB, Java, C++ and more

Supports W3C XML 1.0 and XML DOM• Supports DTD and validation

If you are using JavaScript in IE 5.0, you can create an XML document object with the followingcode:

var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")

If you are using VBScript you create the XML document object with the following code:

set xmlDoc = CreateObject("Microsoft.XMLDOM")

If you are using VBScript in an Active Server Page (ASP), you can use the following code:

set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")

Loading an XML file into the parser

The following code loads an existing XML document (note.xml) into the XML parser:

<script language="JavaScript">var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")xmlDoc.async="false"xmlDoc.load("note.xml")// ....... processing the document goes here</script>

The first line of the script creates an instance of the Microsoft XML parser. The third line tells

the parser to load an XML document called note.xml. The second line assures that the parser will

halt execution until the document is fully loaded.

Loading pure XML text into the parser

The following code loads a text string into the XML parser:

<script language="JavaScript">var text="<note>"text=text+"<to>Tove</to><from>Jani</from>"text=text+"<heading>Reminder</heading>"

Page 19: What is XM1

7/30/2019 What is XM1

http://slidepdf.com/reader/full/what-is-xm1 19/19

text=text+"<body>Don't forget me this weekend!</body>"text=text+"</note>"var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")xmlDoc.async="false"xmlDoc.loadXML(text)// ....... processing the document goes here

</script>

 Note that the "loadXML" method (instead of the "load" method) is used to load a text string.

Introduction to XSL - XSL - The Style Sheet of XML?

HTML pages uses predefined tags, and the meaning of these tags is well understood: <p> meansa paragraph and <h1> means a header, and the browser knows how to display these pages. With

XML we can use any tags we want, and the meaning of these tags are not automatically

understood by the browser: <table> could mean a HTML table or maybe a piece of furniture.

Because of the nature of XML, there is no standard way to display an XML document. In order 

to display XML documents, it is necessary to have a mechanism to describe how the documentshould be displayed. One of these mechanisms is Cascading Style Sheets (CSS), but XSL

(eXtensible Stylesheet Language) is the preferred style sheet language of XML, and XSL is far more sophisticated than the CSS used by HTML.

XSL - More than a Style Sheet

XSL consists of two parts:

• a method for transforming XML documents

a method for formatting XML documents

If you don't understand the meaning of this, think of XSL as a language that can transform XML into HTML, a language that can filter and sort XML data and a language that can format 

XML data, based on the data value, like displaying negative numbers in red.

XSL - What can it do?

XSL can be used to define how an XML file should be displayed by transforming the XML fileinto a format that is recognizable to a browser. One such format is HTML. Normally XSL does

this by transforming each XML element into an HTML element.

XSL can also add completely new elements into the output file, or remove elements. It canrearrange and sort the elements, test and make decisions about which elements to display, and a

lot more.