Java XML DOM int value

Say I have a line within an xml file that is:

<number> 7 </number>

I want to store the value of 7 in an integer in java, but dont know how.. .heres my code so far

if (nodelist.getNodeType() == Node.ELEMENT_NODE &&
                                ((Element) nodelist).getTagName().equals("number")){
                            //store value as int (int value = number in tags)
                        }

Answers


int seven = Integer.parseInt(theNode.getNodeValue());

You could use a utility like jOOX that wraps the standard DOM API to simplify things. Here's how you could access that <number/> element:

Integer seven = $(document).find("number").text(Integer.class);

instead of

Integer seven = Integer.parseInt(
  ((Element) document.getElementsByName("name").item(0)).getTextContent());

Need Your Help

TableView rotates vertical images in Swift 2

ios swift uitableview uiimage

I have 2 views. One is TableView with custom cells (image and label) and second is adding data. I implemented taking pictures/choosing one from a library. If the image is longer than wider TableView

what are Magento products tables

database magento import

I have imported a database from 1.4.1 to 1.8 magento store, and it's seems that products doesn't appear in the back-end or in the front-end , But they show in Catalog &gt; manage categories.