Results 1 to 5 of 5

Thread: [RESOLVED] Ignore DocType when using System.Xml.XmlDocument

  1. #1

    Thread Starter
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Resolved [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:
    1. Dim mInFile As String
    2.         Dim mPrepend As String
    3.         Dim XMLReader As New System.Xml.XmlDocument()
    4.  
    5.         Dim mSpot1 As Integer
    6.         Dim mSpot2 As Integer
    7.  
    8.         Dim mStrip1 As String
    9.         Dim mStrip2 As String
    10.         Dim mStrip3 As String
    11.  
    12.         mStrip1 = "<!DOCTYPE xpif SYSTEM "
    13.         mStrip2 = ".dtd"">"
    14.         mInFile = "G:\LuLu_Past_Jobs-Lou\LULU_INVESTIGATIONS_LOU\CC271100\Processed\CC271100-1_Cover_Libbed.pdf.prepended"
    15.         If GET_XML_FROM_PREPENDED_FILE(mInFile, mPrepend) Then
    16.             'mSpot1 = mPrepend.IndexOf("<!DOCTYPE xpif SYSTEM ")
    17.             'If mSpot1 > -1 Then
    18.             '    mSpot2 = mPrepend.IndexOf(mStrip2, mSpot1)
    19.             '    If mSpot2 > -1 Then
    20.             '        mStrip3 = mPrepend.Substring(mSpot1, mSpot2 + mStrip2.Length - mSpot1)
    21.             '        mPrepend = mPrepend.Replace(mStrip3, "")
    22.             '    End If
    23.             'End If
    24.             XMLReader.LoadXml(mPrepend)
    25.             If XMLReader.GetElementsByTagName("job-message-to-operator").Count = 1 Then
    26.                 MessageBox.Show(XMLReader.GetElementsByTagName("job-message-to-operator").ItemOf(0).InnerText)
    27.             Else
    28.                 MessageBox.Show("MESSAGE TO OPERATOR {QUEUE} NOT FOUND")
    29.             End If
    30.             If XMLReader.GetElementsByTagName("autosend").Count = 1 Then
    31.                 MessageBox.Show("AUTOSEND=" & XMLReader.GetElementsByTagName("autosend").ItemOf(0).InnerText)
    32.             Else
    33.                 MessageBox.Show("AUTOSEND NOT FOUND")
    34.             End If
    35.         Else
    36.             MessageBox.Show("Failed! " & mPrepend)
    37.         End If
    38.         XMLReader = Nothing

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    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:
    1. Dim mInFile As String
    2.         Dim mPrepend As String
    3.         Dim XMLReader As New System.Xml.XmlDocument()
    4.  
    5.         Dim mSpot1 As Integer
    6.         Dim mSpot2 As Integer
    7.  
    8.         Dim mStrip1 As String
    9.         Dim mStrip2 As String
    10.         Dim mStrip3 As String
    11.  
    12.         mStrip1 = "<!DOCTYPE xpif SYSTEM "
    13.         mStrip2 = ".dtd"">"
    14.         mInFile = "G:\LuLu_Past_Jobs-Lou\LULU_INVESTIGATIONS_LOU\CC271100\Processed\CC271100-1_Cover_Libbed.pdf.prepended"
    15.         If GET_XML_FROM_PREPENDED_FILE(mInFile, mPrepend) Then
    16.             'mSpot1 = mPrepend.IndexOf("<!DOCTYPE xpif SYSTEM ")
    17.             'If mSpot1 > -1 Then
    18.             '    mSpot2 = mPrepend.IndexOf(mStrip2, mSpot1)
    19.             '    If mSpot2 > -1 Then
    20.             '        mStrip3 = mPrepend.Substring(mSpot1, mSpot2 + mStrip2.Length - mSpot1)
    21.             '        mPrepend = mPrepend.Replace(mStrip3, "")
    22.             '    End If
    23.             'End If
    24.             XMLReader.LoadXml(mPrepend)
    25.             If XMLReader.GetElementsByTagName("job-message-to-operator").Count = 1 Then
    26.                 MessageBox.Show(XMLReader.GetElementsByTagName("job-message-to-operator").ItemOf(0).InnerText)
    27.             Else
    28.                 MessageBox.Show("MESSAGE TO OPERATOR {QUEUE} NOT FOUND")
    29.             End If
    30.             If XMLReader.GetElementsByTagName("autosend").Count = 1 Then
    31.                 MessageBox.Show("AUTOSEND=" & XMLReader.GetElementsByTagName("autosend").ItemOf(0).InnerText)
    32.             Else
    33.                 MessageBox.Show("AUTOSEND NOT FOUND")
    34.             End If
    35.         Else
    36.             MessageBox.Show("Failed! " & mPrepend)
    37.         End If
    38.         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.

  3. #3

    Thread Starter
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397

    Re: Ignore DocType when using System.Xml.XmlDocument

    Good Idea!

    Thats what this does, when uncommented:

    VB Code:
    1. 'mSpot1 = mPrepend.IndexOf("<!DOCTYPE xpif SYSTEM ")
    2.             'If mSpot1 > -1 Then
    3.             '    mSpot2 = mPrepend.IndexOf(mStrip2, mSpot1)
    4.             '    If mSpot2 > -1 Then
    5.             '        mStrip3 = mPrepend.Substring(mSpot1, mSpot2 + mStrip2.Length - mSpot1)
    6.             '        mPrepend = mPrepend.Replace(mStrip3, "")
    7.             '    End If
    8.             '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.

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width