[RESOLVED] Ignore DocType when using System.Xml.XmlDocument
Using VBNet 2002:
Any idea how I can get System.Xml.XmlDocument to ignore the !DocType referance in an XML string, without just deleting the offending referance prior to .LoadXml ?
Quote:
Error Message: Could not find file "C:\Documents and Settings\lou\My Documents\Visual Studio Projects\Micro_Manage_AutoSubmit\bin\xpif-v2000.dtd".
VB Code:
Dim mInFile As String
Dim mPrepend As String
Dim XMLReader As New System.Xml.XmlDocument()
Dim mSpot1 As Integer
Dim mSpot2 As Integer
Dim mStrip1 As String
Dim mStrip2 As String
Dim mStrip3 As String
mStrip1 = "<!DOCTYPE xpif SYSTEM "
mStrip2 = ".dtd"">"
mInFile = "G:\LuLu_Past_Jobs-Lou\LULU_INVESTIGATIONS_LOU\CC271100\Processed\CC271100-1_Cover_Libbed.pdf.prepended"
If GET_XML_FROM_PREPENDED_FILE(mInFile, mPrepend) Then
'mSpot1 = mPrepend.IndexOf("<!DOCTYPE xpif SYSTEM ")
'If mSpot1 > -1 Then
' mSpot2 = mPrepend.IndexOf(mStrip2, mSpot1)
' If mSpot2 > -1 Then
' mStrip3 = mPrepend.Substring(mSpot1, mSpot2 + mStrip2.Length - mSpot1)
' mPrepend = mPrepend.Replace(mStrip3, "")
' End If
'End If
XMLReader.LoadXml(mPrepend)
If XMLReader.GetElementsByTagName("job-message-to-operator").Count = 1 Then
MessageBox.Show(XMLReader.GetElementsByTagName("job-message-to-operator").ItemOf(0).InnerText)
Else
MessageBox.Show("MESSAGE TO OPERATOR {QUEUE} NOT FOUND")
End If
If XMLReader.GetElementsByTagName("autosend").Count = 1 Then
MessageBox.Show("AUTOSEND=" & XMLReader.GetElementsByTagName("autosend").ItemOf(0).InnerText)
Else
MessageBox.Show("AUTOSEND NOT FOUND")
End If
Else
MessageBox.Show("Failed! " & mPrepend)
End If
XMLReader = Nothing
Re: Ignore DocType when using System.Xml.XmlDocument
Quote:
Originally Posted by NotLKH
Using VBNet 2002:
Any idea how I can get System.Xml.XmlDocument to ignore the !DocType referance in an XML string, without just deleting the offending referance prior to .LoadXml ?
VB Code:
Dim mInFile As String
Dim mPrepend As String
Dim XMLReader As New System.Xml.XmlDocument()
Dim mSpot1 As Integer
Dim mSpot2 As Integer
Dim mStrip1 As String
Dim mStrip2 As String
Dim mStrip3 As String
mStrip1 = "<!DOCTYPE xpif SYSTEM "
mStrip2 = ".dtd"">"
mInFile = "G:\LuLu_Past_Jobs-Lou\LULU_INVESTIGATIONS_LOU\CC271100\Processed\CC271100-1_Cover_Libbed.pdf.prepended"
If GET_XML_FROM_PREPENDED_FILE(mInFile, mPrepend) Then
'mSpot1 = mPrepend.IndexOf("<!DOCTYPE xpif SYSTEM ")
'If mSpot1 > -1 Then
' mSpot2 = mPrepend.IndexOf(mStrip2, mSpot1)
' If mSpot2 > -1 Then
' mStrip3 = mPrepend.Substring(mSpot1, mSpot2 + mStrip2.Length - mSpot1)
' mPrepend = mPrepend.Replace(mStrip3, "")
' End If
'End If
XMLReader.LoadXml(mPrepend)
If XMLReader.GetElementsByTagName("job-message-to-operator").Count = 1 Then
MessageBox.Show(XMLReader.GetElementsByTagName("job-message-to-operator").ItemOf(0).InnerText)
Else
MessageBox.Show("MESSAGE TO OPERATOR {QUEUE} NOT FOUND")
End If
If XMLReader.GetElementsByTagName("autosend").Count = 1 Then
MessageBox.Show("AUTOSEND=" & XMLReader.GetElementsByTagName("autosend").ItemOf(0).InnerText)
Else
MessageBox.Show("AUTOSEND NOT FOUND")
End If
Else
MessageBox.Show("Failed! " & mPrepend)
End If
XMLReader = Nothing
Could you get the data into a temporary string and then replace it with nothing, thus not affecting the actual original file.
Re: Ignore DocType when using System.Xml.XmlDocument
Good Idea!
Thats what this does, when uncommented:
VB Code:
'mSpot1 = mPrepend.IndexOf("<!DOCTYPE xpif SYSTEM ")
'If mSpot1 > -1 Then
' mSpot2 = mPrepend.IndexOf(mStrip2, mSpot1)
' If mSpot2 > -1 Then
' mStrip3 = mPrepend.Substring(mSpot1, mSpot2 + mStrip2.Length - mSpot1)
' mPrepend = mPrepend.Replace(mStrip3, "")
' End If
'End If
I just don't like it, as its fudging around the issue.
I was hoping there might be a .UseDocType switch of some sort, as that would be more elegant.
Re: Ignore DocType when using System.Xml.XmlDocument
Try setting the XmlResolver of the xml document to Nothing before calling LoadXml
Re: Ignore DocType when using System.Xml.XmlDocument
Bingo!
[latka]thankyouverymuch[/latka]
:wave: