hi,
i m doing project in generating XML file and i m not much aware of XML...i generated XML file successfully using DOM...now i m not getting how to modify and delete the elements in XML file...i tried so much..i m not getting can anyone help me out regarding this...my doubt is if i enter the 'packName' it should check whether it exists in XML file or not..if exists it should do modification otherwise it should tell the 'Entered Value' does not exist...here is my code...waiting for the reply..i m getting problem in validation..
modify.jsp
modify.js
thanx,
madhu.
i m doing project in generating XML file and i m not much aware of XML...i generated XML file successfully using DOM...now i m not getting how to modify and delete the elements in XML file...i tried so much..i m not getting can anyone help me out regarding this...my doubt is if i enter the 'packName' it should check whether it exists in XML file or not..if exists it should do modification otherwise it should tell the 'Entered Value' does not exist...here is my code...waiting for the reply..i m getting problem in validation..
modify.jsp
Code:
<tr>
<td></td>
<td><font color="#800000"> </font><font color="#800000"><b>Pack Name</b></font><font color="#800000" size=""> </font></td>
<td><input name="packName" type="text" id="packName"> </td>
<td></td>
</tr>
Code:
function validate() {
if (document.frm.packName.value == "") {
alert("Enter Package Name");
document.frm.packName.focus();
return (false);
}
chkId = /^[WAP_]{4}\d{2}$/;
if (chkId.test(document.frm.packName.value)) {
} else {
alert('Invalid \"Pack Name\" Entry');
return false;
}
return true;
}
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g, "");
}
var xmlhttp = null;
function login() {
if (validate()) {
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
var packName = document.getElementById("packName").value;
var url = "/proj/gprs/login.xml";
url = url + "&packName=" + packName;
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
}
function stateChanged() {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
parseMsg();
} else {
alert("Unable to retrieve");
}
}
}
function parseMsg() {
// PACK_NAME validation
var packName = document.getElementById("packName").value;
response = xmlHttp.responseXML.documentElement;
var valid = true;
var packNodes = response.getElementsByTagName("PACK_NAME");
for ( var i = 0; i < packNodes.length; i++) {
var packNode = packNodes.item(i);
var packNodeChilds = packNode.childNodes;
for ( var j = 0; j < packNodeChilds.length; j++) {
var packNodechild = packNodeChilds.item(j);
if (packNodechild.nodeType == Node.TEXT_NODE) {
//alert(childNode.nodeValue);
if ( packNodechild.nodeValue == packName) {
alert("Pack Name Already Exists");
valid = false;
}
}
}
}
if(valid){
document.frm.submit();
}
}
madhu.
Comment