how to check the entered element in XML is there or not

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhuriks
    New Member
    • Jun 2010
    • 149

    how to check the entered element in XML is there or not

    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

    Code:
    <tr>
                            <td></td>
                            <td><font color="#800000">&nbsp;</font><font color="#800000"><b>Pack Name</b></font><font color="#800000" size="">&nbsp;</font></td>
                            <td><input name="packName" type="text" id="packName"> </td>
                            <td></td>
                       </tr>
    modify.js

    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();
        }
    }
    thanx,
    madhu.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    I recommend Firefox with the Firebug Add-on, so you can set breakpoints in your JS code and follow the code while executing. (i.e. I don’t know your XML, so I can’t tell anything useful)

    Comment

    • madhuriks
      New Member
      • Jun 2010
      • 149

      #3
      Originally posted by Dormilich
      I recommend Firefox with the Firebug Add-on, so you can set breakpoints in your JS code and follow the code while executing. (i.e. I don’t know your XML, so I can’t tell anything useful)
      i used fire-bug in mozilla fox..but unable to get it..

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        in the "Script" pane, you can set breakpoints at which the script stops executing and you can inspect the values of your variables.

        Comment

        Working...