can find () by used in iterating through XML
I am trying to find a way to read through an XML file that allows me to associate some siblings and children to each other. Appropriately enough I wonder if I can do this with find(). Actually I have tried many things with no luck. let me show you some xml:
- <bn>
<node>
<name>Stability</name>
<state>Low -
<state-prob>.15</state-prob>
</state>
<state>Moderate -
<state-prob>.25</state-prob>
</state>
<state>High -
<state-prob>.60</state-prob>
</state>
</node>
<node>
<name>Free/Fair Elections</name>
<state>Yes -
<state-prob>.60</state-prob>
</state>
<state>No -
<state-prob>.40</state-prob>
</state>
</node>
<node>
<name>Regulatory Compliance</name>
<state>Yes -
<state-prob>.80</state-prob>
</state>
<state>No -
<state-prob>.20</state-prob>
</state>
</node>
</bn>
So what I would like to do is read each node and output Name maybe into a ul, with state and state-prob in a nested ul.
I have no problem reading the xml it's just he part where I have to sort through it that is giving me trouble. Would you like to see some JS?
- <html>
<head>
<title>Page Title</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$.get('bn-my-test-data.xml', function(xml){
$('#test').append($(xml).find('name').text());
$('#test').append( '<br>' + $(xml).find('state').text());
});
});
</script>
<section id="test">
</section>
</body>
</html>
I would greatly appreciate any guidance on this topic. And I thank you very much in advance.