Basic XML - Concepts
Our goals
What is XML? XML Syntax Rules XML Elements Naming Rules XML Attributes XML Validation XML Related Technologies XML Quiz
Copy Right Reserved Satyam EAI Team
What is XML?
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. You must define your own tags XML is a W3C Recommendation (10. February 1998.)
Copy Right Reserved Satyam EAI Team
What is XML?
Usage of XML
XML is used to Exchange Data (widely used)
Data can be exchanged between incompatible systems. Information can be exchanged over the Internet.
XML Can be Used to Store Data
Copy Right Reserved Satyam EAI Team
XML Syntax Rules
XML Syntax Rules
The syntax rules of XML are very simple and very strict.
Example:
<?xml version="1.0" ?> <employee> <name>Arun Prakash</name> <id>12345</id> <age>28</age> <department> <name>EAI</name> <location>Tidel park</location> </department> <experience>8</experience> </employee>
Copy Right Reserved Satyam EAI Team
XML Syntax Rules
XML Document can have a XML declaration element
<?xml version="1.0" ?> <?xml version="1.0" encoding="ISO-8859-1"?> Defines the XML version and the character encoding used in the document.
Copy Right Reserved Satyam EAI Team
XML Syntax Rules
XML Documents Must Have a Root Element
Example:
<?xml version="1.0" ?> <employee> <-- ROOT ELEMENT <name>Arun Prakash</name> <id>12345</id> <age>28</age> <department> <name>EAI</name> <location>Tidel park</location> </department> <experience>8</experience> </employee>
Copy Right Reserved Satyam EAI Team
XML Syntax Rules
Invalid XML without Root Element
<?xml version="1.0" ?> <name>Arun Prakash</name> <id>12345</id> <age>28</age> <department> <name>EAI</name> <location>Tidel park</location> </department> <experience>8</experience>
Copy Right Reserved Satyam EAI Team
10
XML Syntax Rules
XML Tags are Case Sensitive
<?xml version="1.0" ?> <employee> <name>Arun Prakash</name> <id>12345</id> <age>28</age> <Department> <-- note the closing tag <name>EAI</name> <location>Tidel park</location> </department> <experience>8</experience> </employee>
Copy Right Reserved Satyam EAI Team
11
XML Syntax Rules
XML Elements Must be Properly Nested
<?xml version="1.0" ?> <employee> <name>Arun Prakash</name> <id>12345</id> <age>28</age> <department> <name>EAI</name> <location>Tidel park</location> <experience>8 </department> </experience> </employee>
Copy Right Reserved Satyam EAI Team
12
XML Syntax Rules
All XML Elements Must Have a Closing Tag
<?xml version="1.0" ?> <employee> <name>Arun Prakash</name> <id>12345 <-- Illegal XML <age>28</age> <department> <name>EAI</name> <location>Tidel park</location> </department> <experience>8</experience> </employee>
Copy Right Reserved Satyam EAI Team
13
XML Syntax Rules
Comments in XML <!-- some comments -->
<?xml version="1.0" ?> <employee> <!-- name of the employee --> <name>Arun Prakash</name> <id>12345</id> <age>28</age> <!-- age of the employee --> <!-- provides details about employee department --> <department> <name>EAI</name> <location>Tidel park</location> </department> <experience>8</experience> </employee>
Copy Right Reserved Satyam EAI Team
14
XML Syntax Rules
With XML, the white space in your document is not truncated.
<?xml version="1.0" ?> <employee> <name>Arun Prakash</name> <id>12345</id> <age>28</age> <department> <name>EAI</name> <location>Tidel park </department> <experience>8</experience> </employee>
Chennai</location>
Copy Right Reserved Satyam EAI Team
15
XML Syntax Rules
XML Element can have Empty Value
Sample : <name></name> or <name/>
Copy Right Reserved Satyam EAI Team
16
XML Elements Naming Rules
17
XML Elements Naming Rules
XML elements must follow these naming rules:
Names can contain letters, numbers, and other characters Names must not start with a number or punctuation character Names must not start with the letters xml (or XML, or Xml, etc) Names cannot contain spaces Names should not have semi colon (:) its reserved for something called namespace
Copy Right Reserved Satyam EAI Team
18
XML Elements Naming Rules
Some Examples:
XML Element Name <someName1234> Valid / Invalid Valid Comments
<1someName234> <some_Name-1234> <some name> <xMLSomeName> <some:name> <some_name_some_n ame_some>
Invalid Valid Invalid Invalid Invalid Valid
Should not start with number Some special characters are allows No spaces Should not start with word xml / XML / xML etc Semi colon not allowed No restriction on element length
Copy Right Reserved Satyam EAI Team
19
XML Attributes
20
XML Attributes
<elementName attributeName=attributeValue>elementValue </elementName>
n number of attributes can be defined in a element Attribute values must always be enclosed in quotes, but either single or double quotes can be used. attributes cannot contain multiple values attributes name should not be repeated in the same element (Check)
Copy Right Reserved Satyam EAI Team
21
XML Attributes
Example:
<?xml version="1.0" ?> <employee id=12345 age=28> <name>Arun Prakash</name> <department name=EAI> <location>Tidel park</location> </department> <experience>8</experience> </employee>
Copy Right Reserved Satyam EAI Team
22
XML Validation
23
XML Validation
Well Formed XML Documents
A "Well Formed" XML document has correct XML syntax. A "Well Formed" XML document is a document that conforms to the XML syntax rules:
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 always be quoted XML attribute may appear more than once on the same start-tag. XML elements name follows the naming syntax rules
Copy Right Reserved Satyam EAI Team
24
XML Validation
Valid XML Documents : A "Valid" XML document also conforms to a XML definition (DTD / XML Schema) A "Valid" XML document is a "Well Formed" XML document, which is according to the XML structure defined in DTD or XML Schema (more about it later) the naming syntax rules
Copy Right Reserved Satyam EAI Team
25
XML Related Technologies
26
XML Related Technologies
XHTML (Extensible HTML) is a stricter and cleaner version of HTML. XSL (Extensible Style Sheet Language) - XSL consists of three parts
XSLT (XSL Transformations)- a language for transforming XML documents XPath - a language for navigating in XML documents XSL-FO (Formatting Objects) - a language for formatting XML documents.
Copy Right Reserved Satyam EAI Team
27
XML Related Technologies
XSD (XML Schema) is an XML-based alternative to DTDs. DTD (Document Type Definition) is used to define the legal elements in an XML document. XQuery (XML Query Language) is designed to query XML data. SOAP (Simple Object Access Protocol) is an XML-based protocol to let applications exchange information over HTTP.
Copy Right Reserved Satyam EAI Team
28
XML Related Technologies
WSDL (Web Services Description Language) is an XMLbased language for describing web services. XLink (XML Linking Language) is a language for creating hyperlinks in XML documents. XPointer (XML Pointer Language) allows the XLink hyperlinks to point to more specific parts in the XML document.
Copy Right Reserved Satyam EAI Team
29
Quiz
30
Quiz
1. What does XML stand for?
eXtensible Markup Language X-Markup Language Example Markup Language Xtra Modern Link
Answer : eXtensible Markup Language
Copy Right Reserved Satyam EAI Team
31
Quiz
2. There is a way of describing XML data, how?
XML uses a description node to describe data XML uses a DTD to describe the data XML uses XSL to describe data
Answer :XML uses a DTD to describe the data
Copy Right Reserved Satyam EAI Team
32
Quiz
3. XML's goal is to replace HTML
False True
Answer : False
Copy Right Reserved Satyam EAI Team
33
Quiz
4. What is the correct syntax of the declaration which defines the XML version?
<?xml version="1.0" /> <xml version="1.0" /> <?xml version="1.0"?>
Answer : <?xml version="1.0"?>
Copy Right Reserved Satyam EAI Team
34
Quiz
5. What does DTD stand for?
Dynamic Type Definition Do The Dance Direct Type Definition Document Type Definition
Answer : Document Type Definition
Copy Right Reserved Satyam EAI Team
35
Quiz
6. Is this a "well formed" 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>
Yes No
Answer : Yes
Copy Right Reserved Satyam EAI Team
36
Quiz
7. Is this a "well formed" XML document?
<?xml version="1.0"?> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body>
Yes No
Answer : No
Copy Right Reserved Satyam EAI Team
37
Quiz
8. Which statement is true?
All the statements are true All XML elements must be lower case All XML documents must have a DTD All XML elements must be properly closed
Answer : All XML elements must be properly closed
Copy Right Reserved Satyam EAI Team
38
Quiz
9. Which statement is true?
All the statements are true XML elements must be properly nested XML tags are case sensitive XML documents must have a root tag
Answer: All the statements are true
Copy Right Reserved Satyam EAI Team
39
Quiz
10. XML preserves white spaces
False True
Answer : False
Copy Right Reserved Satyam EAI Team
40
Quiz
11. Is this a "well formed" XML document?
<?xml version="1.0"?> <note> <to age="29">Tove</to> <from>Jani</from> </note>
No Yes
Answer : Yes
Copy Right Reserved Satyam EAI Team
41
Quiz
12. Is this a "well formed" XML document?
<?xml version="1.0"?> <note> <to age=29>Tove</to> <from>Jani</from> </note>
Yes No
Answer : No
Copy Right Reserved Satyam EAI Team
42
Quiz
13. XML elements cannot be empty
True False
Answer : False
Copy Right Reserved Satyam EAI Team
43
Quiz
14. Which is not a correct name for an XML element?
<h1> <1dollar> All 3 names are incorrect <Note>
Answer : <1dollar>
Copy Right Reserved Satyam EAI Team
44
Quiz
15. Which is not a correct name for an XML element?
All 3 names are incorrect <first name> <age> <NAME>
Answer : <first name>
Copy Right Reserved Satyam EAI Team
45
Quiz
16. Which is not a correct name for an XML element?
All 3 names are incorrect <phone number> <7eleven> <xmldocument>
Answer : All 3 names are incorrect
Copy Right Reserved Satyam EAI Team
46