Several Methods for jQuery to process XML files and several methods for jqueryxml
XML and HTML are both Markup languages, and their syntax forms are very similar. They belong to the same language system. For HTML parsing, It is very convenient for me to use jQuery. In fact, we can also use jquery to parse XML, which is also convenient.
If you have used XML parsing in Java, PHP, and other languages, I believe you will have the same feeling, that is very troublesome. After using jQuery to read, analyze, and operate XML, it is easy to understand. Let's take a look at several methods to process XML files using jQuery.
Parse XML using common JavaScript methods
var xmlDoc = request.responseXML;try // Build Markers, if available{ var markers = xmlDoc.getElementsByTagName("marker") ; for ( var i = 0; i < markers.length ; i++ ) { var point = { markers[i].getAttribute("lat")), markers[i].getAttribute("lng") }; }} catch(e) {}
Parse XML using jQuery
$(request.responseXML).find("marker").each(function() { var marker = $(this); var point = { marker.attr("lat"), marker.attr("lng") };});
Use $. parseXML () to parse XML
If you have read the XML content into the string, you can use the $. parseXML () method to analyze it:
xml = $.parseXML( $('body > pre').text() );$(xml).find("entry").each(function() { var $this = $(this), item = { Address1: $this.find("Address1").text(), Address2: $this.find("Address2").attr('name') }});
The above is all the content of this article, and I hope it will help you learn JavaScript programming.