Topic 05 : Web Based Protocols

50 %
50 %
Information about Topic 05 : Web Based Protocols
Education

Published on September 17, 2013

Author: PradipKharbuja

Source: slideshare.net

Topic 5 : Web Based Protocols Er. Pradip Kharbuja

Learning Objectives • Define and use XML documents • Understand and use the RSS protocol • Incorporate XML parsing into PHP

Introduction • In this lecture, we are going to broaden our understanding of internet based formats and protocols. - This will be important for discussing web services later in the module. • The internet is a complex system of platforms and user requirements. - It is also a system that should be system agnostic. • We do not know or care what kind of computers are receiving our data.

XML • • • • • • • eXtensible Markup Language It is a small database. The file format is generally in .xml xml is case sensitive XML tags are not pre-defined. primary function of XML is to carry data main reason to use xml is portability

XML • XML is a very common data format on the internet, and is the basis for many other protocols and formats. - It stores data alongside the information needed to interpret that data • That is often referred to as metadata – data about data • A firm understanding of XML is required in order to understand how other common formats work. - Such as XHTML, SOAP and RSS

XML • XML (eXtensible Markup Language) is structured very much like HTML. • The main difference is the tags that are used have no intrinsic meaning. • Tags are user defined. • It is a textual format (like HTML), which means that it is built in itself on the unicode format. • This makes it very simple to transmit across networks, as text data is a well understood quantity.

A Simple XML Document • An XML document begins by providing versioning information at the start. • It is then followed by one root element or document element. • It is then followed by child elements. <?xml version="1.0"?> <addresses> <person> <firstname>Michael</firstname> <surname>Heron</surname> <organisation>NCC</organisation> </person> </addresses>

Rules of XML • XML is case sensitive. • Every tag must be closed by the matching end tag. In case of empty tag, / is used.  eg. <person></person>, <br/> • • • • XML declaration must be present in every xml file. There should not be any space or character before XML declaration Value of every attribute must be enclosed by single or double quote. There must be only one root element in an XML.

XML Elements • An XML element is anything that is contained within starting and closing tags. • This may consist of: - Other elements - Attributes - Text

XML Attributes • Attributes allow us to specify additional information about elements. - In HTML, we have the <a> tag, which indicates a hyperlink. We provide it the destination with an attribute href: • <a href = "http://www.google.com"> • XML permits us to do the same thing in our elements.

A Simple XML Document with Attributes <?xml version="1.0"?> <addresses> <person gender="male"> <firstname>Michael</firstname> <surname>Heron</surname> <organisation>NCC</organisation> <notes>Don't buy a used car from this man.</notes> </person> </addresses>

The XML Tree Structure • All of the elements within an XML document must confirm to a tree structure. - The document has a root element, which has one or more child elements. • Each of these child elements may have one or more subchild elements. -And so on

The XML Tree Structure <root> <child> <subchild>something</subchild> </child> <child> <subchild>something</subchild> </child> </root>

Task 1. Design an XML data page to be used for an address book supporting multiple email ids and contact numbers. 2. Design an XML page to store the course details including their available semesters and their subjects.

Types of XML 1. Well Formed XML 2. Valid XML

Well Formed XML • XML has a particular syntax it must follow. - Rules about how names and elements are used. • That is the XML Format • XML documents that consists of these XML rules are called Well Formed XML.

Valid XML • Valid XML is a well formed XML document that also conforms to a set of typing conventions known as a Document Type Definition (DTD). - This DTD defines what is ‘legal’ XML for a particular kind of element. • All valid XML is always well formed XML but all well formed XML may not be valid XML. • An XML Schema can also be used for the same purpose. - To provide for type checking and to provide a platform independent method of interpreting XML Data.

Datatypes of DTD elements 1. #PCDATA 2. #EMPTY 3. #ANY Parsed Character Data

