Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-10-2012, 06:49 PM   PM User | #1
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 127
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
How to find a term in an XML file

I am trying to load an XML file (no problems yet) and then, when a user enter some text into an input TF and hits enter, I want to look for that entered text in the XML file and return information associated with that text.

Do I have to itterate through the entire XML file with '.find'? I have to use attr() in there somewhere, than when it matches I need to return the 'def' attribute.

Code:
<glossary>


<item term="AAA" def="Not the American Automobile Association" rollover="A is A and A" />


<item term="ABC" def="Alpha Beta Carl" />


<item term="ABP" def="Air Bypass" />


<item term="AC" def="Air Conditioner" />

</glossary>
Code:
/* This captures the ENTER key event and checks for letters and numbers only. */
$(document).ready(function() 
{ 
	var glossary_file = $.get('glossary/glossary_data.xml');

    $('#gloss_search').keydown(function(event)
	{ 
        if (event.keyCode == 13)
		{
			var letterNumber = /^[0-9a-zA-Z]+$/;  
			if($(this).val().match(letterNumber))   
			{  
				getGlossTerm($(this).val());
				//return true;  
			} 
            return false; 
		}
	});
 });

 
function getGlossTerm(stringEntered)
{
	$(glossary_file).find(stringEntered).each(function(){
		// when the stringEntered is found how do I 
	});
	
	//glossary_file = $.parseXML( stringEntered );
	
	alert(term);
}
m2244 is offline   Reply With Quote
Old 10-10-2012, 07:25 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I don't really know how jQuery parses xml. If they were normal html tags you could do this:
Code:
<script>
$('item').each(function() {
    alert($(this).attr('def'));
});
</script>
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:11 AM.


Advertisement
Log in to turn off these ads.