Exercise 3: Create An XML File: Step 1: One Day's Forecast
Exercise 3: Create An XML File: Step 1: One Day's Forecast
In this exercise, you will create an XML file. Refer to Lecture 3 for tools that you can use to do
this. For this exercise, you will create XML that captures weather forecast data, much like what
you documented in Exercise 2 for JSON.
The top level element will be called dailyForecast, so let's create an opening and ending tag for
it:
</dailyForecast>
Inside the dailyForecast element, let's add an element called "date". Its value will be
2015-06-01.
Next, add a description element with content of "sunny". It will look like this:
Now, add a maxTemp element for the high temperature forecast for that day. We can use an
attribute called "unit" with a value of "C" to say that it's in degrees Celsius. Have the maximum
temperature be 22.
Take your finished XML and paste it into a XML formatter at:
http://www.freeformatter.com/xml-formatter.html.
This will validate that the XML is the correct syntax and if it is, the it will show you what your
XML will look like when nicely formatted.
Finally, compare your XML to what I came up with at: http://sdkbridge.com/ud/oneday.xml. Note
that your browser may format the XML and not show you the very first line.
</forecast>
Copy and paste your Monday forecast into the array. Indent it properly (either with the XML
formatter, or by hand.)
(Where the … is, you will have the rest of your Step 1 XML file. But not the first line, since you
already have that one.)
Now, copy the dailyForecast element and paste it below so that you have a second one.
Change the values on the second element so that the date is 2015-06-02, the description is
"windy", the wind speed is 40, and danger is true.
Finally, add a third object in the array for the next day. But let's say that we were unable to get
the forecast, so the element is empty. See if you can remember how to do the shortcut that
shows the element is empty without having to use an end tag.
Finally (and don't peek until you've really tried to figure it out), compare it to mine:
http://sdkbridge.com/ud/threeday.xml
Again, your browser may format the XML and not show you the very first line.