The first option:
Second option:
The general steps are as follows:
1. Read xml file
$.get("xmlfile.xml",function( xml){
$(xml).find("item").length;
});
2. Read xml content
If the xml read comes from an xml file, combined with the above point, the processing is as follows:
$.get("xmlfile.xml",function( xml){
$(xml).find("item").length;
});
If you are reading an xml string, please note that the xml string must be surrounded by "" and "" before it can be parsed
$("< ;item>").find("item").length;
Parse xml content:
Sample xml:
dsname
Character datatype>
dstype
>
The following is the parsing sample code:
Copy code The code is as follows:
$(xml).find("field").each(function() {
var field = $(this);
var fName = field.attr("Name"); //Read node attributes
var dataType = field.find("datatype").text();//Read the value of child node
});