Android XML Document to String Convert getErrorText(Document xml)

Here you can find the source of getErrorText(Document xml)

Description

get Error Text

License

Open Source License

Declaration

public static String getErrorText(Document xml) 

Method Source Code

//package com.java2s;
//License from project: MIT License 

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Main {
    public static String getErrorText(Document xml) {
        NodeList errorNodes = xml.getElementsByTagName("error");
        if (errorNodes.getLength() > 0) {
            Element errorElement = (Element) errorNodes.item(0);
            return getElementText(errorElement);
        }//from ww w  . j  av a2s  .c o m
        return null;
    }

    public static String getElementText(Element element) {
        StringBuilder text = new StringBuilder();
        NodeList childNodes = element.getChildNodes();
        int numChildren = childNodes.getLength();
        for (int j = 0; j < numChildren; j++) {
            text.append(childNodes.item(j).getNodeValue());
        }
        return text.toString();
    }
}

Related

  1. toXML(Document document)
  2. getXml(Document doc)
  3. numResults(Document doc)
  4. documentToString(Node n)
  5. xmlDocumentToString(Document document)
  6. xmlToString(Document doc)