Usage of XML
- Previous Page XML Introduction
- Next Page XML Tree Structure
XML is used in all aspects of web development.
XML is usually used to separate data from presentation.
XML separates data from presentation.
XML does not carry any information about how to display data.
The same XML data can be used for many different presentation scenarios.
Therefore, through XML, data and presentation are completely separated.
XML is usually a supplement to HTML
In many HTML applications, XML is used to store or transmit data, while HTML is used to format and display these data.
XML separates data from HTML
When displaying data with HTML, you do not need to edit the HTML file when the data changes.
Data can be stored in a separate XML file through XML.
With just a few lines of JavaScript code, you can read an XML file and then update the data content in HTML.
Books.xml
<?xml version="1.0" encoding="UTF-8"?> <bookstore> <book category="Cuisine"> <title lang="en">Talks on Eating at the Elegant Cottage</title> <author>Liang Shiqiu</author> <press>Jiangsu Literature and Art Publishing House</press> <year>2013</year> <price>35</price> <ISBN>9787539962771</ISBN> </book> <book category="Children"> <title lang="en">The Fantastic Mr. Fox Dad</title> <author>Rolf Dahl</author> <translator>Da Wei</translator> <press>Tomorrow Publishing House</press> <year>2009</year> <price>10</price> <ISBN>9787533259563</ISBN> </book> <book category="Literature"> <title lang="en">Turning Familiarity into Strangeness</title> <author>Zygmunt Bauman</author> <author>Peter Haffner</author> <translator>Wang Liqiu</translator> <press>Nanjing University Press</press> <year>2023</year> <price>68</price> <ISBN>9787305269387</ISBN> </book> <book category="Science"> <title lang="en">Do You Want to Fly, Like a Bird?</title> <author>Richard Dawkins</author> <author>Yana Renzova</author> <translator>High Tianyu</translator> <press>Hunan Science and Technology Press</press> <year>2023</year> <price>88</price> <ISBN>9787571019075</ISBN> </book> <book category="politics" cover="softcover"> <title lang="zh">On the Democracy of the United States</title> <author>Tocqueville</author> <translator>Dong Guoliang</translator> <press>Business Printing House</press> <year>1989</year> <price>60</price> <ISBN>9787100124553</ISBN> </book> </bookstore>
You will learn more about using XML and JavaScript in the DOM section of this tutorial.
Transaction Data
There are thousands of XML formats in numerous industries, describing the daily exchange of data:
- Stocks and Shares
- Financial Transactions
- Medical Data
- Mathematical Data
- Scientific Measurement
- News Information
- Weather Service
Example: XML News
XMLNews is a specification for exchanging news and other information.
The benefits of using standards are that they allow journalists and news consumers to easily cross different hardware, software, and programming languages to create, receive, and store all types of news information.
XMLNews document example:
<?xml version="1.0" encoding="UTF-8"?> <nitf> <head> <title>The Eastern Airlines C919 makes its first flight on the Beijing-Shanghai route</title> </head> <body> <headline> <hl1>First flight of Eastern Airlines C919 on Shanghai Hongqiao to Beijing Daxing route</hl1> </headline> <byline> <bytag>China Central Television</bytag> </byline> <dateline> <location>Shanghai Hongqiao International Airport</location> <date>January 09, 2024</date> </dateline> </body> </nitf>
Example: XML Weather Service
XML National Weather Service provided by NOAA (National Oceanic and Atmospheric Administration):
<?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>
- Previous Page XML Introduction
- Next Page XML Tree Structure