Several Methods for jQuery to process XML files and several methods for jqueryxml

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.