SlideShare a Scribd company logo
1 of 9
Download to read offline
Homework: XML Exercise

1. Objectives

   •   Become familiar with the DOM paradigm;

   •   Use an existing XML parser;

   •   Transform the content of an XML document into an HTML page containing a
       widget.



2. Description

You are required to write an HTML/JavaScript program, which takes the URL of an
XML document containing the final results of selected sports at the 2008 Olympic
Games, parses the XML file, and displays results in an HTML document. The resulting
HTML document will display a collapsible accordion widget with titles of different
sports events. Clicking on a title will display information about the winner of the event in
an HTML table along with a picture and a video related to the event or the athlete from
youtube.com. The JavaScript program will be implemented by embedding it in a HTML
file, so that it can be executed within a browser. You will use jquery library to implement
the widget.

   •   Your program should display a widget with names of the different events listed as
       menu items.

   •   When the page loads, it would call an HTML/JavaScript function within the
       HTML file that parses the XML document given as an input.

   •   After parsing the XML document, a widget should be displayed consisting of
       names of the sports events, read from the XML document, listed as menu items.
       For example, given the following XML document:

        http://www-scf.usc.edu/~csci571/2009Fall/hw4/Swimming.xml

       your program should produce the web page shown in Figure 1 below.




                                                                                          1
Figure 1.   Resulting web page




•   After clicking any menu item, a table should be displayed under the menu item
    containing the details of the event winner including the name of the event winner,
    winner’s country, the final timing of the event, the picture of the athlete and a
    youtube.com video embedded in the last row of the table as shown in Figure 2.
    The data shown in the table cells and the URLs for the pictures and the videos are
    to be read from the XML document. You will have to embed the video in the
    HTML page. See Section 3, Step 5 for details about embedding a YouTube video
    in a webpage.


                                                                                    2
Figure 2. Table Containing Details of the Event After Clicking the Event Title in Accordion Menu




•     If another menu item is clicked, the table containing details of the event should be
      shown under it. This action should not affect the state of any other menu item.
      That is, if any other menu item is in expanded state (showing the table of details
      below it), it should maintain its state as shown in Figure 3.

•     Clicking on the menu item in expanded state should result in collapsing it.

•     You should use the XML DOM Parser that comes as a built-in component in both
      IE and Firefox to parse and validate the XML document. Your code can assume



                                                                                                       3
that the XML files your program will process will be structured as a “two level
    tree” as described in Section 3, Step 1.

•   If the XML file is invalid (e.g. missing the closing tag or having tags that
    overlap), an error message should be generated as shown in Figure 4.




                      Figure 3. Multiple menu items in expanded state




                                                                                 4
In case of a parsing error, your program should show the following web page:




                              Figure 4. Page generated from error.xml

For example, the error above is displayed when parsing the file:

   http://www-scf.usc.edu/~csci571/2009Fall/hw4/error.xml

Since Firefox DOM implementations do not contain the parseError object, you should
show an alert box if the XML file is not valid, as shown in the following Figure 5:




                       Figure 5. Error generated from error.xml in Firefox




3. Hints

   •   Step 1: Writing Your HTML/JavaScript program - Using the DOM Parser

       IE and Firefox have a built-in DOM parser. Microsoft DOM implementation is
       part of Microsoft XML Core Services (MSXML). An introduction to the
       Microsoft DOM can be found at:

       http://msdn.microsoft.com/library/default.asp?url=/library/en-
       us/xmlsdk/html/a09c098b-7e5a-45ff-b5ad-bc910f736a3f.asp



                                                                                      5
The set of DOM enumerated constants can be found at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/xmlsdk/html/e94d1cdf-3d7f-4ac0-8c51-a17d2801519c.asp

Please note that since the MS XML parser does not define the DOM constants as
in Node.ELEMENT_NODE, you will have to define them in your code, as in:

ELEMENT_NODE = 1;

The set of DOM properties, methods and events can be found at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/xmlsdk/html/d051f7c5-e882-42e8-a5b6-d1ce67af275c.asp


