Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML dealing with the NamedNodeMap interface

 
jeff culler
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NodeList theNodeList = parentNode.getChildNodes();
first_EditionSections.setNamedItem( theNodeList.item(1) );
here' a bit of the code.
keep getting java.lang.NullPointerException
Does the node I place in a NamedNodeMap must have
an attribute named "nodeName" or nodeName refer
to the actual name of the node?
I am sure all nodes point to actual xml.
Could someone perhaps post a sample of how
to use the NamedNodeMap?
thanks
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could be getting the null pointer if the node list has 0 or 1 items.
NamedNodeMap only appears to require a String when adding a node, what are you going to do with it after you added the node?
Bill
 
jeff culler
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this was xml that corresponed to a series
of scrollpanes that resided in a JPanel
that used the cardlayout.
I have done some more research on the
NamedNodeMap and the only use I have
seen is to put a node's Attributes in,
to retrieve later.
Can you not simply put a node <a> ,<b> ,<c>
into NamedNodeMap "FirstEditionSections"
Then later retrieve any xml node back by
FirstEditionSections.getNamedItem("a")
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to use this to modify the DOM or just as a handy way to pass things around?
From the API it looks like you should be able to create a Node, add it to the map and later recover it by name, but I have never done it.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic