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

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

Description

get String

Declaration

public static String getString(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 String getString(Document doc, String tagName)
            throws Exception {
        NodeList values = doc.getDocumentElement().getElementsByTagName(
                tagName);//from   w ww  .  j  a v a2s . c o  m
        if (values.getLength() == 1) {
            return values.item(0).getTextContent();
        }
        throw new Exception("more than one " + tagName + " elements"); // TODO create custom exception
    }
}

Related

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