Presentation is loading. Please wait.

Presentation is loading. Please wait.

225 City Avenue, Suite 106 Bala Cynwyd, PA 19004 610.206.0101, phone 610.206.0102, fax www.learnquest.com presents… XML Syntax v2.0.

Similar presentations


Presentation on theme: "225 City Avenue, Suite 106 Bala Cynwyd, PA 19004 610.206.0101, phone 610.206.0102, fax www.learnquest.com presents… XML Syntax v2.0."— Presentation transcript:

1 225 City Avenue, Suite 106 Bala Cynwyd, PA 19004 610.206.0101, phone 610.206.0102, fax www.learnquest.com presents… XML Syntax v2.0

2 2 Learning Objectives  The Markup Syntax – In general  Naming convention  The structure of an XML document  XML Elements  Nesting of XML Elements  Attributes and String Literals  Character and Entity References  Processing Instructions  CDATA sections  Comments

3 3 Markup Syntax – In General  The structure of a XML document is similar to an HTML document  XML markup uses angled-brackets to delimit tags (<>) just like HTML  Unlike HTML tags, XML tags are case-sensitive  In XML,,, are not equal

4 4 Naming Convention  XML names must begin with an underscore, colon or a letter and are followed with name characters  Name characters include the underscore, colon, letter, plus digits, hyphen and periods  Names cannot begin with the string “xml” in any case variation  Names beginning with “xml” are strictly for use by W3C

