DTD: Document Type Definition. It is a document or file that describes the structure of a Web page written in XML. The description of the structure and the rules a SGML or XML document must satisfy. The DTD comprises the formal declaration of the elements that make up a document, their mutual coherence and meaning. DTD is Document Type Definition. You can store a DTD at the beginning of a document or externally in a separate file.

XML file + DTD file->Parser-> Yes or No

DTD states what tags and attributes are used to describe content in an SGML, XML or HTML document, where each tag is allowed, and which tags can appear within other tags. For example, in a Document Type Definition one could say that LIST tags can contain ITEM tags, but ITEM tags cannot contain LIST tags. If an XML document has an associated document type definition and if the document complies with the constraints expressed in it, it is valid XML document. The document type definition must appear before the first element in the document. The name following the word DOCTYPE in the document type definition must match the name of root element. A Document Type Definition provides applications with advance notice of what names and structures can be used in a particular document type. Why we need a DTD XML is a language specification. Based on this specification, individuals and organizations develop their own markup languages, which they then use to communicate information with. When this information is transferred from source to destination, the destination: * Needs to know how the document is structured and * Needs to check if the content is indeed compliant with the structure The Document Type Definition also known as DTD holds information about the structure of an XML document. In this chapter we will understand the important aspects of DTDs.

Why Use a DTD? •A single DTD ensures a common format for each XML document that references it. •An application can use a standard DTD to verify that data that it receives from the outside world is valid •A description of legal, valid data further contributes to the interoperability and efficiency of using XML DTDs let you say: •What element types can occur and where •What attributes each element type can have •What notations are in use •What external entities can be referenced

DTD can be declared inline in the XML document, or as an external reference. Two types of document type declaration • Internal DOCTYPE declaration • External DOCTYPE declaration

Internal DOCTYPE declaration If the DTD is included in an XML source file, it should be wrapped in a DOCTYPE definition. After the line you must type Syntax: Example: ]> Sam Ros Reminder Don't forget me this weekend

External DOCTYPE declaration If the DTD is external to the XML source file, it should be wrapped in a DOCTYPE definition. Syntax: Example:This is the same XML document as above, but with an external DTD. Sam Ros Reminder Don't forget me this weekend!

This is a copy of the file "note.dtd" containing the DTD Note: SYSTEM in the DTD declaration can be replaced by PUBLIC if the DTD is available via the Internet. You would then need to have a public name for the DTD in the file. For example, the W3Group uses DTDs for the various markup languages they recommend.

1) What do you mean by DTD? 2) Receiver can verify the content and structure of received XML file with the help of DTD file. Comment on this statement 3) Explain 2 types of DTDs. External doctype and internal doctype DTD Elements

Declaring an Element With an element declaration XML elements are declared in the DTD. An element declaration has the following syntax: or

Example of a DTD (author2.dtd)

Example 1 of XML using this DTD Example of XML not obeying this DTD example

Empty Elements Empty elements are declared with the category keyword EMPTY: example: XML example:
Example of a DTD (author3.dtd) Example 1 of XML using this DTD Example of XML not obeying this DTD example

Elements with only character data Elements with only character data are declared with #PCDATA inside parentheses: example: The description (#PCDATA) stands for parsed character data. It's the tag that is shown and also will be parsed (interpreted) by the program that reads the XML document. You can also define (#CDATA), this stands for character data. CDATA will not be parsed. Elements with any contents Elements declared with the category keyword ANY, can contain any combination of parsable data: example: “|” means either-or ”,” means succession. EMPTY (without parenthesis) means no contained data.

Example of a DTD (author1.dtd)

Example 1 of XML using this DTD Example of XML not obeying this DTD Margaret Margaret York

Example of a DTD (author.dtd)

Example of XML obeying this DTD Example of XML not obeying this DTD Margaret Margaret York

Number of sub elements If you use , the sub elements brand and type can occur once inside the element car. To change the number of possible occurrences the following indications can be used: If an element name in DTD is followed by • the star [*] - This element can occur zero, once or several times. • the plus [+] - This element can occur once or several times. • the question mark [?] - This element can occur zero or one times. The indications are used behind the sub element name. For instance:

(a*) means that a is repeated 0, 1 or more times. Declaring minimum one occurrence of the same element example The + sign in the example above declares that the child element message must occur one or more times inside the note element. Declaring zero or more occurrences of the same element example 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 example The ? sign in the example above declares that the child element message can occur zero or one times inside the note element.

Example of a DTD (author4.dtd) Example 1 of XML using this DTD Example 1 of XML not satisfies this DTD John Margaret Margaret Eve Eve Peter Peter

(a+) means that a is repeated 1 or more times. Example of a DTD (author5.dtd) Example 1 of XML using this DTD Example 1 of XML using this DTD John John Margaret Margaret Eve Peter

(a?) means that the element a is repeated 0 or 1 times. Example of a DTD (d6.dtd)

Example of XML using this DTD Example of XML not obeying this DTD John John Eve John2 Peter Eve Peter

Example of a DTD Example of XML using this DTD http://cmc.dsv.su.se/file1 http://cmc.dsv.su.se/file2 http://cmc.dsv.su.se/file3 Declaring mixed content Example 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.

4) Explain the uses of symbols ?, *,+ in element definitions in DTD 5) Explain tag 6) Explain the difference between ',' and '|' operators in element definition of DTD 7) Explain keyword EMPTY and ANY

8) Explain with example how we define mixed element in DTD

DTD Attributes

Elements can have zero or more attributes, which are declared using the !ATTLIST tag. Unlike element definitions, attribute definitions do not impose order on when the attributes occur. Furthermore, if several attributes are declared for the same element type, they can be declared using multiple !ATTLIST tags. In the DTD, XML element attributes are declared with an ATTLIST declaration.

Syntax :

DTD Example : XML Example :

Each attribute in a declaration has three parts: a name, a type, and a default value. ATTRIBUTE DEFAULT VALUES

Default Value Description value The default value of the attribute #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 default values can be value, optional (#IMPLIED), required (#REQUIRED), or fixed (#FIXED).

Default attribute value Syntax: DTD example: XML example: 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: DTD example: XML example: Use an implied attribute if you don't want to force the author to include an attribute and you don't have an option for a default value either. Required attribute Syntax: DTD example: XML example: 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: DTD example: XML example: 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. An attribute declaration may specify that an attribute has a fixed value. In this case, the attribute is not required, but if it occurs, it must have the specified value. If it is not present, it will appear to be the specified default. One use for fixed attributes is to associate semantics with an element. Example of a DTD Example 1 of XML using this DTD title CDATA #REQUIRED >

ATTRIBUTE TYPE Attributes can have these types: CDATA, Enumerated attribute value, ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, ENTITY, ENTITIES, NOTATION

CDATA CDATA attributes are strings, any text is allowed. Don't confuse CDATA attributes with CDATA sections. Enumerated attribute values Syntax: DTD example: XML example: or Use enumerated attribute values when you want the attribute values to be one of a fixed set of legal values.

ID The value of an ID attribute must be a name. All of the ID values used in a document must be different. IDs uniquely identify individual elements in a document. Elements can have only a single ID attribute.

IDREF The IDREF type allows the value of one attribute to be an element elsewhere in the document provided that the value of the IDREF is the ID value of the referenced element. A validating parser verifies that no two elements have the same ID value. Thus the attribute can be used as a key of the element. Other elements can then have IDREF attributes (defined in a DTD) that “reference” an element by its ID attribute. Note that a validating parser makes sure that all IDREF attributes refer to an existing ID attribute in the XML document. XML example: Margaret Yorke ... False Pretences is based on the DTD: The disadvantages are that the ID values are not restricted to an element . That is, an ID attribute has to be unique in an XML document regardless of the element in which it is defined. This is troublesome because if an XML document includes a student element and a course element, both with their own ID attribute, then the id (or key) of a student cannot be the same of the id of a course. This issue has to be considered when designing the DTD and the understanding of the id in elements that contain it. Another disadvantage is that the semantics of an ID/IDREF cannot be formally specified. For example, a student element with an IDREF attribute that is intended to be a relationship to a course id cannot be specified in the DTD rules. A validating parser only validates that an IDREF has a value for an id that exists within the document, it cannot validate that such value has to exist “in a specific element”. That is, the following basic rule cannot be specified in the DTD: the value for the attribute “takes” of a student element refers to an id of an existing course element. IDREFS The value is a list of other ids. An IDREF attribute's value must be the value of a single ID attribute on some element in the document. The value of an IDREFS attribute may contain multiple IDREF values separated by white space.

ENTITY or ENTITYS An ENTITY attribute's value must be the name of a single entity . The value of an ENTITIES attribute may contain multiple entity names separated by white space. Values of type ENTITY must match the Name production, values of type ENTITIES must match Names; each Name must match the name of an unparsed entity declared in the DTD. ...

