473,569 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hello, im new to java. i hav a code in which is it should not print duplicate values

1 New Member
but it is displaying al values der in xml file.it should avoid reading duplicate values ,pls help me..
my code is,

Expand|Select|Wrap|Line Numbers
  1. public class nm {
  2. public static void main(String argv[]) {
  3.  
  4.   try {
  5.   File file = new File("c://adv.xml");
  6.   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  7.   DocumentBuilder db = dbf.newDocumentBuilder();
  8.   Document doc = db.parse(file);
  9.   doc.getDocumentElement().normalize();
  10.   System.out.println("Root element " + doc.getDocumentElement().getNodeName());
  11.   NodeList nodeLst = doc.getElementsByTagName("Z12");
  12.   for (int s = 0; s < nodeLst.getLength(); s++) {
  13.  
  14.         Node fstNode = nodeLst.item(s);
  15.  
  16.         if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
  17.  
  18.                Element fstElmnt = (Element) fstNode;
  19.           NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("Value");
  20.           Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
  21.           NodeList fstNm = fstNmElmnt.getChildNodes();
  22.           //System.out.println("value : "  + ((Node) fstNm.item(0)).getNodeValue());
  23.           NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("DisplayName");
  24.           Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
  25.           NodeList lstNm = lstNmElmnt.getChildNodes();
  26.           String zf=((Node) lstNm.item(0)).getNodeValue();
  27.  
  28.               System.out.println("Diaplay Name : " + zf);
  29.  
  30.         }
  31.  
  32.       }
  33.       } catch (Exception e) {
  34.         e.printStackTrace();
  35.       }
  36.      }
  37.     } 
this is my code,
ouput is,
Root element Search_Config
value : BC
Diaplay Name : Bearing complete
value : BC01
Diaplay Name : Bearing complete 01
value : BC
Diaplay Name : Bearing complete
value : BC01
Diaplay Name : Bearing complete 01

but here i want bc, bc01 shoud print only once not twice.
Nov 16 '08 #1
1 1322
JosAH
11,448 Recognized Expert MVP
For every element with index i in your list check whether it is also in the list at
position [0,i-1]. If it is, don't print it because you have seen it in the list before.

Hint: make a separate, private, little (boolean) method to search for the element.

kind regards,

Jos
Nov 16 '08 #2

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

Similar topics

73
7932
by: RobertMaas | last post by:
After many years of using LISP, I'm taking a class in Java and finding the two roughly comparable in some ways and very different in other ways. Each has a decent size library of useful utilities as a standard portable part of the core language, the LISP package, and the java.lang package, respectively. Both have big integers, although only...
3
3586
by: Markus Dehmann | last post by:
I have a two different value types with which I want to do similar things: store them in the same vector, stack, etc. Also, I want an << operator for each of them. class Value{}; // this would be "public interface Value{}" in Java! class IntValue : public Value{ private: int _value; public:
6
2052
by: Rhino | last post by:
I am writing Java UDFs using DB2 V8.2 (Fixpack 8) on Windows XP. I would like to create some common code classes that are visible to the UDFs on my system but I'm not having a lot of luck so far. I'm wondering if I'm trying to do the impossible or if my technique is just wrong. One of the common code classes I want to write contains code...
1
9607
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
458
20946
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers simply aren't smart enough to understand C++? This is not merely a whimsical hypothesis. Given my experience with Java programmers --- the code they...
26
3203
by: Christoph Zwerschke | last post by:
You will often hear that for reasons of fault minimization, you should use a programming language with strict typing: http://turing.une.edu.au/~comp284/Lectures/Lecture_18/lecture/node1.html I just came across a funny example in which the opposite is the case. The following is a binary search algorithm in Java. It searches a value in an...
5
6268
by: r035198x | last post by:
Setting up. Getting started To get started with java, one must download and install a version of Sun's JDK (Java Development Kit). The newest release at the time of writting this article is JDK 6 downloadable from http://java.sun.com/javase/downloads/index.jsp. I will be using JDK 5(update 8)
2
3740
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error when i do the following. if you add a contact with up to 13 fields it will be stored in a data structure. i have a tabbed pane that will show six of...
0
7618
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...
1
7679
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...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
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...
0
3657
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...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
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...

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.