ความน่าใช้ของ XML
- หน้าก่อนหน้า เรื่องย่อ XML
- หน้าต่อไป โครงสร้างต้นไม้ XML
XML ถูกใช้ในทุกด้านของการพัฒนาเว็บ
XML ทั่วไปใช้เพื่อแยกข้อมูลจากการแสดง
XML แยกข้อมูลจากการแสดง
XML ไม่นำมาพร้อมข้อมูลว่าจะแสดงข้อมูลอย่างไร
ข้อมูล XML ที่เหมือนกันสามารถใช้สำหรับสถานการณ์การแสดงหลายๆ รูปแบบ
ดังนั้น ผ่าน XML การแยกข้อมูลและการแสดงเป็นสิ่งแยกกันสุดท้าย
XML ทั่วไปนับว่าเป็นการเสริม HTML
ในหลายๆ โปรแกรม HTML ความเป็นไปได้ที่ XML ใช้เพื่อเก็บข้อมูลหรือของข้อมูล และ HTML ใช้เพื่อรูปแบบและแสดงข้อมูลเหล่านั้น
XML จะแยกข้อมูลจาก HTML
ในการแสดงข้อมูลด้วย HTML คุณไม่จำเป็นต้องแก้ไขแฟ้ม HTML เมื่อข้อมูลเปลี่ยนแปลง
ผ่าน XML ข้อมูลสามารถเก็บเกี่ยวข้องในแฟ้ม XML แยกต่างหาก
เพียงไม่กี่บรรทัด JavaScript คุณก็สามารถอ่านแฟ้ม XML และปรับปรุงข้อมูลใน 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>
- หน้าก่อนหน้า เรื่องย่อ XML
- หน้าต่อไป โครงสร้างต้นไม้ XML