Android XML Document Search getInteger(Document doc, String tagName)

Here you can find the source of getInteger(Document doc, String tagName)

Description

get Integer

Declaration

public static Integer getInteger(Document doc, String tagName)
            throws Exception 

Method Source Code

//package com.java2s;
import org.w3c.dom.Document;

import org.w3c.dom.NodeList;

public class Main {
    public static Integer getInteger(Document doc, String tagName)
            throws Exception {
        NodeList values = doc.getDocumentElement().getElementsByTagName(
                tagName);//from  w w  w.j  a v a2 s . com
        if (values.getLength() == 1) {
            return Integer.parseInt(values.item(0).getTextContent()); // TODO NumberFormatExceptionHandling
        }
        throw new Exception("more than one " + tagName + " elements"); // TODO create custom exception
    }
}

Related

  1. getFirstElementByTagName(Document doc, String name)
  2. getString(Document doc, String tagName)
  3. getStringDataAsList(Document vastDoc, String elementName)
  4. getStringDataAsList(Document vastDoc, String elementName, String attributeName, String attributeValue)