を取得できないようXmlDocument.LoadXml、それは時間がかかりすぎると、それは例外をスロー:.NET:私は、コード(C#)を以下しているDTD
new XmlDocument().
LoadXml("<?xml version='1.0' ?><!DOCTYPE note SYSTEM 'http://someserver/dtd'><note></note>");
それはそれを行う理由を私は理解しています。私の質問は、どうやって止めさせるのか?私はDTD検証については気にしない。私は正規表現を置き換えることができると思うが、より洗練されたソリューションを探している。
背景:
実際のXMLは、私が所有していないWebサイトから受信しました。サイトがメンテナンス中の場合、メンテナンス中に利用できないDTDを指すDOCTYPEを持つXMLを返します。だから私のサービスは、解析する必要があるXMLごとにDTDを取得しようとするので、不要な速度が遅くなります。ここで
は例外スタックです:
Unhandled Exception: System.Net.WebException: The remote name could not be resolved: 'someserver'
at System.Net.HttpWebRequest.GetResponse()
at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenStream(Uri uri)
at System.Xml.XmlTextReaderImpl.DtdParserProxy_PushExternalSubset(String systemId, String publicId)
at System.Xml.XmlTextReaderImpl.DtdParserProxy.System.Xml.IDtdParserAdapter.PushExternalSubset(String systemId, String publicId)
at System.Xml.DtdParser.ParseExternalSubset()
at System.Xml.DtdParser.ParseInDocumentDtd(Boolean saveInternalSubset)
at System.Xml.DtdParser.Parse(Boolean saveInternalSubset)
at System.Xml.XmlTextReaderImpl.DtdParserProxy.Parse(Boolean saveInternalSubset)
at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.LoadXml(String xml)
at ConsoleApplication36.Program.Main(String[] args) in c:\Projects\temp\ConsoleApplication36\Program.cs:line 11
です。 –
XmlReader.Settings.ValidationTypeをValidationType.Noneに設定してください。また、XmlReader.Settings.XmlResolverをnullに設定すると、トリックを行うこともできます。 –
確認済みの 'doc.XmlResolver = null;'は問題を解決します。 –