Hello all!
I have a bit of XML I am parsing and populating a drop-down menu with. I have some simple rules for those drop-downs but the XML I'm pulling is giving me close but not accurate results. I'm just learning php/ajax/jquery and having allot of fun but this has stumped me for a while since my javascript isn't that strong.
Here is a sample of the XML I'm parsing.
Code:
<PlanetaryInteraction>
<Component>
<name>Aqueous Liquids</name>
<cycle>15</cycle>
<structureRequired>Extractor</structureRequired>
<planet>Barren</planet>
</Component>
<Component>
<name>Water</name>
<cycle>30</cycle>
<structureRequired>Basic Industry Facility</structureRequired>
<output>20</output>
<Require>
<quantity>3000</quantity>
<component>Aqueous Liquids</component>
</Require>
</Component>
</PlanetaryInteraction>
The XML above has been edited to show you the problem I have. My javascript code is gabbing these components, but I only want components that have NO <Require> children! And then the later-half of the form I want to do the Opposite and only show components that HAVE <Require>
Below is a snippet of the javascript that grabs the first drop-down's options..
Code:
<script language="JavaScript1.5" type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "xml/PlanetaryInteraction.xml",
dataType: "xml",
success: function(xml) {
var select = $('#pi_extraction_1');
$(xml).find('Component').each(function(){
if ($(this).find('Require').length) {
// Has requirements, do not list
} else {
var name = $(this).find('name').text();
select.append("<option class='item'>"+name+"</option>");
}
});
select.children(":first").text("").attr("selected",true);
...
Now the focus of my problem is this bit:
Code:
if ($(this).find('Require').length) {
// Has requirements, do not list
} else {
var name = $(this).find('name').text();
select.append("<option class='item'>"+name+"</option>");
}
the results I currently get in the drop-down look like this:
Aqueous Liquids
Aqueous Liquids
I want just:
Aqueous Liquids
I suspect its grabbing the component name from both //PlanetaryInteraction/Component/name as well as //PlanetaryInteraction/Component/Require/component
How can I fix this bit of javascript?
Any suggestions greately appreciated and I can provide more code upon request!
Thanks!!