private XPathDocument CreateAndCacheDocument(XmlReader r)
{
string uri = r.BaseURI;
XPathDocument doc = new XPathDocument(r, XmlSpace.Preserve);
r.Close();
//Can't cache documents with empty base URI
if (!string.IsNullOrEmpty(uri))
{
lock (_cache)
{
if (!_cache.ContainsKey(uri))
_cache.Add(uri, new WeakReference(doc));
}
}
return doc;
}