15.11. Write Code QuestionsΒΆ

Click on the button below to see the contents of books.xml. It contains xml tags to define the books in a bookstore.

Data file: books.xml



  
    Everyday Italian
    Giada De Laurentiis
    2005
    30.00
  

  
    Harry Potter
    J K. Rowling
    2005
    29.99
  

  
    XQuery Kick Start
    James McGovern
    Per Bothner
    Kurt Cagle
    James Linn
    Vaidyanathan Nagarajan
    2003
    49.99
  

  
    Learning XML
    Erik T. Ray
    2003
    39.95
  

Fix the errors in the code below so that it reads the data from books.xml and finds all of the book data and prints the title for each book and then finds all the author names for each book and prints each author name.

Click on the button below to see the contents of news.xml. It contains xml tags to define news stories.

Data file: news.xml


  
    Colombia Earthquake
  
  
    
      143 Dead in Colombia Earthquake
    
    
      By Jared Kotler, Associated Press Writer
    
    
      Bogota, Colombia
      Monday January 25 1999 7:28 ET
    
  

Fix the errors in the code below so that it reads the data from news.xml and prints the headline and date.

Click on the button below to see the contents of weather.xml. It contains xml tags to define weather observations.

Data file: weather.xml



NOAA's National Weather Service
http://weather.gov/


  http://weather.gov/images/xml_logo.gif
  NOAA's National Weather Service
  http://weather.gov


New York/John F. Kennedy Intl Airport, NY
KJFK
40.66
-73.78
Mon, 11 Feb 2008 06:51:00 -0500 EST


A Few Clouds
11
-12
36
West
280
18.4
29
1023.6
30.23
-11
-24
-7
-22
10.00

http://weather.gov/weather/images/fcicons/
nfew.jpg
http://weather.gov/disclaimer.html
http://weather.gov/disclaimer.html

Finish the code below so that it reads the data from weather.xml into a tree and then prints the location, temp_f, and windchill_f for the current_observation.

The file email.json below contains JSON data for people including their first_name, last_name and email address.

Data file: email.json
[{
  "id": 1,
  "first_name": "Jeanette",
  "last_name": "Penddreth",
  "email": "jpenddreth0@census.gov",
  "gender": "Female",
  "ip_address": "26.58.193.2"
}, {
  "id": 2,
  "first_name": "Giavani",
  "last_name": "Frediani",
  "email": "gfrediani1@senate.gov",
  "gender": "Male",
  "ip_address": "229.179.4.212"
}, {
  "id": 3,
  "first_name": "Noell",
  "last_name": "Bea",
  "email": "nbea2@imageshack.us",
  "gender": "Female",
  "ip_address": "180.66.162.255"
}, {
  "id": 4,
  "first_name": "Willard",
  "last_name": "Valek",
  "email": "wvalek3@vk.com",
  "gender": "Male",
  "ip_address": "67.76.188.26"
}]

Finish the code below so that it prints the first name, last name and email address for each person in the list of dictionaries returned from json.loads(data).

The file person3.json below contains JSON data for a person in a dictionary including their first name, last name, address, and phone numbers.

Data file: person3.json
{
  "firstName": "John",
  "lastName": "Smith",
  "isAlive": true,
  "age": 27,
  "address": {
    "streetAddress": "21 2nd Street",
    "city": "New York",
    "state": "NY",
    "postalCode": "10021-3100"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "mobile",
      "number": "123 456-7890"
    }
  ],
  "children": [],
  "spouse": null
}

Finish the code below so that it prints the first name, last name, the state the person lives in, and their mobile phone number from the JSON loaded from person3.json.

You have attempted of activities on this page