RegEx to remove invalid XML characters

Posted on 2008-11-19
Medium Priority
Last Modified: 2012-05-05
I am storing data collected on a website as xml in ms sql 2005.

some characters are not allowed and I recieve "XML parsing: line 3, character 27, illegal xml character"
I believe what happens is people type up information in MS word or a similar program that uses extended characters such as curly quotes.  When I find an new illegal character I try and replace it.  But doing each illegal character seems clunkly.  I'm assuming there has to be a RegEx solution here.

Can anyone give me a vb.net example of a RegEx solution that will strip out all non legal XML characters as defined by MS SQL 2005.

Question by:dbashley1

Expert Comment

ID: 23001499
Here is the exact link, which talks about how to parse & remove invalid characters                                             in XML File using C#. May be you can convert this into VB.NET using some convert tool.


Author Comment

ID: 23004109

parsing an error message isn't really the solution I'm looking for.  The error message could change with the next version of .net or other senarios that I'd be trying to anticipate.

I'd really like a RegEx solution if that is possible.


Accepted Solution

livepersoninc earned 2000 total points
ID: 23117145
Balaji Ramesh has published a code that does exactly this. You can get the regular expression that he used:

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question