could any one show me how i can use JavaScript regular expression to change following xml structure ?
default xml
<dict>
<key>TITLE</key>
<string>first</string>
<key>URL</key>
<string>http://someurl.com/1.m3u8</string>
</dict>
<dict>
<key>TITLE</key>
<string>Second</string>
<key>URL</key>
<string>http://someurl.com/2.m3u8</string>
</dict>
<dict>
<key>TITLE</key>
<string>Third</string>
<key>URL</key>
<string>http://someurl.com/3.m3u8</string>
</dict>
convert to :
<dict>
<url>http://someurl.com/1.m3u8</url>
<title>First</title>
</dict>
<dict>
<url>http://someurl.com/2.m3u8</url>
<title>Second</title>
</dict>
<dict>
<url>http://someurl.com/3.m3u8</url>
<title>Third</title>
</dict>
Edit: i want to parse converted xml using this code:
<button type="button" onclick="loadXMLDoc()">crate table</button>
<br><br>
<table id="demo"></table>
<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xmlhttp.open("GET", "myxml.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>URL</th><th>Title</th></tr>";
var x = xmlDoc.getElementsByTagName("dict");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("url")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
</script>