Home  >  Article  >  Web Front-end  >  Detailed explanation of the steps of jquery parsing XML string + XML file (with code)

Detailed explanation of the steps of jquery parsing XML string + XML file (with code)

php中世界最好的语言
php中世界最好的语言Original
2018-04-23 13:50:451434browse

This time I will bring you jqueryParsing XMLString Detailed explanation of the steps of XML file (with code), jquery parsing XML string XML fileNotesWhat are they? Here are actual cases. Let’s take a look.

1. Read the XML string:

For example:

$(document).ready(function(){
var xml = "<xml><root><record><name>liubl</name></record><record><name>chencp</name</record></root></xml>";//var xml="<table><tr><td>100<td></tr></table>"; //也可直接识别Tablevar obj = $(xml).find("record"); });


Note: Be sure to wrap a layer of xml outside, so that jquery In order to be recognized, there also needs to be a root node in the xml, which is root or other can be customized.

2. Read XML files For example:

$(document).ready(function(){ 
$.get('mydata.xml',function(xml)
{
$(xml).find("book").each(function(){
var xmlAttr=$(this).attr("属性");
var xmlText=$(this).fint("节点").text();
});
});
});

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Using jquery plug-in ajaxupload for file upload

How to use jQuery plug-in to limit the size and format of uploaded files

jquery dynamically loading js file implementation steps

The above is the detailed content of Detailed explanation of the steps of jquery parsing XML string + XML file (with code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn