Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.

Similar presentations


Presentation on theme: "Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy."— Presentation transcript:

1 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Textbook to be published by Pearson Ed in early 2014 http://www.funwebdev.com Fundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar © 2015 Pearson http://www.funwebdev.com XML Extensible Markup Language Chapter 17 - 1

2 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML OVERVIEW Section 1 of 7

3 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Overview XML is a text-based markup language, but unlike HTML, XML can be used to mark up any type of data. Derived from Standard Generalized Markup Language SGML One of the key benefits of XML data is that as plain text, it can be read and transferred between applications and different operating systems as well as being human-readable and understandable as well. XML is not only used on the web server and to communicate asynchronously with the browser, but is also used as a data interchange format for moving information between systems Introduction

4 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Overview XML in the web context - Used in many systems

5 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Well Formed XML Syntax Rules For a document to be well-formed XML, it must follow the syntax rules for XML: Element names are composed of any of the valid characters (most punctuation symbols and spaces are not allowed) in XML. Element names can’t start with a number. There must be a single-root element. A root element is one that contains all the other elements; for instance, in an HTML document, the root element is. All elements must have a closing element (or be self-closing). Elements must be properly nested. Elements can contain attributes. Attribute values must always be within quotes. Element and attribute names are case sensitive.

6 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Well Formed XML Sample Document XML declaration is analogous to HTML DOCTYPE

7 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Valid XML Requires a DTD A valid XML document is one that is well formed and whose element and content conform to the rules of either its document type definition (DTD) or its schema. A DTD tells the XML parser which elements and attributes to expect in the document as well as the order and nesting of those elements. A DTD can be defined within an XML document or within an external file.

8 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML parser Verifies that an XML document is well formed. Checks xml document for syntax errors Converts XML document into some type of internal memory structure All contemporary browsers have built-in parsers as do most web development environments such as PHP and ASP.NET Meaning

9 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Data Type Definition Example

10 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Data Type Definition Example The main drawback with DTDs is that they can only validate the existence and ordering of elements. They provide no way to validate the values of attributes or the textual content of elements. For this type of validation, one must instead use XML schemas, which have the added advantage of using XML syntax. Unfortunately, schemas have the corresponding disadvantage of being long-winded and harder for humans to read and comprehend; for this reason, they are typically created with tools.

11 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Schema Just one example

12 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XSLT XML Stylesheet Transformations XSLT is an XML-based programming language that is used for transforming XML into other document formats

13 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XSLT Another usage XSLT is also used on the server side and within JavaScript

14 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XSLT Example XSLT document that converts the XML from Listing 17.1 into an HTML list

15 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XSLT An XML parser is still needed to perform the actual transformation

16 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XPath Another XML Technology XPath is a standardized syntax for searching an XML document and for navigating to elements within the XML document XPath is typically used as part of the programmatic manipulation of an XML document in PHP and other languages XPath uses a syntax that is similar to the one used in most operating systems to access directories.

17 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XPath Learn through example

18 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Textbook to be published by Pearson Ed in early 2014 http://www.funwebdev.com Fundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar © 2015 Pearson http://www.funwebdev.com XML Tutorial http://www.tutorialspoint.com/xml/index.htm

19 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Basics XML tags identify the data and are used to store and organize the data, rather than specifying how to display it like HTML tags XML Characteristics XML is extensible: XML allows you to create your own self-descriptive tags, or language, that suits your application. XML carries the data, does not present it: XML allows you to store the data irrespective of how it will be presented. XML is a public standard: XML was developed by an organization called the World Wide Web Consortium (W3C) and is available as an open standard. Before proceeding with this tutorial you should have basic knowledge of HTML and Javascript. XML Tutorial http://www.tutorialspoint.com/cgi-bin/printpage.cgihttp://www.tutorialspoint.com/cgi-bin/printpage.cgi

20 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Usage XML can work behind the scene to simplify the creation of HTML for large web sites. XML can be used to exchange the information between organizations and systems. XML can be used for offloading and reloading of databases. XML can be used to store and arrange the data, which can customize your data handling needs. XML can easily be merged with style sheets to create almost any desired output. Virtually, any type of data can be expressed as an XML document. Not a programming language it does not perform any computation or algorithms. It is usually stored in a simple text file and is processed by special software that is capable of interpreting XML. list of XML usage

21 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Syntax Hello, world! Tanmay Patil TutorialsPoint (011) 123-4567 Two kinds of information in the above example:  The markup, like and  The text, or the character data, Tutorials Point and (040) 123-4567. Syntax Rules

22 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Declaration The XML declaration is case sensitive and must begin with " " where "xml" is written in lower-case. If document contains XML declaration, then it strictly needs to be the first statement of the XML document. An HTTP protocol can override the value of encoding that you put in the XML declaration. Syntax Rules for Tags and Elements

23 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Syntax Rules for Tags and Elements XML-elements or XML-nodes or XML tags. XML-elements names are enclosed by triangular brackets.. or in simple-cases Nesting of elements: can contain multiple XML-elements as its children, but the children elements must not overlap Elements Which is correct ?

