0

I am using multiple methods to parse xml, with xpathnavigator, regex expressions etc some of the types of parsing. However I strip the xml entries first either using string.split or xpathnavigator and xmldocument.load etc; but found that if there is an entry with bad xml it creates an error and the entire files is blacklisted to a temp folder. I thought I would use xmltextreader to read each entry and add it to a list but when I reach the bad entry, I am not sure how to just ignore that entry and move on to the next entry in the xml document.

Example code:

Try
     Dim ureader as XmlTextReader = New XmlTextReader(New StringBuilder(result))
     While ureader.read
       Try
           If ureader.Name = "entry" then
              page = ureader.ReadInnerXml
              entriesList.add("<entry>" & page & "</entry>")
           EndIf
       Catch ex as exception
          Continue While
       End Try
      End While

 Catch ex as Exception
      log.logError(ex.message.tostring)
 End Try
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
vbNewbie
  • 3,291
  • 15
  • 71
  • 155
  • 1
    This is just a comment because I don't have a good solution, but it's worth noting that the xml spec _requires_ compliant parsers to throw a fatal error for well-formedness issues. – Joel Coehoorn Mar 08 '12 at 18:05
  • If the fault is missing end tag there won't be no next entry. It's a hiding to nothing this, every scenario you code round means there's two more you haven't seen yet. I'd concentrate of getting the producer of the xml, a copy of xml for dummies. – Tony Hopkinson Mar 08 '12 at 18:12
  • I am actually producing the xml files...I am capturing a data stream and once I get the content, write them to files in chunks. Will look into that. But does anyone think just trying to parse it as a string will be better. The point is not to miss much content that gets parsed. – vbNewbie Mar 08 '12 at 20:58

0 Answers0