Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find text string in XML

How would i find the xml node that has a certain text value?

example i want to do something like this which is not working:

var xml = "<data><itemB>more data</itemB><itemC>yes, more data</itemC><itemA>some data</itemA></data>";

var searchString = "more data";

var foundin = $(xml + ":contains(" + searchString + ")");
like image 495
capdragon Avatar asked Jul 15 '26 07:07

capdragon


1 Answers

You can invoke the :contains selector with the root XML element as its context:

var foundin = $(":contains(" + searchString + ")", xml);

You can see the results in this fiddle.

like image 107
Frédéric Hamidi Avatar answered Jul 17 '26 21:07

Frédéric Hamidi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!