PARSING AND MANIPULATING XML DATA ASSIGNMENT INSTRUCTIONS OVERVIEW XML is the basis for many interfaces and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
PARSING AND MANIPULATING XML DATA ASSIGNMENT INSTRUCTIONS OVERVIEW XML is the basis for many interfaces and web services. Consequently, reading and manipulating XML data is a common task in software development. INSTRUCTIONS An online plant distributor has recently experience a shortage in its supply of Anemone plants such that the price has increased by 20%. Their plant catalog is maintained in an XML file and they need a Python utility to find the plant by name, read the current price, change it by the specified percentage, and update the file. Writing this utility is your assignment. Using Python's ElementTree XML API, write a Python program to perform the following tasks below. Note that your program's execution syntax must be as follows: python xmlparse.py plant_catalog.xml plantName percentChange 1. Using ElementTree, read in this assignments XML file plant_catalog.xml specified by a command line parameter as shown above. 2. Find the plant by the name passed in as an argument on the command line (plantName above). 3. Once found, read the current price and adjust it by the command line argument percentChange. Note that this value could be anything in the range of -90 < percentChange < 100. For example, if you run your script as follows: python plant catalog.xml "Greek Valerian" -20 with the original XML containing: Greek Valerian Polemonium caeruleum Annual Shade 4.36 071499 The resulting file should contain: Greek Valerian Polemonium caeruleum Annual Shade 3.48 071499 CSIS 354 Note: You may reduce the precision of the calculation if you wish but it isn't required. Hints Since XML is just a text file, you could write the code to read all the data and the decode the XML information. However, I certainly don't recommend this approach. Instead, let Python do it for you! Using Python's ElementTree module, parse the file into an "in-memory" representation of the XML data. Once parsed, the root (or starting place) is as simple as requesting it from the tree. Once you have the root, you can call methods to find what you are looking for and modify them appropriately. You'll want to "findall" the plants and, "for" each plant "in" the result, you'll want to compare the name with the name passed on the command line. If you find a match you'll apply the percentage change, save the result back to the tree. When you are done with the search you will "write" the tree back to a file. I suggest using a different file name or you will be having to re-download the original with each run. One note of caution, be sure to read about XML in the Distributed Systems text. From doing so and reviewing the data file you will not that there are no attributes in the XML file. Consequently, you do not need to use attribute methods when you attempt this assignment. The following code snippet will give you a good starting point: # Calling arguments: plant_catalog.xml plantName percent Change import xml.etree. ElementTree as ET import sys #input parameters searchName = sys.argv[2] percent = float (sys.argv[3]) #parse XML data file tree = ET.parse(sys.argv[1]) root = tree.getroot () Test your code completely. At each step of the test take a screen shot and embed it into a Word document. Submit the Word document to the appropriate assignment. PARSING AND MANIPULATING XML DATA ASSIGNMENT INSTRUCTIONS OVERVIEW XML is the basis for many interfaces and web services. Consequently, reading and manipulating XML data is a common task in software development. INSTRUCTIONS An online plant distributor has recently experience a shortage in its supply of Anemone plants such that the price has increased by 20%. Their plant catalog is maintained in an XML file and they need a Python utility to find the plant by name, read the current price, change it by the specified percentage, and update the file. Writing this utility is your assignment. Using Python's ElementTree XML API, write a Python program to perform the following tasks below. Note that your program's execution syntax must be as follows: python xmlparse.py plant_catalog.xml plantName percentChange 1. Using ElementTree, read in this assignments XML file plant_catalog.xml specified by a command line parameter as shown above. 2. Find the plant by the name passed in as an argument on the command line (plantName above). 3. Once found, read the current price and adjust it by the command line argument percentChange. Note that this value could be anything in the range of -90 < percentChange < 100. For example, if you run your script as follows: python plant catalog.xml "Greek Valerian" -20 with the original XML containing: Greek Valerian Polemonium caeruleum Annual Shade 4.36 071499 The resulting file should contain: Greek Valerian Polemonium caeruleum Annual Shade 3.48 071499 CSIS 354 Note: You may reduce the precision of the calculation if you wish but it isn't required. Hints Since XML is just a text file, you could write the code to read all the data and the decode the XML information. However, I certainly don't recommend this approach. Instead, let Python do it for you! Using Python's ElementTree module, parse the file into an "in-memory" representation of the XML data. Once parsed, the root (or starting place) is as simple as requesting it from the tree. Once you have the root, you can call methods to find what you are looking for and modify them appropriately. You'll want to "findall" the plants and, "for" each plant "in" the result, you'll want to compare the name with the name passed on the command line. If you find a match you'll apply the percentage change, save the result back to the tree. When you are done with the search you will "write" the tree back to a file. I suggest using a different file name or you will be having to re-download the original with each run. One note of caution, be sure to read about XML in the Distributed Systems text. From doing so and reviewing the data file you will not that there are no attributes in the XML file. Consequently, you do not need to use attribute methods when you attempt this assignment. The following code snippet will give you a good starting point: # Calling arguments: plant_catalog.xml plantName percent Change import xml.etree. ElementTree as ET import sys #input parameters searchName = sys.argv[2] percent = float (sys.argv[3]) #parse XML data file tree = ET.parse(sys.argv[1]) root = tree.getroot () Test your code completely. At each step of the test take a screen shot and embed it into a Word document. Submit the Word document to the appropriate assignment.
Expert Answer:
Related Book For
Managerial Accounting Tools for Business Decision Making
ISBN: 978-1118856994
4th Canadian edition
Authors: Jerry J. Weygandt, Paul D. Kimmel, Donald E. Kieso, Ibrahim M. Aly
Posted Date:
Students also viewed these programming questions
-
QUIZ... Let D be a poset and let f : D D be a monotone function. (i) Give the definition of the least pre-fixed point, fix (f), of f. Show that fix (f) is a fixed point of f. [5 marks] (ii) Show that...
-
State carefully, with proof, the compositionality, soundness, and adequacy results for PCF. [6 marks] (ii) Define the notion of contextual equivalence in PCF. [2 marks] (You need not describe the...
-
Name four ways to mitigate the incentives for managers to overproduce.
-
Song Meister is a popular music store. During the current year, the company's cost of goods available for sale amounted to $330,000. The retail sales value of this merchandise amounted to $600,000....
-
Explain the approaches that can be used to reduce the dysfunctional consequences of short-term financial measures.
-
Reconsider the data from Problem 4. Management has expressed some concern over the life of the project and the impact of possible early termination. As a result, you have developed additional data...
-
For the following independent situations, assume that you are the audit partner on the engagement: 1. In the last 3 months of the current year, Oil Refining Company decided to change direction and go...
-
2. A muon is created in our upper atmosphere and travels toward the ground at 0.998 c. If it's lifetime is 2.2 x 10-6 seconds. What is the lifetime of the muon as observed by the earth's frame of...
-
On January 1, 2021, Stephanopoulos Inc. acquired 90% of Muir Co. by paying $450,000 cash. Muir Co. reported a Common Stock account balance of $130,000 and Retained Earnings of $270,000 at that date....
-
Use Java To write this code: Enter a numeric score - grade of a test, your program should print a corresponding lettergrade that matches the score. For example, if you enter 89.3, the program should...
-
Explain to the board of directors four economic conditions that can affect the cost of money raised from the financial market.
-
Based on the study of the S&P500 market in details 1- What is the significance of the S&P500 for the investors? 2- Discuss the capitalization for each company and the aggregate capitalization in...
-
Main question I have is: What are the 5 risk issues faced by the consultancy firms? Risk description of each issue mentioned? Who does it affect? (Social, economic, political etc) Who are the...
-
What essential classes are needed to establish a proxy server program in Java? [A proxy server acts as a mediator between the server and the client - all messages between the client and server passes...
-
Code is to be done in C. Consider an array of characters char arr[] and max length n. Write a program with a recursive function that generates and prints all possible password combinations created...
-
What is master production scheduling and how is it done?
-
Gomez Company has 2,000 kg of raw materials in its December 31, 2016, ending inventory . Required production for January and February is 5,000 and 6,000 units, respectively. Two kilograms of raw...
-
Pender has prepared the following list of statements about decision making and incremental analysis. 1. The first step in managements decision-making process is, Determine and evaluate possible...
-
Factory labour data for Sargunaraj Manufacturing are given in BE4-2. Manufacturing overhead is assigned to departments on the basis of 200% of labour costs. Journalize the assignment of overhead to...
-
Interview three heads of household, each from a household representing a different stage of the life cycle orsocioeconomic status. Inquire about their financial planning process and their strategies...
-
Jimmy, an accountant, and Bethany just returned from their honeymoon in the Bahamas. They celebrated their marriage and the completion of Bethany's M.B.A. program. They have been encouraged by their...
-
Review the six financial accomplishments that may result from studying personal finance. In your opinion, which three are most important? Why?
Study smarter with the SolutionInn App