HandsOn Assignment 2

profilejams_r1
WHERECANYOUFINDYOURFAVORATECAF_HelpFile.pdf

1

WHERE CAN YOU FIND YOUR FAVORATE CAFÉ?

Assignment Help File This assignment shows how a NoSQL DBMS helps with Web application. The Extensible Markup Language (XML) is a general-purpose specification for creating custom markup languages. It is classified as an extensible language because it allows its users to define their own elements. Its primary purpose is to help information systems share structured data, particularly via the Internet, and it is used both to encode documents and to serialize data. In the latter context, it is comparable with other text-based serialization languages such as JSON and YAML. To get familiar with using XML, please access XML tutorial at http://www.w3schools.com/xml/. This help file will focus on how to get this assignment done. Creating a Simple XML Data File 1. Go through Start/All Programs/Accessories to open Notepad; 2. Save this empty file as CAFÉ.xml. To change the file name extension, first pick All Files from the Save as type list box. Then type the entire file name into File name box. 3. In the first line of this empty document window type <?xml version="1.0" ?> to define the version. 4. Leave an empty space here for style declaration later. 5. Now we are ready to build a data structure to use by a web page in this XML document. The data structure is simple. At the root is a structure called CAFES. This structure at the next level has a repeated number of child structures called CAFE. In turn, the structure CAFE has one attribute, CAFE_TYPE, and it has five elements: • CAFE_NAME • FOOD_QUALITY • ENVIRON • COST_RATING • COMMENTS 6. The code for the entire file CAFE.xml is contained in the image provided in the assignment description. XML code comes in pairs. You have an open tag to mark the beginning of a structure and you use a closing tag to put an end to this structure. 7. To create this data structure, leave an empty space after the style declaration statement, then type <CAFES>; 8. Leave several empty spaces before you create the closing tag </CAFES>. 9. Now you are ready to create the first sub-structure. Remember, each element in this sub-structure also follows the rule of a closing tag. Please use all caps for the tags for easy recognition. 10. Once you created this first CAFÉ structure, check the spelling to ensure its correctness. 11. Now, you can copy this sub-structure four more times below to build the framework for the rest of the data records. Assuming all the XML tags are correct, all you have to do then is to change the data content between each pair of tags. 12. Make sure all your CAFÉ sub-structures are contained within the parental structure of <CAFES> </CAFES>. 13. Now you are ready to check the effect. Please save and close this document first. 14. Double click to open it;

2

15. Mine opens in Internet Explorer. If everything is correct, you should see the same data structure as it is in the image. 16. Click on a minus sign in front of an xml statement to see the change. It should work as a file structure. 17. If you see an error message, please do not panic. Open your XML file in Notepad to search for and correct the error, then check the effect in IE again till it works. 18. Close the IE window and open your XML file into Notepad again. This time we will add a style declaration statement to the beginning of the data structure. 19. In the empty space below the XML version definition, type or copy from the assignment description <?xml-stylesheet type="text/xsl" href="CAFE.xsl"?>. This line declares the type of style sheet to use and the name of the style sheet file. This line determines how the data in your xml file will be displayed in a web page. Formatting XML Using XSL Now consider the XSL file, CAFE.xsl. The file accomplishes several tasks: (1) the XSL file generates the HTML code that eventually runs on the browser. The XSL file has to create the necessary HTML tags for that purpose. (2) As part of the above, the XSL code creates a table that has the tabular headings in the first row. (3) Looping constructs allowed in XSL are used to read individual elements of CAFE in the associated XML file and then to output the values in the HTML table. 1. Open another document in Notepad and save it as CAFÉ.xsl. The procedures are the same as creating CAFÉ.xml in Notepad. 2. Preamble. The file begins with a preamble that defines the location of the XSL specification by the following line: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">. 3. Type <xsl:template match="/"> in the next line. This statement instructs the system to match the XSL template right from the root stage of the structure described in your XML file (i.e., the entire structure of CAFES/CAFE is to be processed as per the XSL file). 4. Now you are ready to create a web page for your xml data. Please type <HTML> and hit Enter to go to the next line; 5. Leave some spaces at the beginning and then type <BODY>. This way you open a web page to display your content. 6. HTML coding also follows the rule of a closing tag. Therefore, leave certain spaces below <BODY> and then type </BODY> to close the body of your web page; 7. Type </HTML> in the next line and have the code vertically aligned with its opening tag to put an end to the html page. 8. In the line next to <BODY>, type <P><B>This is an XML Document on View! </B></P>. This line creates a sentence in your web page in bold. This help file does not teach html coding. Please check other sources for more help with html if you need. 9. Type <P><EM>It uses XSL Sheet</EM></P> in the next line. This sentence is in Italics in IE; 10. Type <P>These XML documents have been produced </P> and <P>using only NotePad and Internet Explorer v5.0 </P> in the next two lines. 11. Now you are ready to create a table in the web page.

3

12. Type <TABLE border="1"> and </TABLE> vertically and leave enough empty space in between for other code statements. Make sure </TABLE> is above </BODY>. 13. First, we need to create all the table column headings. Type <TR> to start a table row; 14. Leave certain space below and type </TR> to close the table row. 15. In between, type <TD><B>Cafe Type</B></TD> to create a first column heading; 16. Move to the next line to type <TD><B>Cafe Name</B></TD> for the second heading; 17. Move to the next line to type <TD><B>Food</B></TD> for the third heading; 18. Move to the next line to type <TD><B>Environment</B></TD> for the fourth heading; 19. Move to the next line to type <TD><B>Meal Cost</B></TD> for the fifth heading; 20. Move to the next line to type <TD><B>Comments</B></TD> for the last heading. 21. Move to the next line to type <xsl:for-each select="CAFES/CAFE"> to set up a loop to read through the CAFES/CAFE structure in the XML file; 22. Since the web page will use a table to display all the data records in the XML file, we will move through the web table structure. Type <TR> and move to the next line; 23. Type <TD><xsl:value-of select="@CAFE_TYPE"/></TD> and move to the next line. This XSL structure value-of select= is used to fetch the value of each individual CAFE element, such as CAFE_NAME and FOOD_QUALITY, and includes each in a table cell. This looping construct is fixed in length, irrespective of how many CAFE child structures are involved. 24. Type <TD><xsl:value-of select="CAFE_NAME"/></TD> and move to the next line; 25. Type <TD><xsl:value-of select="FOOD_QUALITY"/></TD> and move to the next line; 26. Type <TD><xsl:value-of select="ENVIRON"/></TD> and move to the next line; 27. Type <TD><xsl:value-of select="COST_RATING"/></TD> and move to the next line; 28. Type <TD><xsl:value-of select="COMMENTS"/></TD> and move to the next line. 29. Type </TR> to close the table row. So far we have specified that each web table row should read one data record from the XML file. 30. Type </xsl:for-each> to put an end to the loop. 31. The last thing is to close up all the open tags. Make sure you see </TABLE>, </BODY>, </HTML> in the next three lines; 32. Type </xsl:template> to close the XSL template and move to the next line; 33. Type </xsl:stylesheet> to close the style sheet. 34. Please remember that XML code is case sensitive. An upper cased letter is never the same as the lower cased same letter. And the select element name should be exactly the same as mentioned in your xml document. Please check both documents carefully. 35. Double click the XML document to run the files to see the effect. 36. For the last part on this assignment, please read the last paragraph of the assignment description and watch the video clip. ***********************************