The XML (eXtensible Markup Language) is a common format used to
structure and store data on the web. The following is a small sample XML
file that could be used to store names in an address book. Type it in using
a text editor and save it to a file named address.xml (or find it on the
accompanying CD). (continued)
<?xml version="1.0"?>
<address_book>
<contact>
<name>George Clooney</name>
<street>1042 El Camino Real</street>
<city>Beverly Hills</city>
<state>CA</state>
<zip>90214</zip>
</contact>
<contact>
<name>Cathy Pearl</name>
<street>405 A St.</street>
<city>Palmdale</city>
<state>CA</state>
<zip>93352</zip>
</contact>
<contact>
<name>Paris Hilton</name>
<street>200 S. Elm St.</street>
<city>Beverly Hills</city>
<state>CA</state>
<zip>90212</zip>
</contact>
<contact>
<name>Wendy Jones</name>
<street>982 Boundary Ave.</street>
<city>Palmdale</city>
<state>CA</state>
<zip>93354</zip>
</contact>
The sample file contains four contacts. The <> tag denotes the start of a
field and the </> tag denotes the end of the field.
a) You are hosting a party in Palmdale, CA. Write a program that reads in
the address.xml file and outputs the names and addresses of everyone
in Palmdale. Your program shouldn’t output any of the tag information,
just the address content.
b) You would like to send an advertising flyer to everyone in zip codes
90210 through 90214. Write a program that reads in the address.xml
file and outputs the names and addresses of everyone whose zip code
falls within the specified range.
You may assume that each contact in the address file has the same
structure and the same fields. However, your solution should be able to
handle an input file with any number of contacts and should not assume
that the fields within each contact are in the same order.
Sorry the answer is not available at the moment…
If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.
Spread the 'tradition of sharing'.