<html>
<head>
<script type="text/javascript">
var http;
if (window.XMLHttpRequest) { xhttp = new XMLHttpRequest(); }
else { xhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
xhttp.open("GET", "myfile.xml", false);
xhttp.send();
var xmlDoc = xhttp.responseXML;
var x = xmlDoc.getElementsByTagNameNS("https://dotnetheaven.com", "author")[0];
function check() {
var y = x.hasAttributeNS("https://dotnetheaven.com", "Country");
document.getElementById("tst").innerHTML = y;
};
function Add() {
x.setAttributeNS("https://dotnetheaven.com", "Country", "India");
};
</script>
</head>
<body>
<button onclick="check()">
check</button>
<h1 id="tst" style="color: Blue">
click button to check attribute exists or not</h1>
<p>
click this button to add attribute</p>
<button onclick="Add()">
Add attribute</button>
</body>
</html>
|