|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Is RegEx a good choice for reading malformed xml?I download xml logs from several servers every day and read the data out of
them using the XmlTextReader. But about 10% of them each day throw exceptions because they are not well formed. I don't want to lose the data in the files that won't load into an XmlDocument. So I was thinking maybe using a RegEx function, sending a Node Name to the function and having it return the InnerText. Is this a good use for RegEx, or is there a better way to do what I want? I'm not versed in RegEx either, so what would a RegEx expression look like for this? Thanks. Terry,
| Is this a good use for RegEx, or is there a better way to do what I want? IMHO The "better" way, i.e. the *correct* way, would be to correct the program that allegedly is writing Xml to *actually write* Xml, (have it use a "parser" & write well formed Xml) then your program would not (should not) have an issue reading valid Xml! For details see "Item 29 - Always Use a Parser" in Elliotte Rusty Harold's excellent book " Effective XML - 50 Specific Ways to Improve Your XML" from Addison Wesley. Although RegEx could possibly parse the mal formed Xml, what's to say the source program is able to write enough bad Xml so that you regex could read it. Before using RegEx to parse out enough info to throw an exception, I would consider using alternate Xml Parsers/readers, such as the SgmlReader from Got Dot Net: http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=b90fddce-e60d-43f8-a5c4-c3bd760564bc Some RegEx resources: Expresso: http://www.ultrapico.com/Expresso.htm RegEx Workbench: http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=c712f2df-b026-4d58-8961-4ee2729d7322 A tutorial & reference on using regular expressions: http://www.regular-expressions.info/ The MSDN's documentation on regular expressions: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconRegularExpressionsLanguageElements.asp Expresso & RegEx Workbench are helpful tools for learning regular expressions & testing them. I use the regular-expressions.info as a general regex reference, then fall back to MSDN for the specifics. The above link is .NET 1.x; I don't have the ..NET 2.0 link handy; not sure if any thing changes in 2.0. -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Terry Olsen" <tolse***@hotmail.com> wrote in message news:upAR7ZkhGHA.4284@TK2MSFTNGP05.phx.gbl... |I download xml logs from several servers every day and read the data out of | them using the XmlTextReader. But about 10% of them each day throw | exceptions because they are not well formed. I don't want to lose the data | in the files that won't load into an XmlDocument. So I was thinking maybe | using a RegEx function, sending a Node Name to the function and having it | return the InnerText. | | Is this a good use for RegEx, or is there a better way to do what I want? | I'm not versed in RegEx either, so what would a RegEx expression look like | for this? | | Thanks. | |
Calling VB.Net classes from VB6
Data base insert Error HELP! Adding a row to a table help! Is there a Forms collection? VB.NET Screen Stops Refreshing After Losing Focus?? Why doesn't changing the position in a table change the position of the DatGridView that's bound to How to measure bandwidth need by the application UI to enter values into a structure Crypto removing white spaces from byte array Good way to do lookups... |
|||||||||||||||||||||||