NMTOKEN or NMTOKENS “NMTOKEN” implying that the value must conform to XML identifier name specifications. Name token attributes are a restricted form of string attribute. In general, an NMTOKEN attribute must consist of a single word. But there are no additional constraints on the word; it doesn't have to match another attribute or declaration. The value of an NMTOKENS attribute may contain multiple NMTOKEN values separated by white space. The characters of an NMTOKEN value must be a letter, digit, '.', '-', '_', or ':'. It may not include white space. example: Jo Smith

example: Jo Smith

Notation Type specifies that the names must match a particular notation name. 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. A typical notation declaration is: tag is used to define a notation in DTD. Here GIF87A mp and st are notation.

Example: Attribute player of sound tag can store only the names of defined notation.

Figure 2. A short bibliography in XML. This example demonstrates the use of attributes as well as referencing using the id and idref attributes. Aho, A. V. Sethi, R. Ullman, J. D. Compilers: Principles, Techniques, and Tools Addison-Wesley 1985 Principles of Database and Knowledge-Base Systems, Vol.1 ...

Figure 3. A DTD for the bibliography example. The DTD defines a grammar for documents.

]> Weaknesses of the DTD:

• DTD has a limited capability for specifying data types • DTD requires its own language, Not in XML syntax • DTD provides incompatible set of data types with those found in databases. e.g. “PCDATA,” “CDATA” • Example: DTD do not allow to specify element day and month of Type Integer and within a certain Range: 3213 • Do not support XML namespace • Not expressed in XML syntax - can’t process them using XML tools (such as parsers)

XML Schemas Overcome most Limitations of DTD 9) Richer capabilities than a DTD 1. Describes the possible arrangement of tags and text in a valid document 2. 44+ datatypes (as opposed to 10 in DTDs) 3. Allows attribute grouping 4. Supports use of namespaces 5. Supports object-oriented design 1. “Custom” data types can be derived from other data types and inherit their attributes * 6. Can specify element constraints and valid values XML Schema “Limitations” 10) Not all developers and standards bodies use Schema the same way 1. There are at least 20 ways to declare attributes 1. From local attribute with default value to global attribute with fixed value 2. At least 15 ways to declare elements 1. From local element with default value to global element with complex type 3. At least three different ways to identify hierarchy of namespaces 1. XMLSchema is the default 2. targetNamespace is the default 3. No namespace is default

ENTITIES An entity is a symbolic representation of information. What does that mean? Well, let's imagine for a moment that we wanted to create an introduction that is included in every single memo that we write. It would be monotonous to have to type out a three-sentence introduction for every letter, but not to worry, XML entities can help us out. With symbolic representation of information, a lot of text, such as, "Hello my name is Tizag.com and I am an artificial intelligence that teaches the general public how to program in web languages for free" can be represented by an entity symbol. Creating an XML Entity An entity must be created in the Document Type Definition (DTD). When you know where to place the entity, the rest is easy. Here is the syntax for creating your own XML entities.

Below we have created an entity for the default introduction we want to include on all of our documents. After the entity has been created in the DTD it can then be referenced. An example email XML document that uses such an entity would look like: XML Code: A. Nony Mouse &intro; Entity Declaration Entities can be declared internal, or external 11) Entities as variables used to define shortcuts to common text. 12) Entity references are references to entities. 13) Entities can be declared internal. 14) Entities can be declared external Internal Entity Declaration An internal entity is defined completely inside the XML document that references it (the document itself is an entity in XML). Syntax: DTD Example: XML example: &writer;©right; The XML specification predefines five internal entities: • < 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, "

External Entity Declaration External entities derive their content from an external source such as a file. References to external entities include URI (uniform resource identifier) at which they can be found. External entities associate a name with the content of another file. External entities allow an XML document to refer to the contents of another file. External entities contain either text or binary data. If they contain text, the content of the external file is inserted at the point of reference and parsed as part of the referring document. Binary data is not parsed and may only be referenced in an attribute. Binary data is used to reference figures and other non-XML content in the document. Syntax: DTD Example: XML example: &writer;©right; Parameter Entities Parameter entities can only occur in the document type declaration. A parameter entity declaration is identified by placing % (percent-space) in front of its name in the declaration. The percent sign is also used in references to parameter entities, instead of the ampersand. Parameter entity references are immediately expanded in the document type declaration and their replacement text is part of the declaration, whereas normal entity references are not expanded. Parameter entities are not recognized in the body of a document. At the moment, these two elements are the same only because they happen to have the same literal definition. In order to make more explicit the fact that these two elements are semantically the same, use a parameter entity to define their content model. The advantage of using a parameter entity is two-fold. First, it allows you to give a descriptive name to the content, and second it allows you to change the content model in only a single place, if you wish to update the element declarations, assuring that they always stay the same:

Example:

DATA ISLAND When HTML is used to display data, the data is stored inside your HTML. With XML, data can be stored in separate XML files. This way you can concentrate on using HTML for data layout and display, and be sure that changes in the underlying data will not require any changes to your HTML. XML data can also be stored inside HTML pages as "Data Islands". You can still concentrate on using HTML only for formatting and displaying the data.

• Embed XML Data in HTML • Bind Data Island to HTML Elements

Embed XML Data in HTML An XML data island is XML data embedded into an HTML page. Here is how it works; assume we have the following XML document ("note.xml"): Tove Jani Reminder Don't forget me this weekend! Then, in an HTML file, you can embed the XML file above with the tag. The id attribute of the tag defines an ID for the data island, and the src attribute points to the XML file to embed: However, the embedded XML data is, up to this point, not visible for the user. The next step is to format and display the data in the data island by binding it to HTML elements. This data island itself is useless when embedded in an HTML document. In fact, unless you choose to view the page’s source, you don’t even know that the data island is there. Bind Data Island to HTML Elements Let content of f1.xml is Whiskers Spot Bubbles

An XML data island is XML surrounded by tags in a HTML document. Here's an example of an XML data island: In order to bind this data to HTML elements, you must specify the DATASRC and DATAFLD attributes on those elements. The following code demonstrates how to bind the "cat" field to an element:

The "#" preceding the XML data island ID in the DATASRC attribute must be present in order to bind the data. When the page loads, the value of the will be "Whiskers". cd_catalog.xml Empire Burlesque Bob Dylan Hide your heartBonnie Tyler Greatest Hits Dolly Parton f1.html

ArtistTitle
This is my CD collection

Output of f1.html file Artist Title Bob Dylan Empire Burlesque Bonnie Tyler Hide your heart Dolly Parton Greatest Hits This is my CD collection

Example explained: The datasrc attribute of the

tag binds the HTML table element to the XML data island. The datasrc attribute refers to the id attribute of the data island. OUTPUT Title Artist Empire Bob Burles Dylan

Example showing how the content of XML file is displayed in the form of unordered list A1.xml List of Items Important to Markup Languages Languages SGML XML HTML Other Support DTD DSSSL Style Sheets xmlstyle.xsl




output List of Items Important to Markup Languages Languages

. SGML . XML . HTML

Other Support

• DTD • DSSSL • Style Sheets xsl:value-of Although using XSL to print out static messages is fun to play around with, using an XML document's elements and their contents is probably more useful in real world use. This section will teach you how to get the value of elements and attributes in an XML document using the xsl:value-of element.

XML Code: Jack Harry Rebecca Mr. Bean XSL - Element Values Our XSL code has been outputting "Found a learner!" for each student element found. Let's replace that string with the student's actual name, by using xsl:value-of to get the element's contents. XSL Code:

xsl:value-of uses the select attribute to choose elements. Because we are already at the correct element, student, we use a period "." to select the current element's data. The period is a special character to use when you want to select the same element that you matched with template's match attribute. If you were outputting the XSL to a file, this is what the output would look like. XSL Output:(is output of this HTML file)

Jack

Harry

Rebecca

XSL - Attribute Values xsl:value-of can also be used to retrieve the value of attributes of XML elements. We have slightly modified our XML document to include an id attribute, XML Code: Jack Harry Rebecca Mr. Bean Let's output each student's id number before their name to make a nice list. To select an attribute use the at sign "@" followed by the name of the attribute. XSL Code :

-

The XSL output is shown below: XSL Output: 1 - Jack 2 - Harry

1 - Jack

3 - Rebecca

2 - Harry

3 - Rebecca

Xml file Belgian Waffles $5.95 two of our famous Belgian Waffles 650 Simple.xsl. < html> [ ], ( calories per serving) Output [Belgian Waffles$5.95 ], two of our famous Belgian Waffles ( 650 calories per serving)

1) Explain how we can display the content of an XML file using XSL 2) Explain , and tags 3) Explain the basics of XSL language 4) Write the differnce between and 5) Explain how XML documents can be embedded into HTML document. 6) Briefly explain XSL style sheets. 7) Describe in detail the principles of displaying XML Data in HTML browser as HTML tables.

