?
Solved

RegEx to remove invalid XML characters

Posted on 2008-11-19
3
Medium Priority
?
4,118 Views
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.

Thanks
0
Comment
Question by:dbashley1
3 Comments
 

Expert Comment

by:lakram5455
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.

http://forums.microsoft.com/msdn/showpost.aspx?postid=1824669&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=0
0
 

Author Comment

by:dbashley1
ID: 23004109
lakram,

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.

0
 
LVL 1

Accepted Solution

by:
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:
http://balajiramesh.wordpress.com/2008/05/30/strip-illegal-xml-characters-based-on-w3c-standard/
0

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