How Parse XML Using Regular Expressions in Asp.net with C#


Hello Friends, I am Nikunj R Satasiya.and Tody I dedicate How Parse XML Using Regular Expressions in Asp.net with C#.

I got good solution for XML element value find from XML string.
Need to just call this function with parameters XML string, XML element name and default value if value not find into XML string.

 private String ExtractContentFromXml(String xml, String element, String defaultValue)
{
         String RegExpression = String.Format(@"(?<={0}>)[\S\s]*?(?=\<\/{0})", element);
         Match ThisMatch = Regex.Match(xml, RegExpression);
        if (ThisMatch.Success)
                  return ThisMatch.Value;
        else
                 return defaultValue;
}

I hope you will enjoy this solution...
Previous
Next Post »
Thanks for your comment