COMPUTER SCIENCE TOPIC: XML BY : Priyanka pradhan Priyanka Pradhan
Introduction to XML XML is extensible markup language . XML case sensitive . XML was designed to store and transport data. XML is often used for distributing data over the Internet. XML documents form a tree structure. Priyanka Pradhan
Introduction to XML <?xml version=“1.0”?> <student detail> <name> rohit </name> <branch> csit </branch> </student detail> ROOT ELEMENT CHILD ELEMENT Priyanka Pradhan
Contd … Student detail Name: rohit Branch: csit Root Element Child Element Priyanka Pradhan
Priyanka Pradhan
What is the DOM? The HTML DOM defines a standard way for accessing and manipulating HTML documents. It presents an HTML document as a tree-structure . The XML DOM defines a standard way for accessing and manipulating XML documents. It presents an XML document as a tree-structure. Priyanka Pradhan
The XML DOM All XML elements can be accessed through the XML DOM. A standard object model for XML A standard programming interface for XML Platform- and language-independent A W3C standard The XML DOM is a standard for how to get, change, add, or delete XML elements. Priyanka Pradhan
DTD It is Document type definition An XML document with correct syntax is called well formed . An XML document validated against a DTD is both well formed and valid . Priyanka Pradhan
Node Parents, Children, and Siblings Parent nodes have children. Children on the same level are called siblings (brothers or sisters ). In a node tree, the top node is called the root Every node, except the root, has exactly one parent node A node can have any number of children A leaf is a node with no children Siblings are nodes with the same parent Priyanka Pradhan
PCDATA PCDATA - Parsed Character Data XML parsers normally parse all the text in an XML document. When an XML element is parsed, the text between the XML tags is also parsed: <message>This text is also parsed</message> The parser does this because XML elements can contain other elements, as in this example, where the <name> element contains two other elements (first and last): <name><first>Bill</first><last>Gates</last></name> and the parser will break it up into sub-elements like this: <name> <first>Bill</first> <last>Gates</last> </name> Priyanka Pradhan
CDATA - (Unparsed) Character Data The term CDATA is used about text data that should not be parsed by the XML parser. Characters like "<" and "&" are illegal in XML elements. "<" will generate an error because the parser interprets it as the start of a new element. "&" will generate an error because the parser interprets it as the start of an character entity. Some text, like JavaScript code, contains a lot of "<" or "&" characters. To avoid errors script code can be defined as CDATA . A CDATA section starts with " <![CDATA[ " and ends with " ]]> ": Priyanka Pradhan
What is XPath ? XPath stands for XML Path Language XPath uses "path like" syntax to identify and navigate nodes in an XML document XPath contains over 200 built-in functions XPath is a major element in the XSLT standard XPath is a W3C recommendation Priyanka Pradhan
XPath uses path expressions to select nodes or node-sets in an XML document. Priyanka Pradhan
XSLT XSL ( eXtensible Stylesheet Language) is a styling language for XML. XSLT stands for XSL Transformations. XSLT is used to transform XML documents into other formats (like transforming XML into HTML). Priyanka Pradhan
XSL(T) Languages XSLT is a language for transforming XML documents. XPath is a language for navigating in XML documents. XQuery is a language for querying XML documents. Priyanka Pradhan
What is a DTD? A DTD is a Document Type Definition. A DTD defines the structure and the legal elements and attributes of an XML document. An application can use a DTD to verify that XML data is valid . Priyanka Pradhan
If the DTD is declared inside the XML file, it must be wrapped inside the <!DOCTYPE> definition. Priyanka Pradhan
<?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note ( to,from,heading,body )> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to> Tove </to> <from> Jani </from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note> Priyanka Pradhan
The DTD is interpreted like this: !DOCTYPE note defines that the root element of this document is note !ELEMENT note defines that the note element must contain four elements: " to,from,heading,body " !ELEMENT to defines the to element to be of type "#PCDATA" !ELEMENT from defines the from element to be of type "#PCDATA" !ELEMENT heading defines the heading element to be of type "#PCDATA" !ELEMENT body defines the body element to be of type "#PCDATA" Priyanka Pradhan
An External DTD Declaration XML document with a reference to an external DTD <?xml version="1.0"?> <!DOCTYPE note SYSTEM "note.dtd"> <note> <to> Tove </to> <from> Jani </from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Priyanka Pradhan
And here is the file "note.dtd", which contains the DTD: <!ELEMENT note ( to,from,heading,body )> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> Priyanka Pradhan
DTD - XML Building Blocks Elements Attributes Entities PCDATA CDATA Priyanka Pradhan
Elements Elements are the main building blocks of both XML and HTML documents. < body>some text</body> < message>some text</message> Priyanka Pradhan
Attributes Attributes provide extra information about elements . < img src ="computer.gif" /> Priyanka Pradhan
Entities Entity References Character < < & gt ; > & & " " ' ' Priyanka Pradhan
DTD - Elements <!ELEMENT element-name category> or <!ELEMENT element-name (element-content )> Priyanka Pradhan
Elements with Parsed Character Data <!ELEMENT element-name (#PCDATA)> Example: <!ELEMENT from (#PCDATA)> Priyanka Pradhan
Elements with any Contents <!ELEMENT element-name ANY> Example: <!ELEMENT note ANY> Priyanka Pradhan
Elements with Children (sequences) <!ELEMENT element-name (child1)> or <!ELEMENT element-name (child1,child2 ,...)> Example: <!ELEMENT note ( to,from,heading,body )> Priyanka Pradhan
Declaring Only One Occurrence of an Element <!ELEMENT element-name (child-name)> Example: <!ELEMENT note (message)> Priyanka Pradhan
Declaring Minimum One Occurrence of an Element <!ELEMENT element-name (child-name+)> Example: <!ELEMENT note (message+)> Priyanka Pradhan
Declaring Zero or More Occurrences of an Element <!ELEMENT element-name (child-name*)> Example: <!ELEMENT note (message*)> Priyanka Pradhan
Declaring Zero or One Occurrences of an Element <!ELEMENT element-name (child-name?)> Example: <!ELEMENT note (message?)> Priyanka Pradhan
What is an XML Schema? An XML Schema describes the structure of an XML document . The XML Schema language is also referred to as XML Schema Definition (XSD). Priyanka Pradhan
The purpose of an XML Schema is to define the legal building blocks of an XML document: the elements and attributes that can appear in a document the number of (and order of) child elements data types for elements and attributes default and fixed values for elements and attributes Priyanka Pradhan
well-formed XML document it must begin with the XML declaration it must have one unique root element start-tags must have matching end-tags elements are case sensitive all elements must be closed all elements must be properly nested all attribute values must be quoted entities must be used for special characters Priyanka Pradhan
A Simple 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> Priyanka Pradhan
A DTD File <!ELEMENT note (to, from, heading, body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> Priyanka Pradhan
A Reference to a DTD <?xml version="1.0"?> <!DOCTYPE note SYSTEM "https://www.w3schools.com/xml/note.dtd"> <note> <to> Tove </to> <from> Jani </from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Priyanka Pradhan
A Reference to an XML Schema <?xml version="1.0"?> <note xmlns ="https://www.w3schools.com" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation ="https://www.w3schools.com/xml/note.xsd"> <to> Tove </to> <from> Jani </from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Priyanka Pradhan