Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post

    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" />

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,193
    Thanks
    23
    Thanked 605 Times in 604 Posts
    If your second file is your xml, it's not.
    Please read this http://www.w3schools.com/xml/xml_dtd.asp

  • #3
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post
    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.

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,193
    Thanks
    23
    Thanked 605 Times in 604 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •