QUEEPTVEINIUB
New Member
I'm working on reading DMX Values from an XML document. The method only returns one node from the element that I'm trying to pull from but there should be 512.Here is the method:\[code\]public static void readXML(int cueNo){ try { File fXmlFile = new File(MixWindow.Globals.fileLoc); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(fXmlFile); doc.getDocumentElement().normalize(); System.out.println("Root element :" + doc.getDocumentElement().getNodeName()); NodeList nList = doc.getElementsByTagName("Cue"); System.out.println("-----------------------"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = (Node) nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; System.out.println("Cue Name : " + getTagValue("Cue_Name", eElement)); System.out.println("Cue Number : " + getTagValue("Cue_Number", eElement)); //System.out.println("Nick Name : " + getTagValue("nickname", eElement)); //System.out.println("Salary : " + getTagValue("salary", eElement)); } } NodeList nListII = doc.getElementsByTagName("DMX"); //nListII = doc.getElementsByTagName("DMX"); System.out.println("-----------------------"); int length = nListII.getLength(); System.out.println("DMX Length: " + length); for (int tempII = 0; tempII < nListII.getLength(); tempII++) { Node nNodeII = (Node) nListII.item(tempII); if (nNodeII.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNodeII; System.out.println("DMX Chnl: " + getTagValue("DMX_Chnl", eElement)); System.out.println("DMX Val: " + getTagValue("DMX_Val", eElement)); //System.out.println("Nick Name : " + getTagValue("nickname", eElement)); //System.out.println("Salary : " + getTagValue("salary", eElement)); } } } catch (Exception e) { e.printStackTrace(); } } private static String getTagValue(String sTag, Element eElement) { NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes(); Node nValue = http://stackoverflow.com/questions/13779229/(Node) nlList.item(0); return nValue.getNodeValue(); } }\[/code\]Here is a portion of the XML file:\[code\]<?xml version="1.0" encoding="UTF-8" standalone="no"?><ShowFile><Cue><Cue_Name>stuff and junk</Cue_Name><Cue_Number>1</Cue_Number></Cue><DMX><DMX_Chnl>1</DMX_Chnl> <DMX_Val>0</DMX_Val><DMX_Chnl>2</DMX_Chnl> <DMX_Val>0</DMX_Val><DMX_Chnl>3</DMX_Chnl> <DMX_Val>0</DMX_Val><DMX_Chnl>4</DMX_Chnl> <DMX_Val>0</DMX_Val>...... <DMX_Chnl>512</DMX_Chnl> <DMX_Val>0</DMX_Val>\[/code\]System.out created this:\[code\]Cue Name : stuff and junkCue Number : 1-----------------------DMX Length: 1DMX Chnl: 1DMX Val : 0\[/code\]What am I doing wrong?shortened xml:\[code\]<?xml version="1.0" encoding="UTF-8" standalone="no"?><ShowFile><Cue><Cue_Name>Stuff and Junk</Cue_Name><Cue_Number>1</Cue_Number></Cue><DMX><DMX_Chnl>1</DMX_Chnl><DMX_Val>0</DMX_Val><DMX_Cue>1</DMX_Cue><DMX_Chnl>2</DMX_Chnl><DMX_Val>0</DMX_Val><DMX_Cue>1</DMX_Cue><DMX_Chnl>3</DMX_Chnl><DMX_Val>0</DMX_Val><DMX_Cue>1</DMX_Cue><DMX_Chnl>4</DMX_Chnl></DMX></ShowFile>\[/code\]added loop:\[code\]if (nNodeII.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNodeII; NodeList childNodes = nNodeII.getChildNodes(); String result = new String(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); String dcName = node.getNodeName(); String dcVal = node.getNodeValue(); System.out.println("DMX stuff: " + dcName + " " + dcVal); } }\[/code\]