Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<Position1>
<name key="x" value="om"/>
<title key="y" value="op"/>
<quest key="z" value="ol"/>
</Position1>
<Position2>
<OTHER key="x" value="om"/>
<UNKNOWN key="y" value="op"/>
<SPACE key="z" value="ol"/>
</Position2>
<Position3>
<UTILITY key="x" value="om"/>
<Gender key="y" value="op"/>
<board key="z" value="ol"/>
</Position3>


JavaScript
$(document).ready(function(){ 
	$.get("test.xml",{},function(xml){
		$('name',xml).each(function(i) {  //i dont want to do like this			
			var $node1 = $(this); 
			var key = $node1.attr("key");
			var value = $node1.attr("value");
			alert(key+' '+value);
		});
                $('title ',xml).each(function(i) {			
			var $node1 = $(this); 
			var key = $node1.attr("key");
			var value = $node1.attr("value");
			alert(key+' '+value);
		});		
	});
});
Posted
Updated 3-Feb-15 21:37pm
v3
Comments
Sinisa Hajnal 4-Feb-15 3:24am    
What have you tried?
http://api.jquery.com/jquery.parsexml/
OPees 4-Feb-15 3:40am    
updated... Please have look....
_Asif_ 4-Feb-15 3:46am    
What is the actual problem?
OPees 4-Feb-15 3:49am    
i m not able to get list inside Position1 ,position2 and Position2
like in 1st one name,title,quest and in 2nd one other, unknown, space
Sinisa Hajnal 4-Feb-15 4:32am    
With parseXml you get XMLDocument object on which you can use XPath queries...I think they removed XPath from core, but there is a plugin with it. Sorry, not sure how it is called, but it exists.

1 solution

JavaScript
$(document).ready(function(){ 
$.get("test.xml",{},function(xml){
x=xml.documentElement;
y=x.children;
for (i=0;i<y.length;i++)
{
document.write("  Nodename: " + y[i].nodeName + "<br>");
for (z=0;z<y[i].children.length;z++)
  {
      var $node1 = $(y[i].children[z]); 
      var key = $node1.attr("key");
      var value = $node1.attr("value");
      document.write("----- Child Nodename: " + y[i].children[z].nodeName +"    Key " + key +"    value " + value  + "<br>" );
  }
}
});	
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900