I have a jQuery script in my HTML that parses out the URL name. Is it possible to use that parsed out name and query an XML where an element's attribute is the site's name?
<sites>
<site name="Blah00">
<systemStatus color="green">Normal</systemStatus>
<networkNotes>System status is normal</networkNotes>
</site>
<site name="Blah01">
<systemStatus color="green">Normal</systemStatus>
<networkNotes>System status is normal</networkNotes>
</site>
....
</sites>
For example, the site for the first <site>
in my XML could be http://www.example.com/status-Blah00
. Inside the HTML for that site, I am pulling out the Blah00
of the URL and storing that in a variable.
How can I use that variable to get data from my XML file?
For example, under an area of my site that displays the systemStatus
, I want to display the <systemStatus>
of the site whose attribute name
is the same as the variable (in this case, Blah00
).
As helderdarocha pointed out, I can get a site by doing:
var note = $("site[name='Blah01'] networkNotes");
alert(note.text());
However I am asking how I can basically do that same thing but instead of saying the name of the site (ie: Blah00, Blah01, etc.) I want to use the variable that I have pulling the site name from the actual URL.
From my HTML:
<script>
function myExampleSite()
{
var myURL = window.location.href;
var dashIndex = myURL.lastIndexOf("-");
var dotIndex = myURL.lastIndexOf(".");
var result = myURL.substring(dashIndex + 1, dotIndex);
return result;
}
var siteName = myExampleSite();
</script>
I want to be able to use siteName
instead of explicitly typing Blah00, Blah01
, etc.