Android XML String to Text Convert getMatcherWithSurroundingTags(String xml, String tag)

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

Description

get Matcher With Surrounding Tags

Declaration

public static Matcher getMatcherWithSurroundingTags(String xml,
            String tag) 

Method Source Code

//package com.java2s;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static Matcher getMatcherWithSurroundingTags(String xml,
            String tag) {/*from   w  ww .j  a  v a  2 s  . com*/
        String regexCode = "(<" + tag + ".*?>)(.*?)(</" + tag + ">)";
        Matcher m = regexGetMatcherForPattern(xml, regexCode);
        return m;
    }

    public static Matcher regexGetMatcherForPattern(String string,
            String pattern) {
        if (string == null || pattern == null) {
            return null;
        }

        /**
         * strip newline characters because it doesn't work well with this.
         */
        //    string = string.replace("\n", "");

        Pattern p = Pattern.compile(pattern, Pattern.DOTALL
                | Pattern.MULTILINE);
        Matcher m = p.matcher(string);

        return m;
    }
}

Related

  1. getMatcherForXmlTags(String xml, String tag)
  2. getValueInsideXmlTags(String xml, String openTag, String closeTag)
  3. getValueInsideXmlTags(String xml, String tag)
  4. getValueWithSurroundingTags(String xml, String tag)