XML Usage

Ang XML ay ginagamit sa lahat ng aspeto ng web development.

Ang XML ay karaniwang ginagamit upang ihiwalay ang datos at ang pagdisenyo.

Ang XML ay inaalis ang datos at ang pagdisenyo.

Ang XML ay walang kahit anong impormasyon tungkol sa kung paano ipapakita ang datos.

Ang parehong datos ng XML ay maaaring gamitin sa maraming iba't ibang mga kaganapan ng pagdisenyo.

Sa pamamagitan ng XML, ang datos at ang pagdisenyong magkahiwalay na ganap.

Karaniwang ginagamit ang XML bilang komplemento ng HTML

Sa maraming application ng HTML, ginagamit ang XML para sa pag-iimbak o paglilipat ng data, at ang HTML para sa pag-format at pagpapakita ng mga ganitong data.

Ang XML ay nagiging komplemento sa HTML

Sa pagpapakita ng data sa HTML, hindi mo kailangang i-edit ang file na HTML kapag nagbabago ang data.

Ang data ay maaaring isalba sa hiwalay na file na XML sa pamamagitan ng XML.

Mga ilang linya ng JavaScript lang ay sapat upang basahin ang file na XML, at pagkatapos ay i-update ang nilalaman ng HTML.

Books.xml

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="美食">
  <title lang="zh">雅舍谈吃</title>
  <author>梁实秋</author>
  <press>江苏文艺出版社</press>
  <year>2013</year>
  <price>35</price>
  <ISBN>9787539962771</ISBN>
</book>
<book category="儿童">
  <title lang="zh">了不起的狐狸爸爸</title>
  <author>罗尔德·达尔</author>
  <translator>代维</translator>
  <press>明天出版社</press>
  <year>2009</year>
  <price>10</price>
  <ISBN>9787533259563</ISBN>
</book>
<book category="文学">
  <title lang="zh">将熟悉变为陌生</title>
  <author>齐格蒙·鲍曼</author>
  <author>彼得·哈夫纳</author>
  <translator>王立秋</translator>
  <press>南京大学出版社</press>
  <year>2023</year>
  <price>68</price>
  <ISBN>9787305269387</ISBN>
</book>
<book category="科学">
  <title lang="zh">你想飞吗,像鸟一样?</title>
  <author>理查德·道金斯</author>
  <author>亚娜·伦佐娃</author>
  <translator>高天羽</translator>
  <press>湖南科学技术出版社</press>
  <year>2023</year>
  <price>88</price>
  <ISBN>9787571019075</ISBN>
</book>
<book category="政治" cover="平装">
  <title lang="zh">论美国的民主</title>
  <author>托克维尔</author>
  <translator>董果良</translator>
  <press>商务印书馆</press>
  <year>1989</year>
  <price>60</price>
  <ISBN>9787100124553</ISBN>
</book>
</bookstore>

您将在本教程的 DOM 部分中学习关于使用 XML 和 JavaScript 的更多内容。

交易数据

众多行业中存在数以千计的 XML 格式,描述日复一日的数据交换:

  • 股票和股份
  • 金融交易
  • 医疗数据
  • 数学数据
  • 科学测量
  • 新闻资讯
  • 天气服务

实例:XML 新闻

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

使用标准的好处是:可以让新闻工作者和新闻消费者更轻松地跨不同硬件、软件和编程语言,制作、接收并存储任意类型的新闻信息。

XMLNews 文档实例:

<?xml version="1.0" encoding="UTF-8"?>
<nitf>
  <head>
    <title>东航C919首次执飞京沪航线</title>
  </head>
  <body>
    <headline>
      <hl1>东航C919首次执飞上海虹桥往返北京大兴航线</hl1>
    </headline>
    <byline>
      <bytag>中央广播电视总台</bytag>
    </byline>
    <dateline>
      <location>上海虹桥国际机场</location>
      <date>2024年01月09日</date>
    </dateline>
  </body>
</nitf>

实例:XML 天气服务

NOAA(国家海洋和大气管理局)提供的 XML 国家气象服务:

<?xml version="1.0" encoding="UTF-8"?>
<current_observation>
<credit>NOAA's National Weather Service</credit>
<credit_URL>http://weather.gov/</credit_URL>
<image>
  <url>http://weather.gov/images/xml_logo.gif</url>
  <title>NOAA's National Weather Service</title>
  <link>http://weather.gov</link>
</image>
<location>New York/John F. Kennedy Intl Airport, NY</location>
<station_id>KJFK</station_id>
<latitude>40.66</latitude>
<longitude>-73.78</longitude>
<observation_time_rfc822>Mon, 11 Feb 2008 06:51:00 -0500 EST</observation_time_rfc822>
</observation_time_rfc822>
<weather>A Few Clouds</weather>
<temp_f>11</temp_f>
<temp_c>-12</temp_c>
<relative_humidity>36</relative_humidity>
<wind_dir>West</wind_dir>
<wind_degrees>280</wind_degrees>
<wind_mph>18.4</wind_mph>
<wind_gust_mph>29</wind_gust_mph>
<pressure_mb>1023.6</pressure_mb>
<pressure_in>30.23</pressure_in>
<dewpoint_f>-11</dewpoint_f>
<dewpoint_c>-24</dewpoint_c>
<windchill_f>-7</windchill_f>
<windchill_c>-22</windchill_c>
<visibility_mi>10.00</visibility_mi>
<icon_url_base>http://weather.gov/weather/images/fcicons/</icon_url_base>
<icon_url_name>nfew.jpg</icon_url_name>
<disclaimer_url>http://weather.gov/disclaimer.html</disclaimer_url>
<copyright_url>http://weather.gov/disclaimer.html</copyright_url>
</current_observation>