Datasheet

<city>
<name>London</name>
<temperature><min>31</min><max>45</max></temperature>
</city>
<city>
<name>Paris</name>
<temperature><min>20</min><max>74</max></temperature>
</city>
</WeatherForecast>
This next XML document also contains <name> elements but those names are of countries and not of
cities. Adding these two XML documents together could cause a semantic (meaning) conflict between
the
<name> elements in the two separate XML documents:
<?xml version=”1.0”?>
<WeatherForecast date=”2/1/2004”>
<country>
<name>Germany</name>
<temperature><min>22</min><max>45</max></temperature>
</country>
<country>
<name>England</name>
<temperature><min>24</min><max>39</max></temperature>
</country>
<country>
<name>France</name>
<temperature><min>22</min><max>85</max></temperature>
</country>
</WeatherForecast>
Namespaces can be used to resolve this type of conflict by assigning a separate prefix to each XML docu-
ment, adding the prefix to tags in each XML document as follows for the XML document containing
cities:
<?xml version=”1.0”?>
<i:WeatherForecastxmlns:i=”http://www.mywebsite.com/nsforcities” date=”2/1/2004”>
<i:city>
<i:name>Frankfurt</i:name>
<i:temperature><i:min>43</i:min><i:max>52</i:max></i:temperature>
</i:city>
<i:city>
<i:name>London</i:name>
<i:temperature><i:min>31</i:min><i:max>45</i:max></i:temperature>
</i:city>
<i:city>
<i:name>Paris</i:name>
<i:temperature><i:min>20</i:min><i:max>74</i:max></i:temperature>
</i:city>
</i:WeatherForecast>
25
What Is XML?
04_791202 ch01.qxp 10/6/06 10:59 AM Page 25