JSFiddle - React, Tailwind, and code Playground
by grant
JavaScript
var xml = '<?xml version="1.0" encoding="utf-8"?><bookstore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="BookStore.xsd"><book price="730.54" ISBN="string" publicationdate="2016-02-27"> <title>This is a random title</title><author><first-name>string</first-name><last-name>string</last-name></author><genre>string</genre></book><book price="6738.774" ISBN="string"><title>I want to match "Hello World!"</title><author><first-name>string</first-name><last-name>string</last-name></author></book><book price="6738.774" ISBN="string"><title>I want to match "Hello World!"</title><author><first-name>string</first-name><last-name>string</last-name></author></book></bookstore>';
function parseXml(xml) {
var string_to_find = "Hello World!";
$(xml).find('title').each(function () {
var str = $(this).text();
if (str.indexOf(string_to_find) > -1) {
if (matchFound(str, string_to_find)) {
return false;
}
}
});
}
function matchFound(str, string_to_find) {
alert('Match found in string - ' + str + '\r\n While looking for the string- ' + string_to_find);
return true;
}
function matchNotFound() {
alert('No Match found!');
}
parseXml(xml);