简体   繁体   English

XMLdocument.load(url)内部如何从其他位置加载XML

[英]What does XMLdocument.load(url) Internal does to Load the XML from other Location

I want to know what call xmldocument internally uses to load the XML, does it make httpwebsrequest or anything else. 我想知道在内部使用什么调用xmldocument来加载XML,它使httpwebsrequest还是其他东西。

I read about it here, but there is no enough info about the internals 我在这里阅读过有关此内容的信息,但没有足够的内部信息

http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.load.aspx http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.load.aspx

 XmlDocument doc = new XmlDocument();

 doc.Load("http://someotherserver/test.xml");   

Can anyone please tell me about this. 谁能告诉我这件事。

I think this is the code that does it. 我认为这是执行此操作的代码。

It's in the XmlDownloadManager class which is internal 在内部的XmlDownloadManager类中

private Stream GetNonFileStream(Uri uri, ICredentials credentials)
{
    WebRequest request = WebRequest.Create(uri);
    if (credentials != null)
    {
        request.Credentials = credentials;
    }
    WebResponse response = request.GetResponse();
    HttpWebRequest request2 = request as HttpWebRequest;
    if (request2 != null)
    {
        lock (this)
        {
            if (this.connections == null)
            {
                this.connections = new Hashtable();
            }
            OpenedHost host = (OpenedHost) this.connections[request2.Address.Host];
            if (host == null)
            {
                host = new OpenedHost();
            }
            if (host.nonCachedConnectionsCount < (request2.ServicePoint.ConnectionLimit - 1))
            {
                if (host.nonCachedConnectionsCount == 0)
                {
                    this.connections.Add(request2.Address.Host, host);
                }
                host.nonCachedConnectionsCount++;
                return new XmlRegisteredNonCachedStream(response.GetResponseStream(), this, request2.Address.Host);
            }
            return new XmlCachedStream(response.ResponseUri, response.GetResponseStream());
        }
    }
    return response.GetResponseStream();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM