|
-
Jul 11th, 2009, 12:58 PM
#1
Thread Starter
Addicted Member
How Do You Ignore Illegal Characters In An XmlDocument?
Hi,
I'm trying to read quite a large (7mb) XML file which has quite a lot of illegal characters in it. How do I ignore them or ignore the run-time exceptions?
Thanks
Louix
-
Jul 11th, 2009, 04:41 PM
#2
Frenzied Member
Re: How Do You Ignore Illegal Characters In An XmlDocument?
I dunno if this would work but its just a thought, I would read the file as a text document into a string variable and regex.replace() whatever needed to be changed to make the document "valid" then save and re-read.
-
Jul 11th, 2009, 05:21 PM
#3
Thread Starter
Addicted Member
Re: How Do You Ignore Illegal Characters In An XmlDocument?
I have this code which uses RegEx, but it doesn't work:
Code:
String xmlFile = File.ReadAllText("myfile.xml"));
string xmlFileFinal = Regex.Replace(xmlFile, "#x((10?|[2-F])FFF[EF]|FDD[0-9A-F]|7F|8[0-46-9A-F]9[0-9A-F])", "", RegexOptions.IgnoreCase);
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlFileFinal);
-
Jul 11th, 2009, 06:49 PM
#4
Frenzied Member
Re: How Do You Ignore Illegal Characters In An XmlDocument?
I'd need the XML file to verify your regex string or you could google regex buddy. It is a program that will help you verify your regex. That will show you if it is your regex that is wrong.
-
Jul 11th, 2009, 08:21 PM
#5
Thread Starter
Addicted Member
Re: How Do You Ignore Illegal Characters In An XmlDocument?
I'm not allowed to give you the XML file but I can tell you that I'm using XML 1.0 and my RegEx looks like this:
#x((10?|[2-F])FFF[EF]|FDD[0-9A-F]|7F|8[0-46-9A-F]9[0-9A-F])
-
Jul 12th, 2009, 09:35 AM
#6
Hyperactive Member
Re: How Do You Ignore Illegal Characters In An XmlDocument?
Can you tell us why the xml file has illegal characters in it? That seems like a very odd situation. If the file is corrupted or something, removing the illegal characters won't fix it.
My monkey wearing the fedora points and laughs at you.
-
Jul 12th, 2009, 10:41 AM
#7
Thread Starter
Addicted Member
Re: How Do You Ignore Illegal Characters In An XmlDocument?
We are converting a CSV file from our product supplier to XML. The CSV file already has some illegal characters in it, so they get passed through when we convert it. Any way to ignore these exceptions and continue reading the file?
-
Jul 12th, 2009, 12:32 PM
#8
Thread Starter
Addicted Member
Re: How Do You Ignore Illegal Characters In An XmlDocument?
I found the solution!!
http://seattlesoftware.wordpress.com...lid-character/
Very handy!!
Thank you for your help guys
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|