Lab 3

Part 1 dict to XML and back

  1. Creat a working directory lab3 and download the source files from Lab3 Tutorial folder. Import all files into Eclipse.
  2. install dicttoxml and test run "filep9.py"

    • Shift+Right-Click to start Windows PowerShell in the directory created
    • type "pip install dicttoxml"
    • type "python filep9.py"
    • open "client.xml" with "Notepad" and your browser, explain the difference you see.

  3. install xmltodict, print data in JSON, and creat a list of dictionary from client.xml

    • type "pip install xmltodict" in command prompt
    • In Eclipse, copy and paste the following program to create a new module:
      
      import xmltodict
      import json
      import urllib.request
      fileIn=urllib.request.urlopen('http://personal.cityu.edu.hk/~dcywchan/1718SemB121COM/client.xml')
      
      byteStr = fileIn.read()
      lines=byteStr.decode('utf-8')
      dl=xmltodict.parse(lines)
      
      print(json.dumps(dl,indent=4))
          
      newdl=[]
      
      for e in dl['root']['item']:
          tmpdl={}
          for key,value in e.items():
              if key != "@type":
                  value=value["#text"]
                  tmpdl.update({key:value})
                  
          newdl.append(tmpdl)
      
      #print out dictionary list created
      
      
    • complete the programe to see the dictionary list created

Part 2 Programming exercises.

  1. Download (i.e. Pull) the following repository from GitHub:

    https://github.com/SCOPEterenceChan/CHK121COMlab3q1SimpleBillingFromXML.

    Dissect and modify the code to add header, block, and inline comment to the program. After each modification, test if the program is running correctly and do version control in your local repository with Git.

  2. Given the above programs to process XML data. Write a program to use daily forex rate in XML format published by the European Central Bank (ECB).

    http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml

    The program will prompt user for Currency Code and output today currency rate. For example, when user enters "CNY", the program will print

    "On 2018-02-20 3pm Central European Time, One euro is 7.8290 CNY (CHINA RENMINBI)" as output.

    Special drawing rights (XDR) is not an actual currency. However, it is used to define value for various purposes by organisations like the International Monetary Fund. It is defined as:

    1 XDR = 0.423 Euros + 12.1 Japanese Yen + 0.111 British Pounds + 0.66 US Dollars.

    Your program should support XDR as a currency.

Part 3 Project Assignment

  1. There are lot of XML datasets and API available from DATA.GOV.HK Using the business your team has chosen, evaluate these datasets/API, their use, and relevance of the XML/API and how it would benefit for the business in one of these areas:
    • Competitiveness
    • Marketing
    • Efficiency
    • Process Improvement
    • Value for its Customer
    • Business Intelligence

  2. Write a a simple search and list function to make use of the dataset/API.