How to find/extract data from xml with jQuery

后端 未结 2 1976
夕颜
夕颜 2020-12-31 20:40

I\'m trying to extract the StateLongName and StateShortName values from the xml below.

I know there has to be a simple elegant way to do this with jQuery.



        
2条回答
  •  没有蜡笔的小新
    2020-12-31 21:36

    It's case sensitive, use "Table" like this:

    $(xml).find("Table").each(function() {
      var stateName = $(this).find("StateLongName").text();
      var stateCode = $(this).find("StateShortName").text();
    });
    

    Update: Sorry this one was a bit baffling, don't use

    , it treats it as html creating a and things get stranger from there:) If you changed it to just abut anything else, it'll work, here's an example with it changed to : http://jsfiddle.net/Yvetc/

    Here's a full bare test page:

    
          
        
        
      
      
      
    
    

    提交回复
    热议问题