i have a small problem with my script and i’m stuck… I need to count elements in my xml main tags, independently of their names. Can you tell me how to do this?
$.ajax({
type:"GET",
url:"../amica_programator/data/content_data.xml",
dataType:"xml",
success: function(xml) {
var class_main_content = $('.main_content ul').attr('class');
var xml_element_name = $(xml).find(class_main_content)[0].nodeName.toLowerCase();
if ((class_main_content) == xml_element_name){
var n_elements = $(xml).find(xml_element_name).find("element").size();
alert(n_elements);
}
If your XML data is not a
XMLDocumentfirst you should parse it with$.parseXML(). After that you can use simple selectors to find count of elements. Here is an example;ps: I have to add
<root>to make XML valid.