Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can some one help I keep getting a d**m null value and no examples work

 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Document document = parser.getDocument();
Element RootElement = document.getDocumentElement();
NodeList Children = RootElement.getChildNodes();


NodeList ndeList = Children;
NodeList ndeMenuList;
NodeList ndeMenuItemList;
for(int i=0; i<ndeList.getLength();i++) {
if ( ndeList.item(i).getNodeType() == Node.ELEMENT_NODE ) {
String text = "";
//if ( ndeList.item(i).getNodeType() == Node.TEXT_NODE )
System.out.println(ndeList.item(i).getNodeName() + " = " + ndeList.item(i).getFirstChild().getNodeValue());

if ( ndeList.item(i).hasChildNodes() ) {
ndeMenuList = ndeList.item(i).getChildNodes();
for( int j=0; j < ndeMenuList.getLength(); j++ ) {
if ( ndeMenuList.item(j).getNodeType() == Node.ELEMENT_NODE ) {
System.out.println("\t" + ndeMenuList.item(j).getNodeName() + " = " + ndeMenuList.item(j).getFirstChild().getNodeValue() );
if ( ndeMenuList.item(j).getNodeType() == Node.ELEMENT_NODE ) {
ndeMenuItemList = ndeMenuList.item(j).getChildNodes();
for(int k=0; k<ndeMenuItemList.getLength();k++) {
System.out.println("\t\t" + ndeMenuItemList.item(k).getNodeName() + " = " + ndeMenuItemList.item(k).getNodeValue() );
}
}
}

}

}
}
}
I have this code and every time I do getNodeValue it returns null value when it prints
the examples say use getFirstChild() but it doesnt have a childNode
 
Nicholas Turner
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nevermind i figured it out
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic