A page on my website uses regex to read an xml file elsewhere on my site.
Example xml:
What I want to be able to do is to grab text out of the <title> tags inside the <fav> tags.
Ive a while on it so far but this is my nearest working solution:
I get 1 match... but it is blank so far. My regex feels too complicated (like a snowball down a steep hill and big.
Ashthud
Example xml:
Code:
<favs>
<title>Main</title>
<fav>
<title>facebook</title>
<url>facebook.com</url>
</fav>
<fav>
<title>hotmail</title>
<url>hotmail.com</url>
</fav>
<title>User</title>
<fav>
<title>youtube</title>
<url>youtube.com</url>
</fav>
<fav>
<title>myspace</title>
<url>myspace.com</url>
</fav>
</favs>
Ive a while on it so far but this is my nearest working solution:
Code:
<script type="text/javascript">
var s = "";
s += "<favs>\n";
s += " <title>TestMain</title>";
s += " <fav>\n";
s += " <title>Test1</title>\n";
s += " </fav>\n";
s += " <fav>\n";
s += " <title>Test2</title>\n";
s += " </fav>\n";
s += " <fav>\n";
s += " <title>Test3</title>\n";
s += " </fav>\n";
s += " <fav>\n";
s += " <title>Test4</title>\n";
s += " </fav>\n";
s += "</favs>\n";
var re = new RegExp([red]'((<favs>)(\s*|\S*)*)+((<fav>)((\s*|\S*)*(<\/fav>)+))*(\s*|\S*)*(^<\/favs>)'[/red], 'gi');
var matches = s.match(re);
if (matches && matches.length) {
for (var x = 0; x < matches.length; x++) {
document.getElementById('favourites').innerHTML += "<br>matches[" + x + "]=" + matches[x];
}
}
</script>
I get 1 match... but it is blank so far. My regex feels too complicated (like a snowball down a steep hill and big.
Ashthud