XML - eXtensible Markup Language
XML gives a way of defining other markup languages (for example, HTML is a markup language that has an XML format). The "X" is for extensible, so XML is flexible in the data and documents that it can contain.
An example of course data in XML format is:
When working with XML in JavaScript, you can use the DOM, or there are libraries to convert XML to JSON.
One important aspect of XML is that it is really a family of technologies that interoperate quite well -- once you are in the XML world and using XML technologies, working with XML can be easy, straightforward, and even fun. Examples of XML technolgoies are:
- Programming models: DOM and SAX
- Query: XQuery and XPath
- Transformation: XSLT
- Presentation format: Office document formats are XML based, SVG (graphics), XSL-FO (print), XHTML/HTML (web)
So an example where we have the seasons array in XML:
<seasons>
<season>Spring</season>
<season>Summer</season>
<season>Autumn</season>
<season>Winter</season>
</seasons>
We could process that in jQuery by:
$.get("seasons.xml",function(data){
var ul_node = $('<ul/>');
console.log(data);
$(data).find("season").each(function(){
var season_string = $(this).text();
console.log($(this));
$('<li/>').text(season_string).appendTo(ul_node);
});
ul_node.replaceAll($('#seasonslist'));
});
Full code:
Working Examples: