I have a simple block of legacy code that is inside a loop that scans some potentially bad xml node on node and needs to be refactored because it doesn't work as intended:
Try
xmlFrag.LoadXml("<temproot>" & strXMLfragment & "</temproot>")
writer.WriteRaw(strXMLfragment)
Catch ex As Exception
InvalidXML = True
End Try
This block is designed to validate xml, and then write xml out. This is actually checking for invalid xml, and then writing the xml out is only if it is valid. Therefore, it must be corrected for the intended purpose.
My first attempt to fix:
Try
xmlFrag.LoadXml("<temproot>" & strXMLfragment & "</temproot>")
'writer.WriteRaw(strXMLfragment)
Catch ex As Exception
InvalidXML = True
Finally
writer.WriteRaw(strXMLfragment)
End Try
, , WriteRaw . , WriteRaw, , .
, :
Try
xmlFrag.LoadXml("<temproot>" & strXMLfragment & "</temproot>")
Catch ex As Exception
InvalidXML = True
End Try
Try
writer.WriteRaw(strXMLfragment)
Catch
End Try
, . ?