Here's how you could use the Microsoft DOM API and the Mozilla DOM API
used in Firefox to load and parse an XML document into a DOM tree, and then
use the DOM API to extract information from that document.
  <script LANGUAGE=JavaScript>
  //create an instance of the XML parser
  if (window.ActiveXObject){    //Checking if the browser is IE
             var xmlDoc = new ActiveXObject("Microsoft.XMLDOM")
             xmlDoc.async="false"            //make sure doc is fully loaded
             xmlDoc.load(filename) //load the file in the parser
       if (xmlDoc.parseError.errorCode != 0) {
             var myError = xmlDoc.parseError;
             alert("You have error " + myError.reason);
       } else {
             // ....... processing the document goes here
             alert(xmlDoc.xml);
       }
                          }
  else if (document.implementation && document.implementation.createDocument)//for
  mozilla based browsers
   {
     var xmlDoc= document.implementation.createDocument("","doc",null); // NS
     xmlDoc.async=false; //make sure doc is fully loaded
     loaded = xmlDoc.load(URL);
   if(!loaded){
                     alert(“Error”);
                      }
              else
                     {
                     alert(xmlDoc.xml);
                     }
   }
  </script>




Now you can generate the widget from the DOM tree. You must make sure to
write your program so it does not explicitly make use of the tag names in the
sample XML file mentioned above. Instead, your program should assume that the
XML files that your program will process will be structured as a three level tree
with the following format:




                                                                                 6
<Results>

       <event>
              <name> . . . </name>
              <winner> . . . </winner>
              <country> . . .</country>
              <final>. . . </final>
              <picture>. . . </picture>
              <video>. . . </video>
        </event>
        . . .
        <event>
              <name> . . . </name>
              <winner> . . . </winner>
              <country> . . .</country>
              <final>. . . </final>
              <picture>. . . </picture>
              <video>. . . </video>
        </event>

       . . .
  </Results>

Your task is to write a program that transforms this structure into the widget,
where first level tags contain the events, the first tag at the second level for each
event will have the name of the event in the tag name,
e.g.<name>Swimming</name>. All the tags appearing at the second level
<name>, <winner>, <country>, <final>, <picture> and <video> are fixed and
your program may assume that in a certain XML document, the entries at level 2
are always in the same order, and that no entries are missing. However, you do
not know how many records of events may occur in the file. When producing the
output, your program should use the tag names “name”, “winner”, “country”,
“final” and “picture” as the table headers as shown in Figure 2. Please note, the
headers should be dynamically populated from the XML file tags and not from
some constant strings written in the code. Please also note that after clicking the
menu items the tables should be updated dynamically and no page refresh should
occur.

You can access the child nodes of the documents as follows:

  mynodes=xmlDoc.documentElement.childNodes;

Note that unlike the Java-based DOM, which provides methods such as
getChildNodes() and getNodeType() that return a node list of children of a
current node and the type of a node respectively, with the DOM you have to
access the element properties directly, as in:

  myNodeList= mynodes.item(i).childNodes;
  if (myNodeList.item(j).nodeType==ELEMENT_NODE)




                                                                                    7
•   Step 2: Display the Resulting HTML Document

    You should use the DOM document.getElementById(' ').innerHTML method
    to produce the required HTML, as in:

      html_text="<html><head><title>XML Result</title></head><body>";
     document.getElementById('IDofDiv').innerHTML=html_text;
•   Step 3: Use JavaScript control syntax

    The only program control statements that you will need to use for this exercise are
    the “if”, the “for” and some basic string manipulation statements. The syntax of
    both “if” and “for” statements is practically identical to the syntax of the
    corresponding statement in the C, C++ and Java languages, as in:

      if(xmlDoc.documentElement.hasChildNodes()) {
          // do stuff
      }
      for (j=0;j<albumNodeList.length;j++) {
          // do more stuff
      }

•   Step 4: Use JQuery to make widget
•
       The documentation for jquery can be found at http://jquery.com or at
    http://www-scf.usc.edu/~csci571/Slides/jQueryTutorial.ppt. Jquery has its own UI
    library that has multiple widgets in it including the accordion widget. In this
    exercise you will NOT use jquery UI library, but make the widget
    programmatically. You will need to include the basic jquery library in your page
    to make the widget work. You should download the library from
    http://jquery.com and include it in your page. One way to include the library and
    the JavaScript code in your page is as follows:
     <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                    <title>Assignment 4</title>

           <link type="text/css" href="default.css" rel="stylesheet" />
           <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
           <script type="text/javascript">
    $(function(){ // This functions executes when the page has loaded completely

      Your jquery and other javascript code goes here

           });
          </script>
     </head>
        You just need a few jquery functions to make the widget work. Please look up
    the jquery documentation for hide , toggle, slidetoggle(“slow”), removeclass and


                                                                                     8
addclass functions. The whole widget functionality can be achieved by writing
        less than 10 lines of code.

        You can write your own CSS file or use the default.css available at

       http://www-scf.usc.edu/~csci571/2009Fall/hw4/default.css

       The images maximize.png and minimize.png can be downloaded from:

       http://www-scf.usc.edu/~csci571/2009Fall/hw4/images/maximize.png

         and

       http://www-scf.usc.edu/~csci571/2009Fall/hw4/images/minimize.png


   •    Embedding a YouTube video in the html document

        To show a YouTube video, the webpage should contain the following embedding
        code:

        <object width="425" height="344"><param name="movie"
        value="URL"></param><param name="allowFullScreen"
        value="true"></param><embed src="URL" type="application/x-
        shockwave-flash" allowfullscreen="true" width="425"
        height="344"></embed></object>

        where URL in both value and src values should be replaced by the URL contained
        in the <video> tag of the XML document.


   •    Handling of White Spaces in DOM in Firefox

        Note, that white spaces are handled differently in Firefox as compared to IE.
        Below is the link to the web page that demonstrates how to handle white spaces in
        Mozilla:

         http://developer.mozilla.org/en/docs/Whitespace_in_the_DOM

4. Material You Need to Submit

Complete URLs to both olympics.xml and error.xml are given in Section 2. On your
course homework page, your link for this homework should go to a page that looks like
the one displayed in Figure 1. This page should include your entire JavaScript/HTML
program in a single file. Also you should ‘submit’ your source code and a README file
electronically to the csci571 account, so that it can be graded and compared to all other
students' code via the MOSS code comparison tool.




                                                                                       9

More Related Content

What's hot (8)

Database development connection steps
Database development connection stepsDatabase development connection steps
Database development connection steps
 
Prep 2-booklet-2nd-term-2016-2017
Prep 2-booklet-2nd-term-2016-2017Prep 2-booklet-2nd-term-2016-2017
Prep 2-booklet-2nd-term-2016-2017
 
Develop magento 2 custom shipping module
Develop magento 2 custom shipping moduleDevelop magento 2 custom shipping module
Develop magento 2 custom shipping module
 
Unit 2.10 - Frames
Unit 2.10 - FramesUnit 2.10 - Frames
Unit 2.10 - Frames
 
Prep 1 second term new booooklet last
Prep 1 second term new booooklet lastPrep 1 second term new booooklet last
Prep 1 second term new booooklet last
 
AIESEC CMS - User guide
AIESEC CMS - User guideAIESEC CMS - User guide
AIESEC CMS - User guide
 
CRUD with Dojo
CRUD with DojoCRUD with Dojo
CRUD with Dojo
 
Basic Crud In Django
Basic Crud In DjangoBasic Crud In Django
Basic Crud In Django
 

Viewers also liked

Viewers also liked (6)

tutorial2-notes2
tutorial2-notes2tutorial2-notes2
tutorial2-notes2
 
wtst3_pettichord3
wtst3_pettichord3wtst3_pettichord3
wtst3_pettichord3
 
collapsible-panels-tutorial
collapsible-panels-tutorialcollapsible-panels-tutorial
collapsible-panels-tutorial
 
Ad-journal
Ad-journalAd-journal
Ad-journal
 
INFS730
INFS730INFS730
INFS730
 
newsletter84
newsletter84newsletter84
newsletter84
 

Similar to hw4_specifications

Cliw - extension development
Cliw -  extension developmentCliw -  extension development
Cliw - extension development
vicccuu
 
Creating xml publisher documents with people code
Creating xml publisher documents with people codeCreating xml publisher documents with people code
Creating xml publisher documents with people code
Randall Groncki
 
C:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse InfocenterC:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse Infocenter
Suite Solutions
 
For this project your task is to update the RSS Reader program you w.pdf
For this project your task is to update the RSS Reader program you w.pdfFor this project your task is to update the RSS Reader program you w.pdf
For this project your task is to update the RSS Reader program you w.pdf
fathimahardwareelect
 
