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 02-12-2013, 10:23 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 XML attribute

Hello,

I am trying to load an XML file (done I believe) and then find a node which has a specific attribute. I loaded this XML to an object variable but I am not sure that that is the best way to do this. What I need to do is look through the XML, compare the attribute to a string, if it matches stop the search and store the corresponding attribute value in that node.

Can anyone point me in a direction for this?

Code:
var glossaryObj = {};

$.get(pURL, function(xmlFile)
{
	$.ajax({
		type: "GET",
		url: pURL,
		dataType: "text",
		success: parseGlossXML
		});
});


function parseGlossXML(xml)
{
	glossaryObj = xml
	$(glossaryObj).find('term').each(function(){
		alert($(glossaryObj).filter(":first").attr('def'));
	});
}
Code:
<item term="AAA" def="Not the American Automobile Association" rollover="Anti-aircraft Artillery" />


<item term="ABCCC" def="Airborne Battlefield Command and Control Center" />


<item term="ABP" def="Air Battle Plan" />


<item term="AC" def="Active Component" />
m2244 is offline   Reply With Quote
Old 02-13-2013, 01:52 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
If your second file is your xml, it's not.
Please read this http://www.w3schools.com/xml/xml_dtd.asp
sunfighter is offline   Reply With Quote
Old 02-13-2013, 02:08 PM   PM User | #3
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
Quote:
Originally Posted by sunfighter View Post
If your second file is your xml, it's not.
Please read this http://www.w3schools.com/xml/xml_dtd.asp
Why do people look for the mistakes in a question to comment on instead of offering help regarding the question itself?

The above XML is an example of my XML file, it is not the complete file.

I need to know how to find an attribute, compare it to a known string, and if it matches, get the other attribute in that XML node.

I do not need to know about properly formed XML!

Last edited by m2244; 02-13-2013 at 02:23 PM..
m2244 is offline   Reply With Quote
Old 02-13-2013, 07:38 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,365
Thanks: 18
Thanked 348 Times in 347 Posts
sunfighter is on a distinguished road
Quote:
Why do people look for the mistakes in a question to comment on instead of offering help regarding the question itself?
Mistake repair is often the answer. Garbage in, garbage out. How can I show you how to extract anything from a poorly form xml doc? How do I know you know what your doing if you post code with errors?
sunfighter 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 07:19 PM.


Advertisement
Log in to turn off these ads.