473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

149 100+
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

Expand|Select|Wrap|Line Numbers
  1.  
  2. <tr>
  3.                         <td></td>
  4.                         <td><font color="#800000">&nbsp;</font><font color="#800000"><b>Pack Name</b></font><font color="#800000" size="">&nbsp;</font></td>
  5.                         <td><input name="packName" type="text" id="packName"> </td>
  6.                         <td></td>
  7.                    </tr>
  8.  
  9.  
modify.js

Expand|Select|Wrap|Line Numbers
  1.  
  2. function validate() {
  3.     if (document.frm.packName.value == "") {
  4.         alert("Enter Package Name");
  5.         document.frm.packName.focus();
  6.         return (false);
  7.     }
  8.     chkId = /^[WAP_]{4}\d{2}$/;
  9.     if (chkId.test(document.frm.packName.value)) {
  10.     } else {
  11.         alert('Invalid \"Pack Name\" Entry');
  12.         return false;
  13.     }
  14.     return true;
  15. }
  16. function trim(stringToTrim) {
  17.     return stringToTrim.replace(/^\s+|\s+$/g, "");
  18. }
  19. var xmlhttp = null;
  20.  
  21. function login() {
  22.     if (validate()) {
  23.         try {
  24.             // Firefox, Opera 8.0+, Safari
  25.             xmlHttp = new XMLHttpRequest();
  26.         } catch (e) {
  27.             // Internet Explorer
  28.             try {
  29.                 xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  30.             } catch (e) {
  31.                 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  32.             }
  33.         }
  34.         var packName = document.getElementById("packName").value;
  35.         var url = "/proj/gprs/login.xml";
  36.         url = url + "&packName=" + packName;
  37.         xmlHttp.onreadystatechange = stateChanged;
  38.         xmlHttp.open("GET", url, true);
  39.         xmlHttp.send(null);
  40.     }
  41. }
  42. function stateChanged() {
  43.     if (xmlHttp.readyState == 4) {
  44.         if (xmlHttp.status == 200) {
  45.             parseMsg();
  46.         } else {
  47.             alert("Unable to retrieve");
  48.         }
  49.     }
  50. }
  51. function parseMsg() {
  52.  
  53.     // PACK_NAME validation
  54.     var packName = document.getElementById("packName").value;
  55.     response = xmlHttp.responseXML.documentElement;
  56.     var valid = true;
  57.     var packNodes = response.getElementsByTagName("PACK_NAME");
  58.     for ( var i = 0; i < packNodes.length; i++) {
  59.         var packNode = packNodes.item(i);
  60.         var packNodeChilds = packNode.childNodes;
  61.         for ( var j = 0; j < packNodeChilds.length; j++) {
  62.             var packNodechild = packNodeChilds.item(j);
  63.             if (packNodechild.nodeType == Node.TEXT_NODE) {
  64.                 //alert(childNode.nodeValue);
  65.                 if ( packNodechild.nodeValue == packName) {
  66.                     alert("Pack Name Already Exists");
  67.                     valid = false;
  68.                 }
  69.             }
  70.         }
  71.     }
  72.     if(valid){
  73.         document.frm.submit();
  74.     }
  75. }
  76.  
thanx,
madhu.
Jul 7 '10 #1
3 1724
Dormilich
8,658 Expert Mod 8TB
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)
Jul 7 '10 #2
madhuriks
149 100+
@Dormilich
i used fire-bug in mozilla fox..but unable to get it..
Jul 8 '10 #3
Dormilich
8,658 Expert Mod 8TB
in the "Script" pane, you can set breakpoints at which the script stops executing and you can inspect the values of your variables.
Jul 8 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jstaggs39 | last post by:
i am posting this message again in an attempt to solicit more responses. i want to add a function that will NOT allow the form to be ran if the dates entered in the dlgdates box have already been...
3
by: Siah | last post by:
Hi, I'd like to detach some of my dom elements and cache them in an object. My current options are to cache its innerHTML, or create an independent 'div' element and move the element as a child...
4
by: eksamor | last post by:
I have a simple linked list: struct element { struct element *next; int start; }; struct list { struct element *head;
14
by: Ørjan Langbakk | last post by:
I have a form where the user has the possibility to enclose his name. email, address and phonenumber. I want to be able to check if some of the fields are filled - at least one. This is so that...
4
by: ug26jhw | last post by:
Is there any way to determine whether an element in a document exists. I have some code like this where the variable i changes: if(document.getElementById('pref'+i).innerHTML... When it...
6
by: Jankie | last post by:
Greetings ! Can anyone share me some piece of code that displays user submitted data for another chance to verify and correct it before finally inserting it into the database? If insertion cannot be...
4
by: lawpoop | last post by:
Hello all - I would like to use the is_numeric() function to check each element of an array. I am just looking for a false if any element is not numeric, or a true if each element is numeric. ...
35
Frinavale
by: Frinavale | last post by:
I have a quick question... Before I start looping through all of the child elements of a <div> I wanted to ask if there is a better way to check if an element is a child of another element? I...
5
by: premMS143 | last post by:
I'm having idea in VB 6.0 & HTML. Based on this trying to build a simple web application using ASP.NET 3.5, VB as code behind & SQL 2000 for database. Here, I got one doubt. In the Login Form,...
13
by: madhuriks | last post by:
hi, i m new to xml..in my project..i need to develop xml file..i had done it...i used jsp pages for entering the values in xml file...if i enter the same value which is present in xml file...it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.