1 Web Page Foundations Overview This lab walk.docx
1  Web Page Foundations Overview This lab walk.docx1  Web Page Foundations Overview This lab walk.docx
1 Web Page Foundations Overview This lab walk.docx
honey725342
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08
Niit Care
 

Similar to hw4_specifications (20)

Creating a basic joomla
Creating a basic joomlaCreating a basic joomla
Creating a basic joomla
 
treeview
treeviewtreeview
treeview
 
treeview
treeviewtreeview
treeview
 
Cliw - extension development
Cliw -  extension developmentCliw -  extension development
Cliw - extension development
 
New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectors
 
Creating xml publisher documents with people code
Creating xml publisher documents with people codeCreating xml publisher documents with people code
Creating xml publisher documents with people code
 
Firefox addons
Firefox addonsFirefox addons
Firefox addons
 
Debugging in net_sim
Debugging in net_simDebugging in net_sim
Debugging in net_sim
 
C:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse InfocenterC:\Users\User\Desktop\Eclipse Infocenter
C:\Users\User\Desktop\Eclipse Infocenter
 
Dojo1.0_Tutorials
Dojo1.0_TutorialsDojo1.0_Tutorials
Dojo1.0_Tutorials
 
Dojo1.0_Tutorials
Dojo1.0_TutorialsDojo1.0_Tutorials
Dojo1.0_Tutorials
 
Oracle Endeca Developer's Guide
Oracle Endeca Developer's GuideOracle Endeca Developer's Guide
Oracle Endeca Developer's Guide
 
For this project your task is to update the RSS Reader program you w.pdf
For this project your task is to update the RSS Reader program you w.pdfFor this project your task is to update the RSS Reader program you w.pdf
For this project your task is to update the RSS Reader program you w.pdf
 
1 Web Page Foundations Overview This lab walk.docx
1  Web Page Foundations Overview This lab walk.docx1  Web Page Foundations Overview This lab walk.docx
1 Web Page Foundations Overview This lab walk.docx
 
Rancangan Jaringan Komputer
Rancangan Jaringan KomputerRancangan Jaringan Komputer
Rancangan Jaringan Komputer
 
Introduction Dojo Toolkit & IBM Lotus Domino
Introduction Dojo Toolkit & IBM Lotus DominoIntroduction Dojo Toolkit & IBM Lotus Domino
Introduction Dojo Toolkit & IBM Lotus Domino
 
04 sm3 xml_xp_08
04 sm3 xml_xp_0804 sm3 xml_xp_08
04 sm3 xml_xp_08
 
Expanding XPages with Bootstrap Plugins for Ultimate Usability
Expanding XPages with Bootstrap Plugins for Ultimate UsabilityExpanding XPages with Bootstrap Plugins for Ultimate Usability
Expanding XPages with Bootstrap Plugins for Ultimate Usability
 
Creating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisherCreating reports in oracle e business suite using xml publisher
Creating reports in oracle e business suite using xml publisher
 
Pinnacle Cart Design documentation v1.0
Pinnacle Cart Design documentation v1.0Pinnacle Cart Design documentation v1.0
Pinnacle Cart Design documentation v1.0
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

