In the past, I had to deal with huge XML and performance was a problem. All I needed was not cached, read-only, read-only access to XML.
In addition, I did not have control over the scheme, I just needed to squeeze certain tag values ββfrom XML and and CDATA .
Below I get:
private string GetValueFromXmlTag(string xml, string tag) { if (xml == null || tag == null || xml.Length == 0 || tag.Length == 0) return ""; string startTag = "<" + tag + ">", endTag = "</" + tag + ">", value = null; int startTagIndex = xml.IndexOf(tag, StringComparison.OrdinalIgnoreCase), endTagIndex = xml.IndexOf(endTag, StringComparison.OrdinalIgnoreCase); if (startTagIndex < 0 || endTagIndex < 0) return ""; int valueIndex = startTagIndex += startTag.Length - 1; try { value = xml.Substring(valueIndex, endTagIndex - valueIndex); } catch (ArgumentOutOfRangeException responseXmlParserEx) { string err = string.Format("Error reading value for \"{0}\" tag from XXX XML", tag); log.Error(err, responseXmlParserEx); } return (value ?? ""); }
source share