dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: XML parsing issue using Ajax/Jquery

  1. #1
    Join Date
    May 2010
    Posts
    2

    XML parsing issue using Ajax/Jquery

    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!!

  2. #2
    Join Date
    May 2010
    Posts
    2
    Anyone?

Similar Threads

  1. XML Parsing performance question
    By markuplang_user in forum XML
    Replies: 1
    Last Post: 02-22-2010, 01:31 AM
  2. Parsing an XML document using SAX API
    By river22_34 in forum XML
    Replies: 3
    Last Post: 02-03-2008, 06:12 AM
  3. Try XML Junction
    By Tim in forum xml.announcements
    Replies: 0
    Last Post: 10-11-2001, 04:00 PM
  4. Data Junction Announces XML Junction 7.51
    By Tim Frost in forum xml.announcements
    Replies: 0
    Last Post: 04-02-2001, 10:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center