Explain the process of converting XML to HTML with XSL minimalist

XML Editors

The basic job of an XML editor is to help you, to create and manipulate XML documents. The basic features you need are syntax highlighting (color codes the XML to make it easier to read), some sort of way to validate the XML code that you write, and of course, the ability to create, edit, and save XML documents. There are many free XML editors available for download, on the Internet. Here are a few we have found useful: XML Cooktop, XML Mind Standard Editio, Pete's XML Editor Purchasable XML Editors If you are looking for a more professional solution and have the money ($50-$600) then you will want to purchase one of the following XML editors. XML Spy. XML Mind Professional Edition. Xmetal. XML is a text-based . One great thing about XML is that XML files can be created and edited using a simple text-editor like Notepad. However, when you start working with XML, you will soon find that it is better to edit XML documents using a professional XML editor. Why Not Notepad? Many web developers use Notepad to edit both HTML and XML documents because Notepad is included with the most common OS and it is simple to use. But, if you use Notepad for XML editing, you will soon run into problems. Notepad does not know that you are writing XML, so it will not be able to assist you. You will need an intelligent XML editor!

Professional XML editors will help you to write error-free XML documents, validate your XML against a DTD or a schema, and force you to stick to a valid XML structure. An XML editor should be able to: 20) Add closing tags to your opening tags automatically 21) Force you to write valid XML 22) Verify your XML against a DTD 23) Verify your XML against a Schema 24) Color code your XML syntax • Easy to use • Context-sensitive entry helpers

XPath As you know, XML was created to be a self-describing markup format. As XML matured, new XML related creations were popping up. Although you could create a nicely structured document with XML, there didn't seem to be an easy way to find information inside the document. XML documents can be thought of as a Tree Structure, made up of parent, child, and sibling relationships. Because of this very logical layout of an XML document it seems like there should be a standard way to find information. XPath - Finding Information XPath is the solution to finding information in an XML document. XPath uses expressions to find elements, attributes, and other information in your XML. If you had an XML document that contained a bunch of your favorite books, each with author children elements, you could use a one line XPath expression to find all the authors of your favorite books! XPath - Used in XSLT The most common place people might see XPath expressions are in XSLT(Extensible Stylesheet Language Transformation). XPath - Absolute Location Up to this point we have been selecting elements by giving the full path. We start with the the root element and end with the desired descendant element. This method of using the complete path is referred to as absolute location path and is useful for selecting a specific element. There is another method, relative location path, which is useful when you want to select many similar items (more on this later). This lesson will provide an overview of absolute location paths in XPath.

XML Code, lemonade2.xml: $2.50 20 $1.50 10 $4.50 60 180 XPath - Start with the Root Element When you are using the absolute method, your expression must start with the root element of your XML document (inventory in our example). If you only wanted to select the root element, then you're done. XPath Expression: inventory However, if you wanted one of the sub-elements, like lemonade, then you will have to create a string of children elements from the root node to the desired node. XPath Expression: inventory/drink/lemonade XPath - Attribute You have already learned how to select any element in an XML document, but how would you get that element's attribute? Those attributes values are within your reach once you learn how to use @ !

XPath - @ is for Attribute!

After you have figured out how to select an element in your XML document, just take it one step further to get the attribute. At the end of your XPath expression, which is normally the element you want to select, add the at sign "@" plus the name of the attribute you wish to select. The following XPath expression selects chips element. XPath Expression: inventory/snack/chips If we wanted to select the supplier attribute of chips we would add "@supplier" to our expression. XPath Expression: inventory/snack/chips@supplier If we wanted to select the supplier attribute of pop the XPath expression would have to be changed slightly. XPath Expression: inventory/drink/pop@supplier

XML Parser To read and update, create and manipulate an XML document, you will need an XML parser. Two types of parsers are well formed XML parser and valid XML parser. well formed XML parser checks whether a given XML document is well formed or not. valid XML parser checks whether a given XL document satisfies rules specified in the given DTD, that means valid XML parser checks whether given XML document is valid or not.

Xml file+DTD file->Valid XML parser-> yes or no output

Parsing XML Documents To manipulate an XML document, you need an XML parser. The parser loads the document into your computer's memory. Once the document is loaded, its data can be manipulated using the DOM. The DOM treats the XML document as a tree.

Microsoft's XML Parser Microsoft's XML parser is a COM component that comes with Internet Explorer 5 and higher. Once you have installed Internet Explorer, the parser is available to scripts. Microsoft's XML parser 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. An XML parser is a piece of code that reads a document and analyzes its structure. Kinds of parsers There are several different ways to categorize parsers: • Validating versus non-validating parsers • Parsers that support the Document Object Model (DOM) • Parsers that support the Simple API for XML (SAX) • Parsers written in a particular language (Java, C++, Perl, etc.) Validating versus non-validating parsers XML documents that use a DTD and follow the rules defined in that DTD are called valid documents. XML documents that follow the basic tagging rules are called well-formed documents. The XML specification requires all parsers to report errors when they find that a document is not well formed. Validation, however, is a different issue. Validating parsers validate XML documents as they parse them. Non-validating parsers ignore any validation errors. In other words, if an XML document is well-formed, a non-validating parser doesn’t care if the document follows the rules specified in its DTD (if any). Why use a non-validating parser? Speed and efficiency. It takes a significant amount of effort for an XML parser to process a DTD and make sure that every element in an XML document follows the rules of the DTD. If you’re sure that an XML document is valid (maybe it was generated by a trusted source), there’s no point in validating it again. Also, there may be times when all you care about is finding the XML tags in a document. Once you have the tags, you can extract the data from them and process it in some way. If that’s all you need to do, a non-validating parser is the right choice. The Document Object Model (DOM) The Document Object Model is an official recommendation of the World Wide Web Consortium (W3C). It defines an interface that enables programs to access and update the style, structure, and contents of XML documents. XML parsers that support the DOM implement that interface. When you parse an XML document with a DOM parser, you get back a tree structure that contains all of the elements of your document. The DOM provides a variety of functions you can use to examine the contents and structure of the document. XML Namespace XML was designed to be a very robust markup language that could be used in many different applications. However, with XML being able to communicate between so many different platforms, there is one problem that tends to occur. XML Element Overlap When you are creating new elements, there is the chance that the element's name already exists. XML Namespaces provide a method to avoid element name conflicts. Imagine someone was creating a health related XML document. XML Code:

Welcome to my Health Resource

6ft 155 lbs

Here we have two very different elements that want to use the same name: body. The solution to this problem is to create XML Namespaces, which will differentiate between these two similarly named elements! XML Namespace Syntax The XML namespace is a special type of XML attribute that you place in an XML tag. The attribute is actually more like a prefix that you attach to any namespace you create. This attribute prefix is "xmlns:", which stands for XML NameSpace. The colon is used to separate the prefix from your namespace that you are creating. xmlns must have a unique value that not other namespace in the document has. What is most commonly used is the URI (Uniform Resource Identifier) or the more commonly used URL. To rectify the overlap in our health XML document we will be using the W3C's XHTML URL and a made up URI for our second body element. XML Code: Welcome to my Health Resource

6ft 155 lbs

By placing a namespace prefix before our elements we have solved the overlapping problem! Name Conflicts Since element names in XML are not predefined, a name conflict will occur when two different documents use the same element names. This XML document carries information in a table:

