Home >Web Front-end >JS Tutorial >Description of jquery's method of parsing XML strings and XML files_jquery

Description of jquery's method of parsing XML strings and XML files_jquery

WBOY
WBOYOriginal
2016-05-16 16:58:481015browse

1. Read XML string:
For example:

Copy code The code is as follows :

$(document).ready(function(){

var xml = "liublchencp< ;/root>";
//var xml="

100
"; // You can also directly identify Table
var 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 something else that can be customized.

2. Read the XML file
For example:

Copy the code The code is as follows:

$(document).ready(function(){
$.get('mydata.xml',function(xml)
{
$(xml).find( "book").each(function(){
var xmlAttr=$(this).attr("Attribute");
var xmlText=$(this).fint("node").text() ;
});
});
});
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