Download XML and CSS: Understanding XML Tree Structure and Styling with XML and XSLT and more Lecture notes Web Application Development in PDF only on Docsity!
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT XML TECHNOLOGIES 3.1 Introduction to XML 3.. 2 XML structure – Elements - Well-formed XML - XML Namespaces 3.3 Working with DTD - Adding DTDs to documents
- 4 Defining DTD entities - Defining Parameter entities 3.5 Working with attributes - Defining attributes - Defining multiple attributes - Using predefined attributes
- 6 CSS basics - Adding CSS to document
- 7 Need of XSL - XSL basics - XSL transformations
- 8 Introduction to Schemas - Defining simple elements and types 3.9 XML query. 3.1 Introduction to XML What is xml? XML stands for e X tensible M arkup L anguage. XML is designed to transport and store data. XML is important to know, and very easy to learn. XML is a markup language much like HTML. XML was designed to carry data, not to display data. XML tags are not predefined. You must define your own tags. XML is designed to be self-descriptive. XML is a W3C Recommendation. The Difference Between XML and HTML XML (^) HTML XML was designed to transport and store data HTML was designed to display data With focus on what data is With focus on how data looks How Can XML be Used? XML Separates Data from HTML XML Simplifies Data Sharing XML Simplifies Data Transport XML Simplifies Platform Changes XML Makes Your Data More Available XML is Used to Create New Internet Languages
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT XML Tree XML documents form a tree structure that starts at "the root" and branches to "the leaves". XML Documents Form a Tree Structure XML documents must contain a root element. This element is "the parent" of all other elements The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree. Syntax: ..... Example:
Tove Jani Reminder Don't forget me this weekend! The terms parent, child, and sibling are used to describe the relationships between elements. Parent elements have children. Children on the same level are called siblings
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT XML Rules All XML Elements Must Have a Closing Tag XML Tags are Case Sensitive XML Elements Must be Properly Nested XML Documents Must Have a Root Element XML Attribute Values Must be Quoted Character and Entity References Comments in XML White-space is Preserved in XML 3.2 XML Elements An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can contain other elements, simple text or a mixture of both. Elements can also have attributes
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT <book category=“Prog"> JAVA James Gosling 2005 RS. 500.00 In the example above, and have element contents , because they contain other elements. has text content because it contains text. In the example above only has an attribute (category=“Prog"). XML Naming Rules XML elements must follow these naming rules: Names can contain letters, numbers, and other characters Names cannot start with a number or punctuation character Names cannot start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces Any name can be used, no words are reserved Best Naming Practices Make names descriptive. Names with an underscore separator are nice <first_name>, <last_name>. Names should be short and simple, <book_title> Avoid "-" characters, Avoid "." characters, Avoid ":" characters
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT Example for XML element female Anna Smith Avoid XML Attributes Some of the problems with using attributes are: Attributes cannot contain multiple values (elements can) Attributes cannot contain tree structures (elements can) Attributes are not easily expandable (for future changes) Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data. Well Formed XML Documents XML with correct syntax is "Well Formed" XML. XML validated against a DTD is "Valid" XML. A "Well Formed" XML document has correct XML syntax XML documents must have a root element XML elements must have a closing tag XML tags are case sensitive XML elements must be properly nested XML attribute values must be quoted
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT Xml namespaces XML Namespaces provide a method to avoid element name conflicts. Name Conflicts In XML, element names are defined by the developer. This often results in a conflict when trying to mix XML documents from different XML applications This XML carries HTML table information:
This XML carries information about a table (a piece of furniture):
African Coffee Table 80 120
If these XML fragments were added together, there would be a name conflict. Both contain a
element, but the elements have different content and meaning. An XML parser will not know how to handle these differences DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT </h:table> <f:table xmlns:f="http://www.w3schools.com/furniture"> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> Namespaces can be declared in the elements where they are used or in the XML root element: <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> Uniform Resource Identifier (URI) A Uniform Resource Identifier (URI) is a string of characters which identifies an Internet Resource. The most common URI is the Uniform Resource Locator (URL) which identifies an Internet domain address. Another, not so common type of URI is the Universal
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT Resource Name (URN) 3 .3 Introduction to DTD A Document Type Definition (DTD) defines the legal building blocks of an XML document It defines the document structure with a list of legal elements and attributes. The purpose of a DTD is to define the structure of an XML document Types Internal DTD External DTD Internal DTD Declaration The DTD is declared inside the XML file It should be wrapped in a DOCTYPE definition Syntax
**Example** ]> Tove Jani Reminder Don't forget me this weekend DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT The file "note.dtd" which contains the DTD
With a DTD, each of your XML files can carry a description of its own format. With a DTD, independent groups of people can agree to use a standard DTD for interchanging data. Your application can use a standard DTD to verify that the data you receive from the outside world is valid. You can also use a DTD to verify your own data. **3.4 Defining DTD entities - Defining Parameter entities ENTITY** ENTITYs are used to reference data that act as an abbreviation or can be found at an external location. The first character of an ENTITY value must be a letter, '_', or ':'. Example ]> DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT ENTITIES Allows multiple ENTITY names separated by whitespace. Example:
**3.5 Working with attributes - Defining attributes - Defining multiple attributes - Using predefined attributes** Attributes are additional information associated with an element type They are intended for interpretation by an application. The ATTLIST declarations identify which element types may have attributes, what type of attributes they may be, and what the default value of the attributes are. DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT Default Value: Description: #REQUIRED The attribute must always be included. #IMPLIED The attribute does not have to be included. The attribute must always have the default value that is specified. If the attribute #FIXED "Default_Value" is not physically added to the element tag in the XML document, the XML processor will behave as though the default value does exist. Attribute types There are three main attribute types. 1.A string type 2.A tokenized types 3.A enumerated types 1.A string type:- CDATA :- CDATA stands for character data, that is, text that does not form markup. Example:
]> DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT
2. Tokenized Attribute Type ID :- ID is a unique identifier of the attribute. IDs of a particular value should not appear more than once in an XML document. An element type may only have one ID attribute. An ID attribute can only have an #IMPLIED or #REQUIRED default value. The first character of an ID value must be a letter, '', or ':'. Example ]> <student_name student_no="a9216735">Jo Smith</student_name> IDREF IDREF is used to establish connections between elements. The IDREF value of the attribute must refer to an ID value declared elsewhere in the document. The first character of an ID value must be a letter, '', or ':'. Example: ]> <lab_group> <student_name student_no="a8904885">Alex Foo</student_name> <student_name student_no="a9011133">Sarah Bar</student_name>
DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT Example:-
]> Some VRML instructions
**Enumerated** Enumerated attribute types allow you to make a choice between different attribute values. The first character of an Enumerated value must be a letter, digit, '.', '-', '_', or ':'. Example ]> Or 3.6 CSS basics - Adding CSS to document What is CSS? CSS stands for Cascading Style Sheets Most popular way of formatting HTML files so that they can be easily maintained and updated CSS also well supported method of formatting XML document for web browsers DEPARTMENT OF INFORMATION TECHNOLOGY COURSE MATERIAL SUBJECT NAME: INTERNET PROGRAMMING UNIT – III SUBJECT CODE : SIT Basic CSS statement For creating style sheet, Identify the specific rules and values for each element’s available properties Syntax : Example: Selector { property : value} Selector is the element identifier Property is the name of one of the predefined CSS properties. Value is one of the predefined value types for specific property. company { background.color:LIGHTBLUE; font.size:12pt; }