I am trying to parse this particular latitude and longitude string into my XML Parser written in Java, but I am not sure what element to use, as point does not having a closing />
<data>
<location>
<location-key>point1</location-key>
<point latitude="39.95" longitude="-75.17"/>
</location>
<moreWeatherInformation applicable-location="point1">
http://forecast.weather.gov/MapClick.php?textField1=39.95&textField2=-75.17
</moreWeatherInformation>
<time-layout time-coordinate="local" summarization="none">
<layout-key>k-p24h-n1-1</layout-key>
<start-valid-time>2013-10-30T08:00:00-04:00</start-valid-time>
<end-valid-time>2013-10-30T20:00:00-04:00</end-valid-time>
</time-layout>
<time-layout time-coordinate="local" summarization="none">
<layout-key>k-p24h-n2-2</layout-key>
<start-valid-time>2013-10-29T20:00:00-04:00</start-valid-time>
<end-valid-time>2013-10-30T09:00:00-04:00</end-valid-time>
<start-valid-time>2013-10-30T20:00:00-04:00</start-valid-time>
<end-valid-time>2013-10-31T09:00:00-04:00</end-valid-time>
</time-layout>
<parameters applicable-location="point1">
<temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n1-1">
<name>Daily Maximum Temperature</name>
<value>64</value>
</temperature>
<temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n2-2">
<name>Daily Minimum Temperature</name>
<value>44</value>
<value>52</value>
</temperature>
</parameters>
</data>
Using the code below, I get the following output.
try {
File newXMLFile = new File("H:\\520\\SOAP Data Acquisition\\testNOAA.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(newXMLFile);
doc.getDocumentElement().normalize();
System.out.println("Title: " + doc.getElementsByTagName("title").item(0).getTextContent());
System.out.println("Field: " + doc.getElementsByTagName("field").item(0).getTextContent());
System.out.println("category: " + doc.getElementsByTagName("category").item(0).getTextContent());
System.out.println("Date Created: " + doc.getElementsByTagName("creation-date").item(0).getTextContent());
NodeList nList = doc.getElementsByTagName("data");
for(int i = 0; i < nList.getLength(); i++){
Node nNode = nList.item(i);
System.out.println("\nCurrent Element: " + nNode.getNodeName());
if(nNode.getNodeType() == Node.ELEMENT_NODE){
Element eElement = (Element) nNode;
System.out.println("Location: " + eElement.getAttribute("point"));
System.out.println("Start Time: "+eElement.getElementsByTagName("start-valid-time").item(0).getTextContent());
System.out.println("End Time: "+eElement.getElementsByTagName("end-valid-time").item(0).getTextContent());
System.out.println("");
}
}
}catch(Exception e){
e.printStackTrace();
}
Output:
Title: NOAA's National Weather Service Forecast Data
Field: meteorological
category: forecast
Date Created: 2013-10-29T14:42:58Z
Current Element: data
Location:
Start Time: 2013-10-30T08:00:00-04:00
End Time: 2013-10-30T20:00:00-04:00
For the relevant part of your code try this instead. It's assuming there's only going to be one "point" in the entire "data" tag (or at least, that you're only interested in the first "point"), but it works for what you have posted.
NodeList nList = doc.getElementsByTagName("data");
for(int i = 0; i < nList.getLength(); i++){
Node nNode = nList.item(i);
System.out.println("\nCurrent Element: " + nNode.getNodeName());
if(nNode.getNodeType() == Node.ELEMENT_NODE){
Element eElement = (Element) nNode;
Element point = (Element)(eElement.getElementsByTagName("point").item(0));
System.out.println("Location: " + point.getAttribute("latitude") + ", " + point.getAttribute("longitude"));
System.out.println("Start Time: "+eElement.getElementsByTagName("start-valid-time").item(0).getTextContent());
System.out.println("End Time: "+eElement.getElementsByTagName("end-valid-time").item(0).getTextContent());
System.out.println("");
}
}
Related
How to get the values of the name tag which is nested under the grouped tag below. I am able to get the values of the name nested under column tag. How to get the nested values of name coming under grouped tag.The attributes of name tag coming under grouped tag is different.
<Services>
<Service name="check" regrx="" reverseExtention="" >
<File rootProfile="Test" extension="txt" seperator="," targetSeperator="q12">
<Columns>
<name id="1" usn="2234" dob="030395" age="55" validity="20" />
<name id="2" usn="I_TWO" dob="true" age="10" validity="44" >
<grouped>
<name id="343" value1="TYPE0" value2="TYPE4" type="" value7="1"></name>
<name id="564" value1="TYPE6" value2="TYPE7" type="" value7="0"></name>
</grouped>
</name>
<name id="3" usn="55453" dob="050584" age="35" validity="123"/>
<name id="5" usn="7565" dob="050488" age="44" validity="55"/>
</Columns>
</File>
</Service>
</Services>
Here is my code below
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
File fXmlFile = new File("D://test3.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nodeList0 = doc.getElementsByTagName("Service");
NodeList nodeList1 = doc.getElementsByTagName("File");
NodeList nodeList2 = doc.getElementsByTagName("name");
NodeList nodeList3= doc.getElementsByTagName("grouped");
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
for (int temp0 = 0; temp0 < nodeList0.getLength(); temp0++) {
Node node0 = nodeList0.item(temp0);
System.out.println("\nElement type :" + node0.getNodeName());
Element Service = (Element) node0;
System.out.println("----" + temp0 + "-------");
if (node0.getNodeType() == Node.ELEMENT_NODE) {
System.out.println("Name : " + Service.getAttribute("name"));
System.out.println("regrx : " + Service.getAttribute("regrx"));
System.out.println("reverex"+Service.getAttribute("reverseExtention"));
for (int temp = 0; temp < nodeList1.getLength(); temp++) {
Node node1 = nodeList1.item(temp);
System.out.println("------file" + temp + "--------");
System.out.println("\nElement type :" + node1.getNodeName());
Element File = (Element) node1;
//used for getting file level
if (node1.getNodeType() == Node.ELEMENT_NODE) {
System.out.println("rootProfile:" + File.getAttribute("rootProfile"));
System.out.println("extension : " + File.getAttribute("extension"));
System.out.println("seperator : " + File.getAttribute("seperator"));
System.out.println("targetSeperator : " + File.getAttribute("targetSeperator"));
for(int temp2=0;temp2<nodeList2.getLength();temp2++){
Node node2 = nodeList2.item(temp2);
Element name = (Element) node2;
if (node2.getNodeType() == Node.ELEMENT_NODE) {
System.out.println("id:" + name.getAttribute("id"));
System.out.println("usn : " + name.getAttribute("usn"));
System.out.println("dob : " + name.getAttribute("dob"));
System.out.println("age : " + name.getAttribute("age"));
System.out.println("validity : " + name.getAttribute("validity"));
//to get grouped node, the problem seems to be here
Node node3=nodeList3.item(temp2);
if(node3.hasChildNodes()){
Element grouped=(Element)node3;
if(node3.getNodeType()==Node.ELEMENT_NODE){
System.out.println("id:" + grouped.getAttribute("id"));
System.out.println("value1:" + grouped.getAttribute("value1"));
System.out.println("value2:" + grouped.getAttribute("value2"));
System.out.println("type:" + grouped.getAttribute("type"));
System.out.println("value7:" + grouped.getAttribute("value7"));
}
}
}
}
}
}
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
Below is your modified code
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
File fXmlFile = new File("D://test3.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nodeList0 = doc.getElementsByTagName("Service");
NodeList nodeList1 = doc.getElementsByTagName("File");
NodeList nodeList2 = doc.getElementsByTagName("name");
NodeList nodeList3 = doc.getElementsByTagName("grouped");
System.out.println("Root element :"
+ doc.getDocumentElement().getNodeName());
for (int temp0 = 0; temp0 < nodeList0.getLength(); temp0++) {
Node node0 = nodeList0.item(temp0);
System.out.println("\nElement type :" + node0.getNodeName());
Element Service = (Element) node0;
System.out.println("----" + temp0 + "-------");
if (node0.getNodeType() == Node.ELEMENT_NODE) {
System.out
.println("Name : " + Service.getAttribute("name"));
System.out.println("regrx : "
+ Service.getAttribute("regrx"));
System.out.println("reverex"
+ Service.getAttribute("reverseExtention"));
for (int temp = 0; temp < nodeList1.getLength(); temp++) {
Node node1 = nodeList1.item(temp);
System.out.println("------file" + temp + "--------");
System.out.println("\nElement type :"
+ node1.getNodeName());
Element File = (Element) node1;
// used for getting file level
if (node1.getNodeType() == Node.ELEMENT_NODE) {
System.out.println("rootProfile:"
+ File.getAttribute("rootProfile"));
System.out.println("extension : "
+ File.getAttribute("extension"));
System.out.println("seperator : "
+ File.getAttribute("seperator"));
System.out.println("targetSeperator : "
+ File.getAttribute("targetSeperator"));
for (int temp2 = 0; temp2 < nodeList2.getLength(); temp2++) {
Node node2 = nodeList2.item(temp2);
Element name = (Element) node2;
if (node2.getNodeType() == Node.ELEMENT_NODE) {
System.out.println("id:"
+ name.getAttribute("id"));
System.out.println("usn : "
+ name.getAttribute("usn"));
System.out.println("dob : "
+ name.getAttribute("dob"));
System.out.println("age : "
+ name.getAttribute("age"));
System.out.println("validity : "
+ name.getAttribute("validity"));
// to get grouped node, the problem seems to
// be here
// Node node3 = nodeList3.item(temp2);
NodeList grouped = node2.getChildNodes();
if (grouped != null
&& grouped.getLength() > 0) {
for (int ii = 0; ii < grouped
.getLength(); ii++) {
Node group = grouped.item(ii);
{
NodeList gropedNames = group
.getChildNodes();
if (gropedNames != null
&& gropedNames
.getLength() > 0) {
for (int jj = 0; jj < gropedNames
.getLength(); jj++) {
if (gropedNames
.item(jj) != null
&& gropedNames
.item(jj)
.getAttributes() != null) {
System.out
.println(gropedNames
.item(jj)
.getAttributes()
.getNamedItem(
"id"));
System.out
.println(gropedNames
.item(jj)
.getAttributes()
.getNamedItem(
"value1"));
System.out
.println(gropedNames
.item(jj)
.getAttributes()
.getNamedItem(
"value2"));
System.out
.println(gropedNames
.item(jj)
.getAttributes()
.getNamedItem(
"value7"));
}
}
}
}
}
}
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
If you need the nested name tags under the grouped, then ask the elements from the grouped tag and not from the document.
Document.getElementsByTagName() gives you back all tags by that name, calling getElementsByTagName() on an Element will give you back all the descendant elements of the Elemenent (e.g. child, grandchild etc.).
You can safely cast the grouped Node to Element and call getElementsByTagName() on it:
NodeList groupedNodeList = doc.getElementsByTagName("grouped");
for (int i = 0; i < groupedNodeList .getLength(); i++) {
Element groupedElement = (Element) groupedNodeList .item(i);
NodeList nameList = groupedElement.getElementsByTagName("name");
// Here you go, you have the list of name tags UNDER grouped
// Printing the id and value attributes of the name tag:
for (int j = 0; j < nameList.getLength(); j++) {
Element name = (Element) nameList.item(j);
System.out.println("Found <name>: id=" + name.getAttribute("id"));
System.out.println("\tvalue1=" + name.getAttribute("value1"));
System.out.println("\tvalue2=" + name.getAttribute("value2"));
System.out.println("\tvalue7=" + name.getAttribute("value7"));
}
}
Output is:
Found <name>: id=343
value1=TYPE0
value2=TYPE4
value7=1
Found <name>: id=564
value1=TYPE6
value2=TYPE7
value7=0
I am stuck I want to parse a tiled map file, and there is one problem. I dont know how can I get x,y,width,height element, and how can I rebuild back this xml. I will be very grateful for your help.
<objectgroup name="Meter">
<object type="meter" x="3232" y="6016" width="512" height="96">
<properties>
<property name="id" value="1"/>
</properties>
</object>
My Java source code:
public void readXml () throws ParserConfigurationException{
File fXmlFile = new File("xml1.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = null;
try {
doc = dBuilder.parse(fXmlFile);
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
doc.getDocumentElement().normalize();
System.out.println(doc.toString());
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("objectgroup");
System.out.println("----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
System.out.println("\nCurrent Element :" + nNode.getAttributes().getNamedItem("meter"));
}}
You have to make a couple of adjustments, first you have to traverse all the childs and get all the object elements, an then get their attribute values, I know this is not an optimal solution, but will get you what you need:
System.out.println("Root element :"
+ doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("objectgroup");
System.out.println("----------------------------");
for (int temp = 0; temp < nList.getLength(); temp++) {
// for that will go for all objectGroups
Node nNode = nList.item(temp);
NodeList childs = nNode.getChildNodes();
for (int i = 0; i < childs.getLength(); i++) {
Node child = childs.item(i);
if (child.getNodeName().equals("object")) {
// check if we are evaluating an <object> element
System.out.println("\nCurrent Element :"
+ child.getNodeName());
NamedNodeMap attrs = child.getAttributes();
Node x = attrs.item(3), y = attrs.item(4), height = attrs
.item(0), width = attrs.item(2), type = attrs
.item(1);
System.out.println("\n x :" + x.getNodeValue() + " | y : "
+ y.getNodeValue() + " | height: "
+ height.getNodeValue() + " | width: "
+ width.getNodeValue());
}
}
}
im trying to parse xml file, but it wont print attribut value. I dont know how to get attribute typ from phone
try { String subor = "Noviny.xml";
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(subor);
System.out.println("----------------\n");
NodeList nodelist = document.getElementsByTagName("Author");
NodeList nodelist1 = document.getElementsByTagName("Article");
for(int i = 0; i < nodelist.getLength(); i++) {
Node uzol = nodelist.item(i);
if (uzol.getNodeType() == Node.ELEMENT_NODE)
{
Element element = (Element) uzol;
System.out.println("Id:" + element.getElementsByTagName("Id").item(0).getTextContent() + "\n");
System.out.println("Name:" + element.getElementsByTagName("Name").item(0).getTextContent() + "\n");
System.out.println("Email:" + element.getElementsByTagName("Email").item(0).getTextContent() + "\n");
System.out.println("typ: " + element.getAttribute("typ") + "\n");
System.out.println("phone:" + element.getElementsByTagName("phone").item(0).getTextContent() + "\n");
System.out.println("typ: " + element.getAttribute("typ") + "\n");
System.out.println("sal: " + element.getElementsByTagName("sal").item(0).getTextContent() + "\n");
}
catch (Exception e) {
e.printStackTrace();
}
and xml
<Noviny>
<Author>
<Id>1</Id>
<Name>first</Name>
<Email>first#gmail.com</Email>
<phone typ="mobil">09443916565</phone>
<sal>500</sal>
</Author>
<Author>
<Id>2</Id>
<Name>second</Name>
<Email>second#gmail.com</Email>
<phone typ="pevna">094415665465</phone>
<sal>1000</sal>
</Author>
and one more thing:ňIs it possible to just print (System.out.println) tree representation of xml file?
thank you
You're currently asking for the typ attribute of the <Author> element (twice, for some reason). You should fetch the <phone> element (which you're already doing) and then ask for the typ attribute of that element, rather than the <Author> element.
I'm trying to parse this XML in Java:
<entities>
<entity name="product_section" id="1">
<product_type>3</product_type>
<section_type>1</section_type>
<name>Empresa</name>
<description>d</description>
<position>1</position>
<align>left</align>
<files section_id="1">
<ico id="ico_1" type="normal" src="sections/1/icons/ico.png"></ico>
<ico id="ico_2" type="hover" src="sections/1/icons/ico.png"></ico>
<ico id="ico_3" type="active" src="sections/1/icons/ico.png"></ico>
<img id="img_1" type="normal" src="sections/1/img/pestanya.png"></img>
<img id="img_2" type="hover" src="sections/1/img/pestanya-hover.png"></img>
<img id="img_3" type="active" src="sections/1/img/pestanya-active.png"></img>
<background id="background_1" type="background" position="1" src="sections/1/background/bg1.png"></background>
<background id="background_2" type="background" position="2" src="sections/1/background/bg2.png"></background>
<background id="background_3" type="background" position="3" src="sections/1/background/bg3.png"></background>
</files>
</entity>
But I just achieved to loop through Entities, getting all Entity and each <product_type>, <section_type>, etc.
But I want to loop through files too.
This is my implementation so far:
try {
File contingut = new File("xmlfile.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(contingut);
doc.getDocumentElement().normalize();
System.out.println("root of xml file " + doc.getDocumentElement().getNodeName());
//loop a cada entity
NodeList nodes = doc.getElementsByTagName("entity");
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
Element element = (Element) node;
System.out.println("product_type: " + getValue("product_type", element));
System.out.println("section_type: " + getValue("section_type", element));
System.out.println("name: " + getValue("name", element));
System.out.println("description: " + getValue("description", element));
System.out.println("position: " + getValue("position", element));
System.out.println("align: " + getValue("align", element));
}
} catch (Exception e){
e.printStackTrace();
}
getValue function is:
private static String getValue(String tag, Element element) {
NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
Node node = (Node) nodes.item(0);
return node.getNodeValue();
}
I've done lot of google search, and all I find are "simple" examples, with a parent, and a child, but not child's child.
Any help would be appreciated.
At first one suggestion:
check element type after this Element element = (Element) node;
use this code or something like this :
if (element.getNodeType() == Element.ELEMENT_NODE) { // do smth}
and answer to your question:
You can simply rewrite you code. after you create element you can get all it's child elements by using element.getChildNodes();
it gives you all child tags. After that you write simple for loop where you get each node element from node list like this :
NodeList nodes = element.getChildNodes();
for(int i =0; i < nodes.getLength(); i++){
Element child = (Element) nodes.item(i);
if(child.getNodeType() == Element.ELEMENT_NODE){
String tagName = child.getTagName();
if(!tagName.equals("files")){
System.out.println(tagName + " : " + child.getTextContent());
}else{
NodeList filesChilds = child.getChildNodes();
for(int j = 0; j < filesChilds.getLength(); j++){
//and like above
}
}
}
}
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:
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 = (Node) nlList.item(0);
return nValue.getNodeValue();
}
}
Here is a portion of the XML file:
<?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>
System.out created this:
Cue Name : stuff and junk
Cue Number : 1
-----------------------
DMX Length: 1
DMX Chnl: 1
DMX Val : 0
What am I doing wrong?
shortened xml:
<?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>
added loop:
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);
}
}
Java and the XML parser behave correctly.
But you expect the document to have a different structure than it actually does! So you are looking in the wrong place for nodes, and thus not finding nodes there.
There is only one DMX element. You want to enumerate the children, not the DMX elements.
(i.e. you want to have DMX_Chnl elements, and these are not each wrapped in a separate DMX node)