Android XML String Build getXmlBetweenTag(String xml, String tag)

Here you can find the source of getXmlBetweenTag(String xml, String tag)

Description

get Xml Between Tag

Parameter

Parameter Description
xml the origin response return from ONVIF device
tag tag name of destination border

Return

the content between tag

Declaration

public static String getXmlBetweenTag(String xml, String tag) 

Method Source Code

//package com.java2s;

import android.util.Log;

public class Main {
    private static final String TAG = "XstreamUtil";

    /**//from www  . j av  a  2  s .  c om
     * @param xml the origin response return from ONVIF device
     * @param tag tag name of destination border
     * @return the content between tag
     */
    public static String getXmlBetweenTag(String xml, String tag) {
        if (xml == null) {
            Log.e(TAG, "getXmlBetweenTag, params xml:" + xml + ", tag:"
                    + tag);
            return "";
        }
        String ret = "";
        String start = "<" + tag + ">";
        String end = "</" + tag + ">";
        int startIndex = xml.indexOf(start) + start.length();
        int endIndex = xml.indexOf(end);
        Log.i(TAG, "getXmlBetweenTag, startIndex:" + startIndex
                + ", endIndex:" + endIndex);
        if (startIndex > 0 && endIndex > startIndex) {
            ret = xml.substring(startIndex, endIndex);
        }
        //Log.i(TAG, "getXmlBetweenTag, ret:" + ret);
        return ret;
    }
}

Related

  1. addElement(StringBuffer out, String tag, String content)
  2. createCloseTag(String tagname)
  3. createCloseTagNewLine(String tagname)
  4. createOpenTag(String tagname)
  5. createOpenTagNewLine(String tagname)