|
-
Dec 21st, 2006, 04:42 PM
#1
Thread Starter
pathfinder
[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 ?
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
-
Dec 22nd, 2006, 09:39 AM
#2
Hyperactive Member
Re: Ignore DocType when using System.Xml.XmlDocument
 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.
» Twitter: @rudi_visser : Website: www.rudiv.se «
If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.
-
Dec 22nd, 2006, 09:51 AM
#3
Thread Starter
pathfinder
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.
-
Dec 22nd, 2006, 10:43 AM
#4
Re: Ignore DocType when using System.Xml.XmlDocument
Try setting the XmlResolver of the xml document to Nothing before calling LoadXml
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Dec 22nd, 2006, 01:01 PM
#5
Thread Starter
pathfinder
Re: Ignore DocType when using System.Xml.XmlDocument
Bingo!
[latka]thankyouverymuch[/latka]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|