Example of DTD <?xml version="1.0"?> <!DOCTYPE addresses[ <!ELEMENT addresses (person)> <!ELEMENT person (firstname, surname, organisation) > <!ELEMENT firstname (#PCDATA)> <!ELEMENT surname (#PCDATA)> <!ELEMENT organisation (#PCDATA)> ]>

Example of DTD [Contd.] <addresses> <person> <firstname>Michael</firstname> <surname>Heron</surname> <organisation>NCC</organisation> </person> </addresses>

Access Modifier of DTD 1. + 2. * 3. ? 4. one or more occurances zero or more occurances zero or one occurance if nothing written, only one time and is required

Example of DTD with Access Modifier <?xml version="1.0"?> <!DOCTYPE addresses[ <!ELEMENT addresses (person*)> <!ELEMENT person (firstname, surname?, organisation+) > <!ELEMENT firstname (#PCDATA)> <!ELEMENT surname (#PCDATA)> <!ELEMENT organisation (#PCDATA)> ]>

Types of DTD 1. Internal DTD 2. External DTD

External DTD • save the rules in .dtd file • Replace <!DOCTYPE.... with <!DOCTYPE root_element SYSTEM "filename.dtd">

RSS • RSS (Really Simple Syndication). • RSS is an XML based format for providing updates on changed or new content within a website. • Blogs, news sites and other such web pages will usually publish an RSS feed. • e.g. http://feeds.bbci.co.uk/news/rss.xml • e.g. http://weather.yahooapis.com/forecastrss?w=2269179

RSS • Other web enabled applications can then use this feed in order to update users with changing content on other sites. • The RSS standard defines what tag names are used to transport information. • These include any images, links to the main story, summaries, languages, copyright reasons, and so on. - These can then be incorporated into an application in whatever way the developer desires.

Parsing XML with PHP • PHP comes complete with an XML parsing system. • We need functions to deal with: - Encountering a start tag - Encountering an end tag - Encountering content - These are the callback functions.

Simple XML Parsing function contents($parser, $data){ echo $data; } function startTag($parser, $data){ echo "&lt; $data &gt;"; } function endTag($parser, $data){ echo "&lt; $data &gt; <br />"; }

Setting up Parser • To create a parser, we need an XML file to parse. • We can open a remote internet file in PHP in the same way we can open a local file. - Through the fopen() function. • We create the parser itself by using xml_parser_create(). - $xml_parser = xml_parser_create() or die("Couldn create parser.");

Setting up Parser [Contd.] • We need to set the functions responsible for finding start tags and end tags: - xml_set_element_handler($xml_parser, "startTag", "endTag"); • And the function for content: - xml_set_character_data_handler($xml_parser, "contents");

Reading and Parsing the File • As the file is a remote file, we need to read from the server in chunks. - This is done using the fread() function. • We take those chunks and then pass them through our parser. - We do this through the xml_parse() function - This then calls the callback functions where it encounters the tags & elements. • At the end, we free the parser and close the file reference using fclose() and xml_parser_free().

Our Architecture So Far Presentation HTML Application PHP Data MySQL XML fits into the data layer of our architecture. XML

To Study yourself... • • • • • • Why use XML? Why not to use XML? Importance of Formats Importance of Protocols SMTP Protocol Internet Protocols and Formats

End of Topic 5

#pcdata presentations

Add a comment

Related presentations

Related pages

Topic 05 : Web Based Protocols - Education - documents.mx

1. Topic 5 : Web Based Protocols Er. Pradip Kharbuja. 2. Learning Objectives • Define and use XML documents • Understand and use the RSS protocol ...
Read more

Cobalt-based nanocatalysts for green oxidation and ...

Cobalt-based nanocatalysts for green oxidation and ... the development of nanoscale metal oxides has become a prime topic for ... Nature Protocols 05 ...
Read more

JRP-JMIR Research Protocols

JMIR Research Protocols (ISSN 1929 ... a topic unrelated to ... a self-administered Web-based questionnaire will be issued at baseline and after 4 weeks ...
Read more

XML-Based Protocols - C# Corner

In this article I will explain you about XML-Based Protocols. * * C# ... Please refer to the World Wide Web ... topic > http://electrocommerce ...
Read more

Additional Web Protocols - Documents

Additional Web Protocols. JavaScript and XML An overview of web languages and emerging technologies. JavaScript Overview. Scripting Language that uses a ...
Read more

IBC'05 Home page

Incentive Based Computing (IBC'05 ... we design efficient protocols that are robust ... dedicated exclusively to this important topic. IBC'05 ...
Read more

Managing Protocols - technet.microsoft.com

The virtual servers that are associated with the various protocols, ... based on the capabilities ... Office Outlook 2003 Web ...
Read more

Tools for Implementing an Evidence-Based Approach in ...

... including free online resources in the following topic ... to provide web-based training materials ... 2006/jan/05_0166.htm ...
Read more

Messaging Protocols - msdn.microsoft.com

The Windows Communication Foundation ... and the most common encodings used by Web services are XML-based ... This topic covers WCF implementation ...
Read more