hw4_specifications

  • 1. Homework: XML Exercise 1. Objectives • Become familiar with the DOM paradigm; • Use an existing XML parser; • Transform the content of an XML document into an HTML page containing a widget. 2. Description You are required to write an HTML/JavaScript program, which takes the URL of an XML document containing the final results of selected sports at the 2008 Olympic Games, parses the XML file, and displays results in an HTML document. The resulting HTML document will display a collapsible accordion widget with titles of different sports events. Clicking on a title will display information about the winner of the event in an HTML table along with a picture and a video related to the event or the athlete from youtube.com. The JavaScript program will be implemented by embedding it in a HTML file, so that it can be executed within a browser. You will use jquery library to implement the widget. • Your program should display a widget with names of the different events listed as menu items. • When the page loads, it would call an HTML/JavaScript function within the HTML file that parses the XML document given as an input. • After parsing the XML document, a widget should be displayed consisting of names of the sports events, read from the XML document, listed as menu items. For example, given the following XML document: http://www-scf.usc.edu/~csci571/2009Fall/hw4/Swimming.xml your program should produce the web page shown in Figure 1 below. 1
  • 2. Figure 1. Resulting web page • After clicking any menu item, a table should be displayed under the menu item containing the details of the event winner including the name of the event winner, winner’s country, the final timing of the event, the picture of the athlete and a youtube.com video embedded in the last row of the table as shown in Figure 2. The data shown in the table cells and the URLs for the pictures and the videos are to be read from the XML document. You will have to embed the video in the HTML page. See Section 3, Step 5 for details about embedding a YouTube video in a webpage. 2
  • 3. Figure 2. Table Containing Details of the Event After Clicking the Event Title in Accordion Menu • If another menu item is clicked, the table containing details of the event should be shown under it. This action should not affect the state of any other menu item. That is, if any other menu item is in expanded state (showing the table of details below it), it should maintain its state as shown in Figure 3. • Clicking on the menu item in expanded state should result in collapsing it. • You should use the XML DOM Parser that comes as a built-in component in both IE and Firefox to parse and validate the XML document. Your code can assume 3
  • 4. that the XML files your program will process will be structured as a “two level tree” as described in Section 3, Step 1. • If the XML file is invalid (e.g. missing the closing tag or having tags that overlap), an error message should be generated as shown in Figure 4. Figure 3. Multiple menu items in expanded state 4
  • 5. In case of a parsing error, your program should show the following web page: Figure 4. Page generated from error.xml For example, the error above is displayed when parsing the file: http://www-scf.usc.edu/~csci571/2009Fall/hw4/error.xml Since Firefox DOM implementations do not contain the parseError object, you should show an alert box if the XML file is not valid, as shown in the following Figure 5: Figure 5. Error generated from error.xml in Firefox 3. Hints • Step 1: Writing Your HTML/JavaScript program - Using the DOM Parser IE and Firefox have a built-in DOM parser. Microsoft DOM implementation is part of Microsoft XML Core Services (MSXML). An introduction to the Microsoft DOM can be found at: http://msdn.microsoft.com/library/default.asp?url=/library/en- us/xmlsdk/html/a09c098b-7e5a-45ff-b5ad-bc910f736a3f.asp 5
  • 6. The set of DOM enumerated constants can be found at: http://msdn.microsoft.com/library/default.asp?url=/library/en- us/xmlsdk/html/e94d1cdf-3d7f-4ac0-8c51-a17d2801519c.asp Please note that since the MS XML parser does not define the DOM constants as in Node.ELEMENT_NODE, you will have to define them in your code, as in: ELEMENT_NODE = 1; The set of DOM properties, methods and events can be found at: http://msdn.microsoft.com/library/default.asp?url=/library/en- us/xmlsdk/html/d051f7c5-e882-42e8-a5b6-d1ce67af275c.asp Here's how you could use the Microsoft DOM API and the Mozilla DOM API used in Firefox to load and parse an XML document into a DOM tree, and then use the DOM API to extract information from that document. <script LANGUAGE=JavaScript> //create an instance of the XML parser if (window.ActiveXObject){ //Checking if the browser is IE var xmlDoc = new ActiveXObject("Microsoft.XMLDOM") xmlDoc.async="false" //make sure doc is fully loaded xmlDoc.load(filename) //load the file in the parser if (xmlDoc.parseError.errorCode != 0) { var myError = xmlDoc.parseError; alert("You have error " + myError.reason); } else { // ....... processing the document goes here alert(xmlDoc.xml); } } else if (document.implementation && document.implementation.createDocument)//for mozilla based browsers { var xmlDoc= document.implementation.createDocument("","doc",null); // NS xmlDoc.async=false; //make sure doc is fully loaded loaded = xmlDoc.load(URL); if(!loaded){ alert(“Error”); } else { alert(xmlDoc.xml); } } </script> Now you can generate the widget from the DOM tree. You must make sure to write your program so it does not explicitly make use of the tag names in the sample XML file mentioned above. Instead, your program should assume that the XML files that your program will process will be structured as a three level tree with the following format: 6
  • 7. <Results> <event> <name> . . . </name> <winner> . . . </winner> <country> . . .</country> <final>. . . </final> <picture>. . . </picture> <video>. . . </video> </event> . . . <event> <name> . . . </name> <winner> . . . </winner> <country> . . .</country> <final>. . . </final> <picture>. . . </picture> <video>. . . </video> </event> . . . </Results> Your task is to write a program that transforms this structure into the widget, where first level tags contain the events, the first tag at the second level for each event will have the name of the event in the tag name, e.g.<name>Swimming</name>. All the tags appearing at the second level <name>, <winner>, <country>, <final>, <picture> and <video> are fixed and your program may assume that in a certain XML document, the entries at level 2 are always in the same order, and that no entries are missing. However, you do not know how many records of events may occur in the file. When producing the output, your program should use the tag names “name”, “winner”, “country”, “final” and “picture” as the table headers as shown in Figure 2. Please note, the headers should be dynamically populated from the XML file tags and not from some constant strings written in the code. Please also note that after clicking the menu items the tables should be updated dynamically and no page refresh should occur. You can access the child nodes of the documents as follows: mynodes=xmlDoc.documentElement.childNodes; Note that unlike the Java-based DOM, which provides methods such as getChildNodes() and getNodeType() that return a node list of children of a current node and the type of a node respectively, with the DOM you have to access the element properties directly, as in: myNodeList= mynodes.item(i).childNodes; if (myNodeList.item(j).nodeType==ELEMENT_NODE) 7
  • 8. Step 2: Display the Resulting HTML Document You should use the DOM document.getElementById(' ').innerHTML method to produce the required HTML, as in: html_text="<html><head><title>XML Result</title></head><body>"; document.getElementById('IDofDiv').innerHTML=html_text; • Step 3: Use JavaScript control syntax The only program control statements that you will need to use for this exercise are the “if”, the “for” and some basic string manipulation statements. The syntax of both “if” and “for” statements is practically identical to the syntax of the corresponding statement in the C, C++ and Java languages, as in: if(xmlDoc.documentElement.hasChildNodes()) { // do stuff } for (j=0;j<albumNodeList.length;j++) { // do more stuff } • Step 4: Use JQuery to make widget • The documentation for jquery can be found at http://jquery.com or at http://www-scf.usc.edu/~csci571/Slides/jQueryTutorial.ppt. Jquery has its own UI library that has multiple widgets in it including the accordion widget. In this exercise you will NOT use jquery UI library, but make the widget programmatically. You will need to include the basic jquery library in your page to make the widget work. You should download the library from http://jquery.com and include it in your page. One way to include the library and the JavaScript code in your page is as follows: <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Assignment 4</title> <link type="text/css" href="default.css" rel="stylesheet" /> <script type="text/javascript" src="js/jquery-1.3.2.min.js"></script> <script type="text/javascript"> $(function(){ // This functions executes when the page has loaded completely Your jquery and other javascript code goes here }); </script> </head> You just need a few jquery functions to make the widget work. Please look up the jquery documentation for hide , toggle, slidetoggle(“slow”), removeclass and 8
  • 9. addclass functions. The whole widget functionality can be achieved by writing less than 10 lines of code. You can write your own CSS file or use the default.css available at http://www-scf.usc.edu/~csci571/2009Fall/hw4/default.css The images maximize.png and minimize.png can be downloaded from: http://www-scf.usc.edu/~csci571/2009Fall/hw4/images/maximize.png and http://www-scf.usc.edu/~csci571/2009Fall/hw4/images/minimize.png • Embedding a YouTube video in the html document To show a YouTube video, the webpage should contain the following embedding code: <object width="425" height="344"><param name="movie" value="URL"></param><param name="allowFullScreen" value="true"></param><embed src="URL" type="application/x- shockwave-flash" allowfullscreen="true" width="425" height="344"></embed></object> where URL in both value and src values should be replaced by the URL contained in the <video> tag of the XML document. • Handling of White Spaces in DOM in Firefox Note, that white spaces are handled differently in Firefox as compared to IE. Below is the link to the web page that demonstrates how to handle white spaces in Mozilla: http://developer.mozilla.org/en/docs/Whitespace_in_the_DOM 4. Material You Need to Submit Complete URLs to both olympics.xml and error.xml are given in Section 2. On your course homework page, your link for this homework should go to a page that looks like the one displayed in Figure 1. This page should include your entire JavaScript/HTML program in a single file. Also you should ‘submit’ your source code and a README file electronically to the csci571 account, so that it can be graded and compared to all other students' code via the MOSS code comparison tool. 9