5 5 Naming Convention (con't)  The following are legal names in XML Employee employee _employee Employees:empid  The following are not legal names in XML XmlEmployee 124Empid -employee Empidsalary$ These two are not equivalent in XML

6 6 The Structure of an XML Document  An XML document consist of three parts An optional prolog The body consisting of the elements in a tree like structure An optional epilog containing comments, Processing Instructions (PIs) and/or white spaces

7 7 The Structure of an XML Document (con't) mk124 Amy Jones $80000 mk125 Cathy Smith $90000 BODY EPILOG PROLOG

8 8 The Structure of an XML Document (con't)  The “Prolog” is the starting point of an XML document  The “Prolog” Describes the character encoding method Provides configuration information to the parser  The “Prolog” consists of Optional XML Declaration Optional Document Type Declaration Optional PIs, white space characters, comments

9 9  XML Declaration: This is the basic syntax of an XML declaration  If an XML declaration is specified, it should be the first character in the XML document  This is the complete syntax of the XML declaration The Structure of an XML Document (con't)

10 10 The Structure of an XML Document (con't)  Document Type Declaration: Document Type Declaration is a way to associate a DTD (Document Type Definition) to a XML document (Document Type Declaration and Document Type Definition are different terms)  All “valid” XML documents must include this declaration

11 11 The Structure of an XML Document (con't)  The “Epilog” in an XML document may contain comments and PIs  The “Epilog” is not commonly declared in an XML document. It is advisable not to use it

12 12 The Structure of an XML Document (con't) An XML document hierarchical tree structure Document Root / Document Entity Document Element / Parent Element Elements

13 13 mk124 Amy Jones $80000 mk125 Cathy Smith $90000 The Structure of an XML Document (con't) Document Root Document Element Child Elements

14 14 XML Elements  Elements are the building blocks of an XML document  Elements may contain other elements, character data, PIs, comments or entity references  Elements consist of the element type name enclosed within angle brackets  Every element must contain a start-tag and an end- tag with the exception of empty-tags

15 15 XML Elements (con't)  Here are some legal start-tags  Here are some legal end-tags

16 16 XML Elements (con't)  This is a complete element with the start-tag and end-tag This is example to demonstrate elements and tags

17 17  Empty elements do not contain any content  Empty elements may consist of the start-tag and end-tag or be represented by a hybrid form  This is how we can represent empty elements XML Elements (con't)

18 18 XML Elements (con't)  Elements can have any of the four kinds of content Element type containing other elements with no character data is said to have element content Element type containing both character data and elements is said to have mixed content Element type containing only character data is considered character data Element type containing no content is an empty element. Empty elements may however contain attributes

19 19 Nesting of XML Elements  XML elements must be properly nested  Unlike HTML, XML does not permit improper nesting  If elements are not properly nested, a hierarchical tree cannot be constructed in XML  The XML parser will report any improper nesting in the XML document

20 20 Attributes and String Literals  Sometimes it is necessary to attach additional information about an element which may not be contained in the element itself  Attributes can be used for such situations  An attribute is a name value pair attached to the element

21 21  Any of the two formats can be used for attributes attributename = “attributevalue” attributename = ‘attributevalue’  The rules of string literals are applicable on attribute values  Start-tags and empty-elements can contain attributes Attributes and String Literals (con't)

22 22 Attributes and String Literals (con't) mk124 Amy Jones $80000 mk125 Cathy Smith $90000 Attribute Name and Attribute Value

23 23 Attributes and String Literals (con't)  String Literals are used as Values of attributes Internal entities External identifiers  String Literals are enclosed in delimiters  An apostrophe (‘) or double quotes (“) can be used as delimiters  Apostrophe or double quotes can be used within the string literal itself with some restrictions

24 24  If an apostrophe (‘) appears in the string literal, double quotes can used as a delimiter and vice versa  If both delimiters must appear within the string literal, they have to be appropriately escaped, using entity references - &apos; and "  Here are some valid string literals “value” ‘value’ ‘Remember, XML&apos;s “case-sensitivity” issue’ Attributes and String Literals (con't)

25 25  Here are some invalid string literals ‘value” “value’ ‘Remember, XML’s “case-sensitivity” issue’ Attributes and String Literals (con't)

26 26 Character and Entity References  XML provides two methods of representing characters that are not found in the ASCII character set  These two methods are: Character references Entity references

27 27 Character and Entity References (con't)  Character references are used as a substitute for a literal form of a character where the processing of the literal form will produce a non-well formed XML document  Character references are comprised of a decimal or hexadecimal number which is prefixed by “&#” (decimal) or “&#x” (hexadecimal) string literals and is followed by a semi-colon (;)

28 28 Character and Entity References (con't)  &#NN; represents the decimal equivalent to any Unicode character value in XML  &#xNN; represents the hexadecimal equivalent to any Unicode character value in XML - NN is a one or more digit that corresponds to a Unicode character value in XML  The hexadecimal form is preferred in XML

29 29  For example: The ampersand (&) in the word “L&T” could be represented in the following manner in XML L&T L&T  Decimal 38 and hexadecimal 26 represent the Unicode value for ampersand (&)  The decimal value has been prefixed with &# and the hexadecimal value has been prefixed with &#x Character and Entity References (con't)

30 30 Character and Entity References (con't)  To understand “Entity References”, first we will define an “Entity”  An “Entity” is a named body of data/content  “Entity Reference” is a placeholder to display that data or in other words, the entity  The entity is represented by the name prefixed with an ampersand (&) and followed by a semi-colon (;)

31 31 Character and Entity References (con't)  This is how an entity reference in displayed &entityname;  XML has five predefined entities & < > &apos; "  These five entities are used as escape sequences for the XML delimiter characters

32 32  Here is example of a predefined XML entity L&T  Except for the predefined entities, all entities must be defined prior to using them  An XML parser reports an error if it finds an undefined entity reference  Entities are defined in a DTD Character and Entity References (con't)

33 33 Character and Entity References (con't)  This is how we declare an entity within an XML document <!DOCTYPE root [ <!ENTITY example-info “This is just an example to show how an entity is declared"> ]> &example-info;

34 34  In a browser, this is how the entity will be displayed This is just an example to show how an entity is declared  Entity references may also be used as general text macros as above Character and Entity References (con't)

35 35 <!DOCTYPE root [ ]> &LQInfo; Do You Think This Will Work?

36 36 Processing Instructions  XML is designed for describing data. The presentation of the XML document is dependent on the application  But there are times when it is required to pass this information to an application along with the XML document  Processing Instruction (PI) is the mechanism to achieve this in an XML document

37 37  A CDATA Section is a section within the element content/data which is meant to be interpreted as character data and not markup by the parser  The basic syntax of a CDATA section is  A CDATA section begins with <![CDATA[  A CDATA section ends with the first occurrence of ]]> CDATA Sections

38 38  Consider this example: LearnQuest  All text within the start tag and end tag is considered as text and not markup. If you write it like this, LearnQuest ]]> The code will be interpreted as <start_tag>LearnQuest</end-tag> or <start_tag>LearnQuest</end-tag> CDATA Sections (con't)

39 39 CDATA Sections (con't)  CDATA sections are used when the author of the XML document wants to write XML code within the text or XML content  A CDATA section cannot contain the string “]]>”. Therefore a CDATA section cannot appear within a CDATA section

40 40 Comments  The basic syntax of an XML comment is:  where “Your comment goes here” can be any character string which does not include “- -”  The comment cannot end with a hyphen (-). The hyphen is a part of the closing delimiter and hence could be misinterpreted

41 41 Comments (con't)  Here are some examples displaying comments: <!- - A comment can also continue.. on another line - - >

42 42 Comments (con't)  Some illegal comments: This is not a legal way to comment because comments cannot appear within tags >

43 43 Any Questions?


Download ppt "225 City Avenue, Suite 106 Bala Cynwyd, PA 19004 610.206.0101, phone 610.206.0102, fax www.learnquest.com presents… XML Syntax v2.0."

Similar presentations


Ads by Google