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

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

Description

get Matcher For Xml Tags

Declaration

public static Matcher getMatcherForXmlTags(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 getMatcherForXmlTags(String xml, String tag) {
        String regexCode = "(?<=<" + tag + ">)(.*?)(?=</" + tag + ">)";
        Matcher m = regexGetMatcherForPattern(xml, regexCode);
        return m;
    }//  ww  w  .j a v a  2  s.com

    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. getMatcherWithSurroundingTags(String xml, String tag)
  2. getValueInsideXmlTags(String xml, String openTag, String closeTag)
  3. getValueInsideXmlTags(String xml, String tag)
  4. getValueWithSurroundingTags(String xml, String tag)