my code is,
Expand|Select|Wrap|Line Numbers
- public class nm {
- public static void main(String argv[]) {
- try {
- File file = new File("c://adv.xml");
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(file);
- doc.getDocumentElement().normalize();
- System.out.println("Root element " + doc.getDocumentElement().getNodeName());
- NodeList nodeLst = doc.getElementsByTagName("Z12");
- for (int s = 0; s < nodeLst.getLength(); s++) {
- Node fstNode = nodeLst.item(s);
- if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
- Element fstElmnt = (Element) fstNode;
- NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("Value");
- Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
- NodeList fstNm = fstNmElmnt.getChildNodes();
- //System.out.println("value : " + ((Node) fstNm.item(0)).getNodeValue());
- NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("DisplayName");
- Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
- NodeList lstNm = lstNmElmnt.getChildNodes();
- String zf=((Node) lstNm.item(0)).getNodeValue();
- System.out.println("Diaplay Name : " + zf);
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
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.