XML 不携带任何有关如何显示数据的信息。
相同的 XML 数据可以用于许多不同的呈现场景。
因此,通过 XML,数据和呈现之间完全分离。
在许多 HTML 应用程序中,XML 用于存储或传输数据,而 HTML 用于格式化和显示这些数据。
在使用 HTML 显示数据时,您不必在数据更改时编辑 HTML 文件。
通过 XML,数据可以存储在单独的 XML 文件中。
只需几行 JavaScript 代码,您就可以读取 XML 文件,然后更新 HTML 中的数据内容。
<?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 格式,描述日复一日的数据交换:
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>
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> <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>
相关
视频
RELATED VIDEOS
科技资讯
1
2
3
4
5
6
7
8
9
精选课程
共5课时
17.3万人学习
共49课时
77.4万人学习
共29课时
62万人学习
共25课时
39.5万人学习
共43课时
71.3万人学习
共25课时
61.9万人学习
共22课时
23.1万人学习
共28课时
34.1万人学习
共89课时
125.8万人学习