473,608 Members | 2,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check the entered field exists are not in xml

149 New Member
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 should throw an alert that 'Already the name exists'...can anyone help me out..i used DOM for creation of XML file...

Thanks in advance..
madhu.
Jun 22 '10 #1
13 5048
jkmyoung
2,057 Recognized Expert Top Contributor
What is the structure of your xml like? Are these values stored in particular elements? Can you get a list of these elements, eg using some sort of getElementsByTa gName function? or SelectNodes?
Jun 22 '10 #2
madhuriks
149 New Member
hi,
here is my XML file...i entered all the values using jsp page..i.e P_Name,M_Status ..etc...if i re-enter the values..it should show me an alert that the name already exists..


Expand|Select|Wrap|Line Numbers
  1. <PD>
  2. <GT>
  3. <GL>
  4. <P_Name>Hello</P_Name>
  5. <M_Status>M</M_Status>
  6. <E_Qualification>B.Tech</E_Qualification>
  7. </GL>
  8. </GT>
  9. </PD>
Thanks in Advance,
madhu.
Jun 22 '10 #3
madhuriks
149 New Member
hi,
i created xml file using DOM...if i enter the values...which are present in xml file...it is not showing any error...it is accepting the value...can anyone suggest me how to check the enter value with existing value...i need help from anyone urgently...

Thanks in advance,
madhu.
Jun 23 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
I would need to see some code to make a sensible statement.
Jun 23 '10 #5
madhuriks
149 New Member
hi,
this is my code waiting for the reply..

Expand|Select|Wrap|Line Numbers
  1. package login;
  2.  
  3. import java.io.*;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6.  
  7. import java.io.*;
  8. import org.w3c.dom.*;
  9. import javax.xml.parsers.*;
  10. import javax.xml.transform.*;
  11. import javax.xml.transform.dom.*;
  12. import javax.xml.transform.stream.*;
  13.  
  14. public class register extends HttpServlet
  15. {
  16.     public void doPost(HttpServletRequest request, HttpServletResponse response)
  17.             throws ServletException, IOException
  18.     {
  19.         response.setContentType("text/html");
  20.         PrintWriter pw = response.getWriter();
  21.         String id = "";
  22.         String name = "";
  23.         String gender = "";
  24.         String qual = "";
  25.         id = request.getParameter("id");
  26.         name = request.getParameter("name");
  27.         gender = request.getParameter("gender");
  28.         qual = request.getParameter("qual");
  29.         try
  30.         {
  31. DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  32. DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
  33. java.io.File file = new java.io.File("E:/login.xml");
  34. Document doc = null;
  35. if (file.exists()) {
  36. doc = docBuilder.parse(file);
  37. } else {
  38. doc = docBuilder.newDocument();
  39. Element root = doc.createElement("LOGIN");
  40. doc.appendChild(root);
  41. }
  42. createXmlTree(doc, id, name, gender, qual);
  43. }
  44. catch (Exception e) {
  45. System.out.println(e);
  46. }
  47. }
  48.  
  49. private void createXmlTree(Document doc, String id, String name, String gender, String qual)
  50. throws Exception {
  51. Node node = doc.getFirstChild();
  52. Node childnode =doc.getChildNodes().item(1);
  53. Element child = doc.createElement("LIST");
  54. Element subchild = doc.createElement("GENERAL");
  55. // adding a node after the last child node of the specified node.
  56. node.appendChild(child);
  57. child.appendChild(subchild);
  58.  
  59. Element child1 = doc.createElement("ID");
  60. subchild.appendChild(child1);
  61. Text text = doc.createTextNode(id);
  62. child1.appendChild(text);
  63.  
  64. Element element = doc.createElement("NAME");
  65. subchild.appendChild(element);
  66. Text text1 = doc.createTextNode(name);
  67. element.appendChild(text1);
  68.  
  69. Element element1 = doc.createElement("GENDER");
  70. subchild.appendChild(element1);
  71. Text text2 = doc.createTextNode(gender);
  72. element1.appendChild(text2);
  73.  
  74. Element element2 = doc.createElement("QUAL");
  75. subchild.appendChild(element2);
  76. Text text3 = doc.createTextNode(qual);
  77. element2.appendChild(text3);
  78.  
  79. // TransformerFactory instance is used to create Transformer objects.
  80.         TransformerFactory factory = TransformerFactory.newInstance();
  81.         Transformer transformer = factory.newTransformer();
  82.         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
  83.         // create string from xml tree
  84.         StringWriter sw = new StringWriter();
  85.         StreamResult result = new StreamResult(sw);
  86.         DOMSource source = new DOMSource(doc);
  87.         transformer.transform(source, result);
  88.         String xmlString = sw.toString();
  89.  
  90.         File file = new File("E:/login.xml");
  91.         BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
  92.                 new FileOutputStream(file)));
  93.         bw.write(xmlString);
  94.         bw.flush();
  95.         bw.close();
  96.  
  97.     }
  98. }
