case
ADM Blog
28Sep/100

Parse XML in JavaScript with jQuery

Yes, you can do it with XMLDOM and all the other ways out there, but why not use the power of jQuery ?
Like so:

1
2
3
4
5
6
7
   <root>
      <items>
          <item name="first" id="1">Content 1</item>
          <item name="second" id="2">Content 2</item>
      </items>
      <other atribute="true" />
    </root>
1
2
3
4
   var xml = '<root ......';
   var obj = $(xml);
   // and now you can use jquery selectors to get what you want
   $("item[name=second]", obj).attr('id'); // 2

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


CommentLuv badge

*

No trackbacks yet.