0

I'm trying to search for a specific node in an xml document; unfortunately, i can't seem to find a reliable way to do this, correctly, in a crossbrowser fashion. Given this setup:

var test1 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><test:things>\"things\"</test:things>"
var parser=new DOMParser();
var test2 =parser.parseFromString(test1,"text/xml");

in firefox this seems to work properly:

> $(test2).find("test\\:things")
[<test:things>​…​</test:things>​]

in chrome this seems to work properly:

> $(test2).find("things")
[<test:things>​…​</test:things>​]

haven't tried farther than that - is there a cross-browser safe method for performing this search? i'd rather not have to write two searches each time i need this functionality

blueberryfields
  • 45,910
  • 28
  • 89
  • 168
  • since you tagged jquery, have you seen http://api.jquery.com/jquery.parsexml/? use normal jquery selectors to find what you need. – mothmonsterman Sep 11 '14 at 15:33
  • 1
    der ok i read a little closer... see this answer: http://stackoverflow.com/a/1901903/152640 – mothmonsterman Sep 11 '14 at 15:36
  • possible duplicate of [jQuery XML parsing with namespaces](http://stackoverflow.com/questions/853740/jquery-xml-parsing-with-namespaces) – blueberryfields Sep 11 '14 at 15:58
  • On my machine, Firefox 32 returns a `parsererror`: "prefix not bound to a namespace", because the XML snippet doesn't declare the `test:` namespace. @blueberryfields, how did you get the code above to parse? – Jeremy Sep 11 '14 at 23:54

0 Answers0