现实生活中的 XML

一个现实生活中的例子,向您展示 XML 如何携带数据。

实例: XML 新闻

XMLNews 是用于交换新闻和其他信息的规范。

对新闻的供求双方来说,通过使用这种标准,可以使各种类型的新闻信息通过不同软硬件以及编程语言进行的制作、接收和存档更加容易。

一个 XMLNews 文档实例:

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2.  
  3. <nitf>
  4.  
  5. <head>
  6. <title>Colombia Earthquake</title>
  7. </head>
  8.  
  9. <body>
  10.  
  11. <headline>
  12. <hl1>143 Dead in Colombia Earthquake</hl1>
  13. </headline>
  14. <byline>
  15. <bytag>By Jared Kotler, Associated Press Writer</bytag>
  16. </byline>
  17. <dateline>
  18. <location>Bogota, Colombia</location>
  19. <date>Monday January 25 1999 7:28 ET</date>
  20. </dateline>
  21.  
  22. </body>
  23.  
  24. </nitf>

实例:XML Weather Service

国家气象服务案例,来自 NOAA (National Oceanic and Atmospheric Administration):

  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2.  
  3. <current_observation>
  4.  
  5. <credit>NOAA's National Weather Service</credit>
  6. <credit_URL>http://weather.gov/</credit_URL>
  7.  
  8. <image>
  9. <url>http://weather.gov/images/xml_logo.gif</url>
  10. <title>NOAA's National Weather Service</title>
  11. <link>http://weather.gov</link>
  12. </image>
  13.  
  14. <location>New York/John F. Kennedy Intl Airport, NY</location>
  15. <station_id>KJFK</station_id>
  16. <latitude>40.66</latitude>
  17. <longitude>-73.78</longitude>
  18. <observation_time_rfc822>
  19. Mon, 11 Feb 2008 06:51:00 -0500 EST
  20. </observation_time_rfc822>
  21.  
  22. <weather>A Few Clouds</weather>
  23. <temp_f>11</temp_f>
  24. <temp_c>-12</temp_c>
  25. <relative_humidity>36</relative_humidity>
  26. <wind_dir>West</wind_dir>
  27. <wind_degrees>280</wind_degrees>
  28. <wind_mph>18.4</wind_mph>
  29. <wind_gust_mph>29</wind_gust_mph>
  30. <pressure_mb>1023.6</pressure_mb>
  31. <pressure_in>30.23</pressure_in>
  32. <dewpoint_f>-11</dewpoint_f>
  33. <dewpoint_c>-24</dewpoint_c>
  34. <windchill_f>-7</windchill_f>
  35. <windchill_c>-22</windchill_c>
  36. <visibility_mi>10.00</visibility_mi>
  37.  
  38. <icon_url_base>
  39. http://weather.gov/weather/images/fcicons/
  40. </icon_url_base>
  41. <icon_url_name>nfew.jpg</icon_url_name>
  42. <two_day_history_url>
  43. http://www.weather.gov/data/obhistory/KJFK.html
  44. </two_day_history_url>
  45. <disclaimer_url>
  46. http://weather.gov/disclaimer.html
  47. </disclaimer_url>
  48. <copyright_url>
  49. http://weather.gov/disclaimer.html
  50. </copyright_url>
  51.  
  52. </current_observation>