24 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Syntax Rules for Tags and Elements Only one root element Case sensitive ≠ Element attribute (single property); one or more attributes. For example: Tutorialspoint!.... correct? Attribute names are defined without quotation marks, whereas attribute values must always appear in quotation marks.... correct? XML References begin with the "&”and ends with the symbol ";” Entity References: & Character References contains a hash mark (“#”) followed by a number. The number always refers to the Unicode code of a character. In this case, 65 refers to alphabet "A". Root, Attributes, XML References: Entity and Character Which is correct ?

25 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Text XML-elements attributes names are case-sensitive, start and end name need to be written in the same case. To avoid character encoding problems, all XML files should be saved as Unicode UTF-8 or UTF-16 files. Whitespace characters like blanks, tabs and line-breaks between XML-elements and between the XML-attributes will be ignored. Some characters are reserved by the XML syntax. Encoding

26 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Documents Document prolog comes at the top of the document, before the root element. It contains:  XML declaration  Document type declaration Document Elements are the building blocks of XML, a hierarchy of sections, each serving a specific purpose. The elements can be containers, with a combination of text and other elements. Document Prolog and Elements

27 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Declaration XML declaration contains details that prepare an XML processor to parse the XML document. It is optional, but when it is used, it must appear in first line of the XML document.Syntax Syntax

28 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Declaration If present in the XML, it must be placed as the first line in the XML document. If included, it must contain version number attribute. The Parameter names and values are case-sensitive. The names are always in lower case. The order of placing the parameters is important. The correct order is: version, encoding and standalone. Either single or double quotes may be used. The XML declaration has no closing tag i.e. XML declaration with version definition: XML declaration with all parameters defined: XML declaration with all parameters defined in single quotes: Rules

29 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Tags Start Tag End Tag Empty Tag ot may be used for any element which has no content Rules 1.XML tags are case-sensitive This is wrong syntax correct? 2.XML tags must be closed in an appropriate order This tag is closed before the outer_element Definition and Rules

30 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Elements XML elements can be defined as building blocks of an XML. Elements can behave containers to hold text, elements, attributes, media objects or all of these. Each XML document contains one or more elements, the scope of which are delimited by start and end tags, or for empty elements, by an empty-element tag, separated by white spaces It associates a name with a value, which is a string of characters. An attribute is written as: name = "value” double(" ") or single(' ') quotes Empty Element (no content)

31 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Elements Rules An element name can contain any alphanumeric characters. The only punctuation marks allowed in names are the hyphen (-), under-score (_) and period (.). Names are case sensitive. For example, Address, address, and ADDRESS are different names. Start and end tags of an element must be identical. An element, which is a container, can contain text or elements as seen in the above example.

32 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Attributes An element can have multiple unique attributes or properties is always a name-value pair. An XML attribute has following syntax....content.. where attribute1 and attribute2 has the following form: name = "value” Attributes are used to add a unique label to an element, place the label in a category, add a Boolean flag, or otherwise associate it with some string of data. Attributes are part of the XML elements, Syntax Two categories of plants, one flowers and other color. Hence we have two plant elements with different attributes.

33 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Attribute Types Attribute TypeDescription StringTypeIt takes any literal string as a value. CDATA is a StringType. CDATA is character data. This means, any string of non-markup characters is a legal part of the attribute. TokenizedTypeThis is more constrained type. The validity constraints noted in the grammar are applied after the attribute value is normalized. The TokenizedType attributes are given as: ID: It is used to specify the element as unique. IDREF: It is used to reference an ID that has been named for another element. IDREFS: It is used to reference all IDs of an element. ENTITY: It indicates that the attribute will represent an external entity in the document. ENTITIES: It indicates that the attribute will represent external entities in the document. NMTOKEN: It is similar to CDATA with restrictions on what data can be part of the attribute. NMTOKENS: It is similar to CDATA with restrictions on what data can be part of the attribute. numeratedType This has a list of predefined values in its declaration. out of which, it must assign one value. There are two types of enumerated attribute: NotationType: declares that an element will be referenced to a NOTATION declared somewhere else in the XML document. Enumeration: defines a specific list of values that the attribute value must match

34 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Element Attribute Rules An attribute name must not appear more than once in the same start-tag or empty-element tag. An attribute must be declared in the Document Type Definition (DTD) using an Attribute-List Declaration. Attribute values must not contain direct or indirect entity references to external entities. The replacement text of any entity referred to directly or indirectly in an attribute value must not contain either less than sign <

35 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Comments Tanmay A Any text between

36 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Character Entities W3C: “The document entity serves as the root of the entity tree and a starting- point for an XML processor.” declared in the document prolog or in a DTD Types of Character Entities There are three types of character entities: 1.Predefined Character Entities: Ampersand: & Single quote: &apos; Greater than: > Less than: < Double quote: " 2.Numbered Character Entities: &# decimal number; #x Hexadecimal number; 3.Named Character Entities 'Acute’ 'ugrave’

37 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML CDATA Sections Defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup. The predefined entities such as <, >, and & require typing and are generally difficult to read in the markup. In such cases, CDATA section can be used The above syntax is composed of three sections: 1.CDATA Start section - CDATA begins with the nine-character delimiter <![CDATA[ 2.CDATA End section - CDATA section ends with ]]> delimiter. 3.CData section - Characters between these two enclosures are interpreted as characters, and not as markup. This section may contain markup characters (, and &), but they are ignored by the XML processor Character Data CDATA ignored by the parser treated as character data and not as markup.

38 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar CDATA Rules CDATA cannot contain the string "]]>" anywhere in the XML document. Nesting is not allowed in CDATA section. spaces, tabs, and newlines

39 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar XML Whitespaces TanmayPatil different? Tanmay Patil different? A special attribute named xml:space may be attached to an element. This indicates that whitespace should not be removed for that element by the application. You can set this attribute to default or preserve as shown in the example below: Where: The value default signals that the default whitespace processing modes of an application are acceptable for this element; The value preserve indicates the application to preserve all the whitespaces.

40 Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar xml XML Processing is not included page 34 stop XML Quick Guide pdf


Download ppt "Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy."

Similar presentations


Ads by Google