Your SlideShare is downloading. ×
  • Like
Topic 05 : Web Based Protocols
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Topic 05 : Web Based Protocols

  • 391 views
Published

 

Published in Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads

Views

Total Views
391
On SlideShare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
15
Comments
1
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Topic 5 : Web Based Protocols Er. Pradip Kharbuja
  • 2. Learning Objectives • Define and use XML documents • Understand and use the RSS protocol • Incorporate XML parsing into PHP
  • 3. 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.
  • 4. 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
  • 5. 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
  • 6. 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.
  • 7. 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>
  • 8. 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.
  • 9. XML Elements • An XML element is anything that is contained within starting and closing tags. • This may consist of: - Other elements - Attributes - Text
  • 10. 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.
  • 11. 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>
  • 12. 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
  • 13. The XML Tree Structure <root> <child> <subchild>something</subchild> </child> <child> <subchild>something</subchild> </child> </root>
  • 14. 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.
  • 15. Types of XML 1. Well Formed XML 2. Valid XML
  • 16. 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.
  • 17. 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.
  • 18. Datatypes of DTD elements 1. #PCDATA 2. #EMPTY 3. #ANY Parsed Character Data
  • 19. 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)> ]>
  • 20. Example of DTD [Contd.] <addresses> <person> <firstname>Michael</firstname> <surname>Heron</surname> <organisation>NCC</organisation> </person> </addresses>
  • 21. 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
  • 22. 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)> ]>
  • 23. Types of DTD 1. Internal DTD 2. External DTD
  • 24. External DTD • save the rules in .dtd file • Replace <!DOCTYPE.... with <!DOCTYPE root_element SYSTEM "filename.dtd">
  • 25. 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
  • 26. 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.
  • 27. 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.
  • 28. 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 />"; }
  • 29. 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.");
  • 30. 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");
  • 31. 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().
  • 32. Our Architecture So Far Presentation HTML Application PHP Data MySQL XML fits into the data layer of our architecture. XML
  • 33. To Study yourself... • • • • • • Why use XML? Why not to use XML? Importance of Formats Importance of Protocols SMTP Protocol Internet Protocols and Formats
  • 34. End of Topic 5