1

htmlagilitypack を使用して xml ドキュメントを解析しています。これを使用して文字列を htmldocument としてロードし、xmltextreader を使用して解析します。htmlagility.dll で未処理の stackoverflow 例外が発生することがあります。具体的な行は

internal Dictionary<string, Htmlattribute> Hashitems = new 
                            Dictionary<string, HtmlAttribute>()

編集:

Try
            Dim hdoc = New HtmlAgilityPack.HtmlDocument()
            hdoc.LoadHtml(xmlsnippet)
            Dim nreader As XmlTextReader = New 
                         XmlTextReader(New StringReader(xmlsnippet))
            Dim ncount As Integer = 0

            While nreader.Read
                If Not nreader.Name = "" Then
                    ncount += 1
                    If ncount = 18 Then
                        Exit While
                    End If
                    num += 1
                    nodelist.Add(nreader.Name)
                    If nreader.Name = "id" Then
                        statid = nreader.ReadInnerXml
                    End If
                    If nreader.Name = "published" Then
                        contentDate = nreader.ReadInnerXml
                        contentDate = Regex.Replace(contentDate, "T", " ")
                        contentDate = Regex.Replace(contentDate, "\+", " ")
                        contentDate = contentDate.Replace("Z", "")
                    End If
                    If nreader.Name = "summary" Then
                        ctext = nreader.ReadInnerXml
                    End If
                    If nreader.Name = "title" Then
                        csubject = nreader.ReadInnerXml
                        If csubject.Contains("posted") Then
                            template = csubject
                            author = Regex.Replace(template, "posted.*", "")
                        End If
                        If csubject.Contains("Keyword -") Then
                          Dim tip As String = csubject
                            searchterm = 
                            Regex.Replace(csubject, "xxxxxx.*xxxxxx.*xxxx.*-", "")
                            searchterm = 
                           Regex.Replace(searchterm, "xxxxx.*xxxxxx.*Search.*-", "")
                            Trim(searchterm)
                        End If
                    End If
                End If
            End While

            Dim mreader As XmlTextReader = 
                        New XmlTextReader(New StringReader(xmlsnippet))
            Dim mcount As Integer = 0

            While mreader.Read
                If Not mreader.Name = "" Then
                    mcount += 1
                    If mcount > 15 Then
                        If mreader.Name = "uri" Then
                            authorUri = mreader.ReadInnerXml
                            Trim(authorUri)
                            If authorUri = "http://www.xxxxxxxx.com/" Then
                                authorUri = ""
                            End If
                        End If
                        If mreader.Name = "name" Then
                            author = mreader.ReadInnerXml
                            If author = "xxxxxx" Then
                                author = ""
                            End If
                        End If
                        If mreader.Name = "content" Then
                            htext = mreader.ReadInnerXml
                        End If
                        If mreader.Name = "link" Then
                            Dim address As String
                            address = mreader.ReadOuterXml
                            If address.Contains("related") Then
                                Dim regex12 As Regex =
            New Regex("<link.*rel.*href=""(?<Link>.*?)"".*/>", RegexOptions.IgnoreCase)
                                Dim m12 As Match = regex12.Match(address)
                                himage = m12.Groups("Link").Value
                            ElseIf address.Contains("alternate") Then
                                Dim regex13 As Regex = 
           New Regex("<link.*rel.*href=""(?<Link>.*?)"".*/>", RegexOptions.IgnoreCase)
                                Dim m13 As Match = regex13.Match(address)
                                authorUri = m13.Groups("Link").Value
                            End If
                        End If
                        If mreader.Name = "subtitle" Then
                            hsubtitle = mreader.ReadInnerXml
                        End If
                    End If
                End If
            End While

        Catch ex As Exception
            appLogs.constructLog(ex.Message.ToString, True, True)
            Exit Sub
        End Try

実際、異なる行で異なるスタックオーバーフロー例外エラーが発生していますが、同じエラーであり、htmlagilitypack の使用中にのみ発生します。私はxmldocument、xpathnavigatorを使用してxmlを解析しようとしている別の方法を使用していますが、悪いxmlを取得しない限り正常に動作し、この方法に進みます。不正な xml をフォルダーに移動してからこのメソッドを終了するように例外キャッチを設定しましたが、これらの種類の例外をキャッチすることはできませんか?

エラーが表示される別の行:

public string Name
{
   get
   {
     if (_name == null)
     {
       Name = _ownerdocument.Text.Substring(_namestartindex, _namelength);
     }
      return _name != null ? _name.ToLower() : string.Empty;

ファイル HtmlNode.cs の上記のスニペットの最後の行。コール スタック ウィンドウの上部は次のように表示されます。

HtmlAgilityPack.dll!HtmlAgilityPack.HtmlNode.Name.get() Line 432 + 0x21 bytes
4

0 に答える 0