How to skip validation of DTD file on VB.Net when the DTD is offline

G

GCeaser

------- I have also posted this to the microsoft.public.xml group but I
am not sure which one it belongs in ------

OK - I have an XML file from a vendor that uses a DTD files as follows:

<!DOCTYPE metis PUBLIC "-//METIS/METIS XML 1.2//EN"
"http://xml.metis.no/metis12.dtd">

The problem is - currently and periodically - the vendor takes the dtd
file offline. Thus, when I am trying to open the XML document in
Vb.Net using the following code:

Private iobj_MetisModel As New XmlDocument
iobj_MetisModel.Load(is_Path_To_Metis_File)

The load is failing with a SocketException because the DTD is not
available (see full stack trace below). I am only reading the XML and
doing some Xpath queries on it. Any idea how I can tell the XML
document to simply continue if it cannot access the DTD?

-------------------------------- Stack Trace
-----------------------------------
MetisReporting: An error occurred while the Metis Reporting System
process was running. Full details are below. System.Net.WebException:
Unable to connect to the remote server --->
System.Net.Sockets.SocketException: A connection attempt failed because
the connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to
respond
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,
SocketAddress socketAddress)
at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean
connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress&
address, ConnectSocketState state, IAsyncResult asyncResult, Int32
timeout, Exception& exception)
--- End of inner exception stack trace ---
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.ParseDoctypeDecl()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
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.Load(String filename)
at MetisDatabaseClass.MetisToDatabase.LoadMetisXMLDocument() in
D:\Visual Studio 2005
Projects\MetisToDB\MetisDatabaseClass\ConvertMetisXMLToDatabase.vb:line
223
at MetisDatabaseClass.MetisToDatabase.GetContainers(TreeView&
pobj_TreeView) in D:\Visual Studio 2005
Projects\MetisToDB\MetisDatabaseClass\ConvertMetisXMLToDatabase.vb:line
359
at
MetisToDBFrontEnd.frmMetisDBFrontEnd.frmMetisDBFrontEnd_Load(Object
sender, EventArgs e) in D:\Visual Studio 2005
Projects\MetisToDB\MetisToDBFrontEnd\frmMetisDBFrontEnd.vb:line 61
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd,
Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at MetisToDBFrontEnd.startupModule.Main() in D:\Visual Studio 2005
Projects\MetisToDB\MetisToDBFrontEnd\startupModule.vb:line 12
 
G

GCeaser

Ok - So the following solution works:


Dim lobj_XMLTextReader As XmlTextReader
Dim iobj_MetisModel As New XmlDocument


'Start up the XmlTextReader - using this to override the
XMLResolver
lobj_XMLTextReader = New XmlTextReader(is_Path_To_File)
lobj_XMLTextReader.XmlResolver = Nothing
iobj_MetisModel.Load(lobj_XMLTextReader)

this was a pain - I hope it helps others :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top