tags cannot be bound to data, so we are using tags. The tag allows the datafld attribute to refer to the XML element to be displayed. In this case, it is datafld="ARTIST" for the element and datafld="TITLE" for the element in the XML file. As the XML is read, additional rows are created for each <CD> element If you are running IE 5.0 or higher, you can try it yourself.</p><p>A1.xml <?xml version="1.0" encoding="ISO-8859-1"?> <root> <data> <cat>Whiskers</cat><dog>Spot</dog> <fish>Bubbles</fish> </data> <data> <cat>Whiskers1</cat><dog>Spot1</dog><fish>Bubbles1</fish></data> <data> <cat>Whiskers2</cat><dog>Spot2</dog><fish>Bubbles2</fish></data> </root> html1.html <html><body> <html> <xml id="cdact1" src="a1.xml"></xml> <body> <table border="1" datasrc="#cdact1"> <xml id="cdact" src="a1.xml"></xml> <tr> <input type="text" datasrc="#cdact" datafld="cat"> <td><span datafld="cat"></span></td> </body> </tr> </html> </table> </body></html> output Output Whiskers Whiskers1 Whiskers2</p><p>15) define DATAISLAND 16) How can you display content of an XML file in table format? 17) Write an XML document that stores some tabular data. Write on HTML page that displays the above XML data XSL</p><p>In some ways, XSL (eXtensible Style Language) is to XML as CSS is to HTML. XSL provides a mechanism to specify how to render (display) the elements of an XML file. XSL goes beyond CSS in that it also provides mechanisms to choose & manipulate XML data. XSL transforms the XML data to another file format (html). Creating an XSL file Open a text document (notepad) type XSL instructions in that file. Save that file with .Xsl extension like f2.xsl</p><p>Example for an XSL file is given below <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> * page code here * </xsl:template> </xsl:stylesheet></p><p>The style sheet (XSL file) begins with an XML declaration and <xsl:stylesheet > tag XSL - XML Declaration You should include an XML declaration at the top of your XSL documents. The attribute version defines what version of XML you are using. <?xml version="1.0" ?></p><p>XSL - Stylesheet Root Element Every XSL file must have the root element xsl:stylesheet . This root element has two attributes that must be included:</p><p>• version - the version of XSL • xmlns:xsl - the XSL namespace, which is a URI to w3.org. That may be http://www.w3.org/1999/XSL/Transform OR http://www.w3.org/TR/WD-xsl</p><p><?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"></p><p></xsl:stylesheet></p><p>Importing XSL file into an XML file</p><p> xml-stylesheet xml-stylesheet is a special declaration in XML for linking XML with stylesheets. Place this after your XML declaration to link your XML file to your XSL code. xml-stylesheet has two attributes:</p><p>18) type: the type of file being linked to. We will be using the value text/xsl to specify XSL. 19) href: the location of the file. If you saved your XSL and XML file in the same directory, you can simply use the XSL filename. Let the following xml file is saved as classs.xml. In this Xml file we imported one XSL file class.xsl. Make sure that both your XSL and XML file are in the same directory. If we open class.xml file using notepad content will be displayed as given below. If we open class.xml file using Internet Explorer content of the xml file will be displayed according to the instructions given in the Xsl file.</p><p><?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="class.xsl"?> <class> <student>Jack</student> <student>Harry</student> <student>Rebecca</student> <teacher>Mr. Bean</teacher> </class> Save this XML file as class.xml and your XML file will be linked to your XSL file. After you have finished this step you can continue learning XSL!</p><p>Working of XSL The purpose of XSL is to take an XML document and transform it into something new. To transform an XML document, XSL must be able to do two things well:</p><p>• Find information in the XML document • Add additional text and/or data</p><p>Both of these items are taken care of with the very important XSL element xsl:template. xsl:template Match Attribute of xsl:template To find information in an XML document you will need to use xsl:template's match attribute. It is in this attribute that you use your knowledge of XPath to find information in your XML document. We will be using above class.xml as our example XML document.</p><p>If we wanted to find student elements we would set the match attribute to a simple XPath expression: student. Every time we find a student let's print something out. The text we want printed must go between the opening and closing tags of <xsl:template>. Let's have it print out "Found a learner!" The following XSL code will find student elements in the XML and output "Found a learner!" for each student element. <?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="student"> Found a learner! </xsl:template> </xsl:stylesheet></p><p>Save this file as class.xsl. Then open class.xml. You can see the output given below. This simple XSL does not work in Firefox because the output is not well-formed XML. However, Internet Explorer 6.0+ will view it just fine. XSL Output: Found a learner! Found a learner! Found a learner! Mr. Bean </p><p>Our XML document had three students and one teacher, so our XSL printed out "Found a learner!" three times, followed by the unmatched teacher element's text "Mr. Bean". In a later lesson we will show you how to filter out the unwanted text "Mr. Bean". xsl:apply-templates</p><p>The file a2.xml given below uses stylesheet manager1.xsl for displaying the content of it. By changing the content of manager1.xsl different outputs will get. Outputs for different manager1.xsl files are given below. A2.xml</p><p><?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="manager1.xsl"?> <company> <name>Asme</name> <manager> <name>phil</name> <title>Chief james officer manager1.xsl

output Chief phil hai officer james

hai

output Chief phil

output officer james

Asme Chiefphil

officerjames

Output blank

To display the content of file a3.xml in table format, we can use XSL (we can use the file s2.xsl given below to display the content of a3.xml in table format.) A3.xml Empire Bob Burles Dylan s2.xsl

Title Artist
S2.XSL
TitleArtist

Apples Bananas
This XML document carries information about a table (a piece of furniture): African Coffee Table80120
If these two XML documents were added together, there would be an element name conflict because both documents contain a element with different content and definition Solving Name Conflicts Using a Prefix This XML document carries information in a table:

Apples Bananas This XML document carries information about a piece of furniture African Coffee Table 80 120 Now there will be no name conflict because the two documents use a different name for their

element ( and ). By using a prefix, we have created two different types of
elements.

Using Namespaces This XML document carries information in a table: Apples Bananas This XML document carries information about a piece of furniture: African Coffee Table 80 120 Instead of using only prefixes, we have added an xmlns attribute to the

tag to give the prefix a qualified name associated with a namespace. The XML Namespace (xmlns) Attribute The XML namespace attribute is placed in the start tag of an element and has the following syntax: xmlns:namespace-prefix="namespaceURI" When a namespace is defined in the start tag of an element, all child elements with the same prefix are associated with the same namespace. Note that the address used to identify the namespace is not used by the parser to look up information. The only purpose is to give the namespace a unique name. However, very often companies use the namespace as a pointer to a real Web page containing information about the namespace.

1) Write a note on XML parser. 2) What is Namespace? 3) What is an XPath 4) What are the features f XML editor XML Application

With XML, your data is stored outside your HTML. When HTML is used to display data, the data is stored inside your HTML. With XML, data can be stored in separate XML files. This way you can concentrate on using HTML for data layout and display, and be sure that changes in the underlying data will not require any changes to your HTML. XML data can also be stored inside HTML pages as "Data Islands". You can still concentrate on using HTML only for formatting and displaying the data. With XML, data can be exchanged between incompatible systems. 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 many different types of applications. With XML, financial information can be exchanged over the Internet. Expect to see a lot about XML and B2B (Business To Business) in the near future. XML is going to be the main language for exchanging financial information between businesses over the Internet. A lot of interesting B2B applications are under development. With XML, plain text files can be used to share data. Since XML data is stored in plain text format, XML provides a software- and hardware-independent way of sharing data. This makes it much easier to create data that different applications can work with. It also makes it easier to expand or upgrade a system to new operating systems, servers, applications, and new browsers. With XML, plain text files can be used to store data. XML can also be used to store data in files or in databases. Applications can be written to store and retrieve information from the store, and generic applications can be used to display the data. With XML, your data is available to more users. Since XML is independent of hardware, software and application, you can make your data available to other than only standard HTML browsers. Other clients and applications can access your XML files as data sources, like they are accessing databases. Your data can be made available to all kinds of "reading machines" (agents), and it is easier to make your data available for blind people, or people with other disabilities. XML is the mother of WAP and WML. The (WML), used to markup Internet applications for handheld devices like mobile phones, is written in XML.

If they DO have sense, all future applications will exchange their data in XML. The future might give us word processors, spreadsheet applications and databases that can read each other's data in a pure text format, without any conversion utilities in between. Enable Smart Searches One major problem with today's web is that search engines can't process HTML intelligently. For example, if you search on "chip" when you're looking for someone named Chip, you might get pages on chocolate chips, computer chips, and guys named Chip. But if there were a DTD for name and address records, searching for a guy named Chip could generate much more accurate and useful search results. Enable Smart Agents When writing an agent, one of the challenges is to make sense of incoming data. A good agent interprets information intelligently, then responds to it accordingly. If the data sent to an agent is structured with XML, it's much easier for the agent to understand exactly what the data means and how it relates to other pieces of data it may already know. Enable Business to Business Communication When using XML, I can receive XML-tagged data from your system, and you can receive XMLtagged data from mine. Neither of us has to know how the other's system is organized. If another partner or supplier teams up with my organization, I don't have to write code to exchange data with their system. I simply require them to follow the document rules defined in the DTD.

As an example the Math(s) Markup Language (MathML) [1] is an XML application which became a W3C Recommendation recently. Although most browsers do not yet support MML, a number of Java and ActiveX applications have been developed which can display MML documents. The use of Java and ActiveX to render XML applications is another way of deploying XML with the current generation of browsers. A paper [2] at the WWW 7 conference suggested Java applets known as displets as a way of rendering XML documents. An example is illustrated in Figure 4. You can download the Java application yourself, together with some example applications from . What other applications are available? A number of XML applications have already been developed including: CDF (Channel Definition Format) The Channel Definition Format is an XML application which has been developed by Microsoft and submitted to the W3C. CML () The Chemical Markup Language, developed by Peter Murray-Rust, Nottingham University. PGML (Precision Graphics Markup Language) A proposed 2D imaging model in XML of the PostScript language and the Portable Document Format (PDF). RDF (Resource Description Framework) A framework for describing metadata applications. OSD (Open Software Description) A suggested XML application for automated distribution and updating software. SMIL (Synchronized Multimedia Integration Language) An XML application which enables independent multimedia objects to be integrated into a synchronized multimedia presentation. SMIL is a proposed W3C Recommendation.