0

I'm trying to use jquery to parse and find an xml element. The element I'm trying to find has an odd name "ex:relatedid" and for some reason jquery seems to not be able to find it. Any ideas? Thanks in advance!

XML

    <item>
        <id>3ac0daff-51c7-40f2-9396-e0c6adf50858</id>
        <published>2014-12-09T11:27:43.000Z</published>
        <updated>2014-12-09T11:27:43.000Z</updated>
        <ex:relatedid>7fa16377-3382-4ad9-ac52-7ee139e7d9ce</relatedid>

jquery that doesn't work

 $(xml).find('item').each(function () {

          //works
          var id = $(this).find('id').text();

          //doesn't work
          var ex = $(this).find('ex:relatedid').text();

          console.log(ex);

   });
NullReference
  • 4,404
  • 12
  • 53
  • 90

1 Answers1

1

Like this it will work, you need to escape "characters" like ":"

DEMO

$('xml').find('item').each(function () {

      //works
      var id = $(this).find('id').text();

      //doesn't work
      var ex = $(this).find('ex\\:relatedid').text();

      console.log(ex);

});

baao
  • 71,625
  • 17
  • 143
  • 203