this is my code..can u chk it nd do me the needful..

Thanks in advance,
madhu.
Jun 23 '10 #6
jkmyoung
2,057 Recognized Expert Top Contributor
"...if i enter the same value"
How exactly are you entering these values?

What type of DOM?

It looks like you can just search your P_Name nodes every time you make an entry.
Jun 23 '10 #7
jkmyoung
2,057 Recognized Expert Top Contributor
As you add the nodes, create a vector to hold the already used values. When you try to add new values, compare against the values in the vector.
Jun 23 '10 #8
madhuriks
149 New Member
@jkmyoung
hi,
if i enter the 'P_NAME' value as 'Hello' again it is taking ...how to solve the prob.

Thanks,
madhu.
Jun 24 '10 #9
jkmyoung
2,057 Recognized Expert Top Contributor
Did you try what we suggested? Please show us the code for your try.
Jun 24 '10 #10

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

Similar topics

2
1979
by: PeterW | last post by:
I have a data entry form based on a query. As a user enters data in the fields, I want to check if that data exists in the underlying table. I have tried Dlookup on the table and also a recordset.open with a select query the error message I get trying to open the recordset is along the lines of :
2
13183
by: Pawel Wrobel | last post by:
Hi! I have a folowing situation - in my Access database I have a table that is linked with SPS. I put some data into this table to present it no SPS. The thing is that when I have no connection with SPS then I get ugly VB error message (table is readonly or does not exist) What I would like to do is return nice message like "SPS is not connected" is case of such event. How to do this? One way is to catch the error event and fire a...
13
13169
by: MLH | last post by:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer) If LaborCost > 0 Then Me!LaborCost.Visible = True If MatlsCost > 0 Then Me!MatlsCost.Visible = True If OtherCost > 0 Then Me!OtherCost.Visible = True End Sub I use procedures similar to the above sub in forms to make controls on the form visible when desired. I'm unable to accomplish this in a report's OnFormat property code. How can I do this on a report?
1
5233
by: Dixie | last post by:
I am looking for code that will check if a field (fieldname) exists in a certain table (tablename), then to add it if it does not. Can anyone guide me in the right direction. I think I can add the field, but I need to know how to find if the field is already there. TIA dixie
8
4176
by: News Microsoft | last post by:
Hi there. I would like to know how can I test if a Form exists. This is the situation: I have a single Form in my application. My objective is, when I minimize the form, it will disapear and a TrayIcon apears in the task bar. When I click that icon, the form apears again. The problem is that when I click the icon more than once, the form apears serveral times (several instances).
1
3548
by: Edwina Rothschild | last post by:
Hello, I am new to PHP so I have done a research on how to check if an entry exists on the table. I came up with the following code: include("dbinfo.inc.php"); $Name=$_POST; $Code=$_POST; mysql_connect($host,$username,$password); @mysql_select_db($database) or die( "Unable to select database");
3
3606
by: pollygw | last post by:
I have a page that dynamically adds rows to a table and the user can also delete any of the rows in no specific order. When the form is submitted I need to do some validation. I can't loop through it because the names may by out of sequence if the user deleted some lines, so I need to check whether that particular text field exists. For some reason I can't reference the newly created text fields. I tried referencing it by id and by name but...
1
14009
by: jillB02 | last post by:
does anyone have some simple VBA code to determine if a Field exists in an Access Table? I am using Access 2003. All help and suggestions much appreciated regards from, Jill
1
1906
by: Agnes | last post by:
pKcno = myReader.Item("kcno") <--it will return error when the field "kcno" doesn't exist any method to check the field exist or not first , if not exist, I want to skip the above statement. Thanks
1
2092
omerbutt
by: omerbutt | last post by:
hi there i am new to php ,have been working in asp classic and access but now have switched to php and mysql,and for the practice sake i started to convert my asp and access based projects into php and mysql, i have a inventory system in which i have a stock entry Portion which has aloots of fields concerning to the codeno,partno, auto , product,quantity, size, height and lots of other fields too but our main concern is with these two "CODENO...
0
8067
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8010
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8501
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8157
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8349
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5479
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3967
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4030
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1336
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.